30 Ekim 2018 Salı

Hibernate CP30 - Kullanmayın

Giriş
Şu satırı dahil ederiz.
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-c3p0</artifactId>
  <version>4.2.20.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
<dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
</dependency>
Şu satırı dahil ederiz.
<!-- c3p0 -->
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-c3p0</artifactId>
  <version>5.2.12.Final</version>
</dependency>
Değişkenler
Örnek
Bazı değişkenler şöyle
minPoolSize=10
maxPoolSize=50
maxStatements=50
idleConnectionTestPeriod=3600
acquireIncrement=5
maxIdleTime=600
numHelperThreads=6
unreturnedConnectionTimeout=3600
maxIdleTimeExcessConnections=600
Örnek
hibernate.cfg.xml dosyasında şöyle yaparız. Normalde bu satırı eklemeye gerek yok çünkü hibernate.c3p0.* ile başlayan ayarları görünce Hibernate otomatik olarak bu satırı gerçekleştirir.
<property name="hibernate.connection.provider_class">
  org.hibernate.connection.C3P0ConnectionProvider</property>
acquire_increment Alanı
Şöyle yaparız.
<!-- c3p0 -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.max_size">25</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_statement">0</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">250</property>
timeout Alanı
Örnek
hibernate.cfg.xml dosyasında şöyle yaparız.
<!DOCTYPE hibernate-configuration SYSTEM
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">
        com.mysql.jdbc.Driver
    </property>
    <property name="hibernate.connection.url">
        jdbc:mysql://localhost:3306/demo
    </property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">1234</property>
    <property name="hibernate.dialect">
        org.hibernate.dialect.MySQLDialect
    </property>

    <!-- Use the C3P0 connection pool provider -->
    <property name="hibernate.c3p0.min_size">5</property> 
    <property name="hibernate.c3p0.max_size">20</property> 
    <property name="hibernate.c3p0.timeout">300</property> 
    <property name="hibernate.c3p0.max_statements">50</property> 
    <property name="hibernate.c3p0.idle_test_period">3000</property>

    <!--List of XML mapping files -->
    <mapping class="www.Message"/>
</session-factory>
</hibernate-configuration>
idle_test_period Alanı
Örnek
hibernate.cfg.xml dosyasında şöyle yaparız.
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.timeout">3600</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">false</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.numHelperThreads">25</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.maxStatementsPerConnection">12</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_periods">3000</property>
min_size Alanı
Örnek
Şöyle yaparız.
<!-- pooling -->
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">180</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.timeout">300</property>
max_size Alanı
Örnek
Kodla ayarlamak için şöyle yaparız.
//Pooling
sqlProps.put("hibernate.c3p0.min_size", "5");
sqlProps.put("hibernate.c3p0.max_size", "20");
sqlProps.put("hibernate.c3p0.timeout", "300");
sqlProps.put("hibernate.c3p0.max_statements", "50");
sqlProps.put("hibernate.c3p0.idle_test_period", "3000");