-
Notifications
You must be signed in to change notification settings - Fork 120
C3P0 Configuration
Vlad Mihalcea edited this page Oct 17, 2024
·
4 revisions
<dependency>
<groupId>com.vladmihalcea.flexy-pool</groupId>
<artifactId>flexy-c3p0</artifactId>
<version>${flexy-pool.version}</version>
</dependency>
<bean id="poolingDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxPoolSize" value="3"/>
<property name="checkoutTimeout" value="1000"/>
</bean>
@org.springframework.context.annotation.Configuration
public class FlexyPoolBeanConfiguration {
@Autowired
private ComboPooledDataSource poolingDataSource;
@Value("${flexy.pool.uniqueId}")
private String uniqueId;
@Bean
public FlexyPoolConfiguration<ComboPooledDataSource> configuration() {
return new FlexyPoolConfiguration.Builder<ComboPooledDataSource>(
uniqueId,
poolingDataSource,
C3P0PoolAdapter.FACTORY
)
.setMetricsFactory(CodahaleMetrics.INSTANCE)
.setConnectionProxyFactory(JdkConnectionProxyFactory.INSTANCE)
.setJmxEnabled(true)
.setMetricLogReporterPeriod(5)
.build();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
FlexyPoolConfiguration<ComboPooledDataSource> configuration = configuration();
return new FlexyPoolDataSource<ComboPooledDataSource>(configuration,
new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
new RetryConnectionAcquisitionStrategy.Factory(2)
);
}
}
<bean id="configurationBuilder" class="com.vladmihalcea.flexypool.config.Configuration$Builder">
<constructor-arg value="uniqueId"/>
<constructor-arg ref="poolingDataSource"/>
<constructor-arg value="#{ T(com.vladmihalcea.flexypool.adaptor.C3P0PoolAdapter).FACTORY }"/>
</bean>
<bean id="configuration" factory-bean="configurationBuilder" factory-method="build"/>
<bean id="dataSource" class="com.vladmihalcea.flexypool.FlexyPoolDataSource" init-method="start" destroy-method="stop">
<constructor-arg ref="configuration"/>
<constructor-arg>
<array>
<bean class="com.vladmihalcea.flexypool.strategy.IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory">
<constructor-arg value="5"/>
</bean>
<bean class="com.vladmihalcea.flexypool.strategy.RetryConnectionAcquisitionStrategy.Factory">
<constructor-arg value="2"/>
</bean>
</array>
</constructor-arg>
</bean>