Advertisement
Guest User

Untitled

a guest
Mar 18th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <session-factory>
  7. <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
  8. <property name="connection.driver_class">org.postgresql.Driver</property>
  9. <property name="connection.url">jdbc:postgresql://localhost:5432/netstat</property>
  10. <property name="connection.username">netstat</property>
  11. <property name="connection.password">netstat</property>
  12.  
  13. <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  14.  
  15. <!-- configuration pool via c3p0 -->
  16. <property name="c3p0.min_size">5</property>
  17. <property name="c3p0.max_size">100</property>
  18. <property name="c3p0.max_statements">200</property>
  19. <property name="c3p0.timeout">600</property> <!-- seconds -->
  20.  
  21. <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
  22. <property name="current_session_context_class">thread</property>
  23. <property name="hibernate.show_sql">false</property>
  24. <property name="hibernate.hbm2ddl.auto">update</property>
  25. <!-- Mapping classes -->
  26. <mapping class="ru.gooamoko.model.Group" />
  27. <mapping class="ru.gooamoko.model.Host" />
  28. <mapping class="ru.gooamoko.model.Traffic" />
  29. <mapping class="ru.gooamoko.model.DailyTraffic" />
  30.  
  31. </session-factory>
  32. </hibernate-configuration>
  33.  
  34. package ru.gooamoko.dao;
  35.  
  36. import org.hibernate.SessionFactory;
  37. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  38. import org.hibernate.cfg.Configuration;
  39. import org.hibernate.service.ServiceRegistry;
  40.  
  41. public class HibernateProvider {
  42. private static SessionFactory factory;
  43. private static ServiceRegistry registry;
  44.  
  45. public static SessionFactory getSessionFactory() {
  46. Configuration configuration = new Configuration();
  47. configuration.configure();
  48. registry = new StandardServiceRegistryBuilder().applySettings(
  49. configuration.getProperties()).build();
  50. factory = configuration.buildSessionFactory(registry);
  51. return factory;
  52. }
  53.  
  54. }
  55.  
  56.  
  57. package ru.gooamoko.dao;
  58.  
  59. import org.hibernate.Session;
  60. import org.hibernate.SessionFactory;
  61.  
  62. public class GenericDao {
  63.  
  64. private SessionFactory factory;
  65. protected Session session;
  66.  
  67. protected void begin() {
  68. session = factory.getCurrentSession();
  69. session.beginTransaction();
  70. }
  71.  
  72. protected void commit() {
  73. if (session.isOpen()) {
  74. session.getTransaction().commit();
  75. }
  76. }
  77.  
  78. protected void rollback() {
  79. if (session.isOpen()) {
  80. session.getTransaction().rollback();
  81. }
  82. }
  83.  
  84. public GenericDao() {
  85. this.factory = HibernateProvider.getSessionFactory();
  86. }
  87. }
  88.  
  89. 27-Aug-2014 15:06:24.559 WARNING [C3P0PooledConnectionPoolManager[identityToken->1hge12w9467h4hm1tfa5tj|3b40a97d]-HelperThread-#2] com.mchange.v2.resourcepool.BasicResourcePool.forceKillAcquires Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@4df5a3a4 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
  90. 27-Aug-2014 15:06:24.563 WARNING [C3P0PooledConnectionPoolManager[identityToken->1hge12w9467h4hm1tfa5tj|3b40a97d]-HelperThread-#2] com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@628977a2 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
  91. org.postgresql.util.PSQLException: ?????: ?????????? ????? ??????????? ??????????????? ??? ??????????? ????????????????? (?? ??? ??????????)
  92. at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:572)
  93. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:177)
  94. at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
  95. at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136)
  96. at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
  97. at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
  98. at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)
  99. at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
  100. at org.postgresql.Driver.makeConnection(Driver.java:393)
  101. at org.postgresql.Driver.connect(Driver.java:267)
  102. at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
  103. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
  104. at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
  105. at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
  106. at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
  107. at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
  108. at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
  109. at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
  110. at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
  111.  
  112. package ru.gooamoko.dao;
  113.  
  114. import org.hibernate.HibernateException;
  115. import org.hibernate.SessionFactory;
  116. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  117. import org.hibernate.cfg.Configuration;
  118. import org.hibernate.service.ServiceRegistry;
  119.  
  120. public class HibernateProvider {
  121.  
  122. private static final SessionFactory factory = buildFactory();
  123.  
  124. public static SessionFactory getSessionFactory() {
  125. return factory;
  126. }
  127.  
  128. private static SessionFactory buildFactory() {
  129. try {
  130. Configuration configuration = new Configuration();
  131. configuration.configure();
  132. ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(
  133. configuration.getProperties()).build();
  134. return configuration.buildSessionFactory(registry);
  135. } catch (HibernateException ex) {
  136. // Make sure you log the exception, as it might be swallowed
  137. System.err.println("Initial SessionFactory creation failed." + ex);
  138. throw new ExceptionInInitializerError(ex);
  139. }
  140. }
  141. }
  142.  
  143. SELECT COUNT(*) FROm pg_stat_activity;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement