-
Notifications
You must be signed in to change notification settings - Fork 120
Atomikos TransactionsEssentials Configuration
Traditionally, the flexy-atomikos
is the dependency you should use for Atomikos TranscationEssentials.
<dependency>
<groupId>com.vladmihalcea.flexy-pool</groupId>
<artifactId>flexy-atomikos</artifactId>
<version>${flexy-pool.version}</version>
</dependency>
However, since [version 5](https://www.atomikos.com/Blog/ExtremeTransactions5dot0), Atomikos has changed the package names of the AtomikosDataSourceBean
, hence FlexyPool 2.2.0 added support for Atomikos 5 while maintaining backward compatibility with Atomikos 4 or previous versions.
If you’re using Atomikos 5, it’s much more efficient to set this dependency instead of the legacy flexy-atomikos
:
<dependency>
<groupId>com.vladmihalcea.flexy-pool</groupId>
<artifactId>flexy-atomikos5</artifactId>
<version>${flexy-pool.version}</version>
</dependency>
Also, for Atomikos 4 or older releases, it’s much more efficient to use the flexy-atomikos4
dependency:
<dependency>
<groupId>com.vladmihalcea.flexy-pool</groupId>
<artifactId>flexy-atomikos4</artifactId>
<version>${flexy-pool.version}</version>
</dependency>
The difference between using the flexy-atomikos
on one hand or the flexy-atomikos5
or flexy-atomikos4
on the other lies in the PoolAdapter
implementation you have to use.
Therefore, you can match the PoolAdapter
implementation with the Maven dependency you configured according to the following compatibility matrix:
flexy-atomikos
-
For the legacy dependency, you can use
AtomikosPoolAdapter
, which will delegate calls to eitherAtomikos5PoolAdapter
orAtomikos4PoolAdapter
based on the type of the provided targetDataSource
. flexy-atomikos5
-
For the Atomikos 5-specific dependency, you can use the
Atomikos5PoolAdapter
. flexy-atomikos4
-
For the Atomikos 4-specific dependency, you can use the
Atomikos4PoolAdapter
.
The advantage of using either Atomikos5PoolAdapter
or Atomikos4PoolAdapter
is that FlexyPool does not need to delegate calls from the AtomikosPoolAdapter
, therefore increasing performance.
Assuming you are using the following AtomikosDataSourceBean
:
<bean id="poolingDataSource"
class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init"
destroy-method="close">
<property name="uniqueResourceName" value="testDataSource"/>
<property name="xaDataSourceClassName" value="org.hsqldb.jdbc.pool.JDBCXADataSource"/>
<property name="minPoolSize" value="1"/>
<property name="maxPoolSize" value="3"/>
<property name="borrowConnectionTimeout" value="1"/>
<property name="xaProperties">
<props>
<prop key="user">${jdbc.username}</prop>
<prop key="password">${jdbc.password}</prop>
<prop key="url">${jdbc.url}</prop>
</props>
</property>
</bean>
The FlexyPool Atomikos configuration depends on the FlexyPool Atomikos dependency you have configured in your project.
If you’re using the flexypool-atomikos
dependency, you can configure FlexyPool using the following Spring Java-Bean Configuration:
@org.springframework.context.annotation.Configuration
public class FlexyPoolBeanConfiguration {
@Autowired
private DataSource poolingDataSource;
@Value("${flexy.pool.uniqueId}")
private String uniqueId;
@Bean
public FlexyPoolConfiguration<DataSource> configuration() {
return new FlexyPoolConfiguration.Builder<DataSource>(
uniqueId,
poolingDataSource,
AtomikosPoolAdapter.FACTORY
)
.setJmxEnabled(true)
.setMetricLogReporterMillis(TimeUnit.SECONDS.toMillis(5))
.build();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
FlexyPoolConfiguration<DataSource> configuration = configuration();
return new FlexyPoolDataSource<DataSource>(configuration,
new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
new RetryConnectionAcquisitionStrategy.Factory(2)
);
}
}
Or you could use the legacy XML-based Spring configuration:
<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.AtomikosPoolAdapter).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>
For the Atomikos 5 dependency, the Java-based configuration can use the Atomikos 5-specific com.atomikos.jdbc.internal.AbstractDataSourceBean
which is extended by either the JTA-specific AtomikosDataSourceBean
or the RESOURCE_LOCAL-specific AtomikosNonXADataSourceBean
.
Also, since we are using Atomikos 5, we can use the Atomikos5PoolAdapter
instead of the legacy AtomikosPoolAdapter
:
@org.springframework.context.annotation.Configuration
public class FlexyPoolBeanConfiguration {
@Autowired
private AbstractDataSourceBean poolingDataSource;
@Value("${flexy.pool.uniqueId}")
private String uniqueId;
@Bean
public FlexyPoolConfiguration<AbstractDataSourceBean> configuration() {
return new FlexyPoolConfiguration.Builder<AbstractDataSourceBean>(
uniqueId,
poolingDataSource,
Atomikos5PoolAdapter.FACTORY
)
.setJmxEnabled(true)
.setMetricLogReporterMillis(TimeUnit.SECONDS.toMillis(5))
.build();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
FlexyPoolConfiguration<AbstractDataSourceBean> configuration = configuration();
return new FlexyPoolDataSource<AbstractDataSourceBean>(configuration,
new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
new RetryConnectionAcquisitionStrategy.Factory(2)
);
}
}
For the Atomikos 4 dependency, the Java-based configuration can use the Atomikos 4-specific com.atomikos.jdbc.AbstractDataSourceBean
which is extended by either the JTA-specific AtomikosDataSourceBean
or the RESOURCE_LOCAL-specific AtomikosNonXADataSourceBean
.
Also, since we are using Atomikos 4, we can use the Atomikos4PoolAdapter
instead of the legacy AtomikosPoolAdapter
:
@org.springframework.context.annotation.Configuration
public class FlexyPoolBeanConfiguration {
@Autowired
private AbstractDataSourceBean poolingDataSource;
@Value("${flexy.pool.uniqueId}")
private String uniqueId;
@Bean
public FlexyPoolConfiguration<AbstractDataSourceBean> configuration() {
return new FlexyPoolConfiguration.Builder<AbstractDataSourceBean>(
uniqueId,
poolingDataSource,
Atomikos4PoolAdapter.FACTORY
)
.setJmxEnabled(true)
.setMetricLogReporterMillis(TimeUnit.SECONDS.toMillis(5))
.build();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
FlexyPoolConfiguration<AbstractDataSourceBean> configuration = configuration();
return new FlexyPoolDataSource<AbstractDataSourceBean>(configuration,
new IncrementPoolOnTimeoutConnectionAcquisitionStrategy.Factory(5),
new RetryConnectionAcquisitionStrategy.Factory(2)
);
}
}