use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class TestCPDSConnectionFactory method testNullValidationQuery_Deprecated.
/**
* JIRA: DBCP-442
*/
@Test
public void testNullValidationQuery_Deprecated() throws Exception {
final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
try (final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory)) {
factory.setPool(pool);
pool.setTestOnBorrow(true);
final PooledConnection pcon = pool.borrowObject().getPooledConnection();
try (final Connection con = pcon.getConnection()) {
}
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class TestSynchronizationOrder method testSessionSynchronization.
@Test
public void testSessionSynchronization() throws Exception {
final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, xads);
final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null);
factory.setValidationQuery("SELECT DUMMY FROM DUAL");
factory.setDefaultReadOnly(Boolean.TRUE);
factory.setDefaultAutoCommit(Boolean.TRUE);
// create the pool
try (final GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<>(factory)) {
factory.setPool(pool);
pool.setMaxTotal(10);
pool.setMaxWait(Duration.ofSeconds(1));
// finally create the datasource
try (final ManagedDataSource<PoolableConnection> ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry())) {
ds.setAccessToUnderlyingConnectionAllowed(true);
transactionManager.begin();
try (final DelegatingConnection<?> connectionA = (DelegatingConnection<?>) ds.getConnection()) {
// close right away.
}
transactionManager.commit();
assertTrue(transactionManagerRegistered);
assertFalse(transactionSynchronizationRegistryRegistered);
}
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class TestSynchronizationOrder method testInterposedSynchronization.
@Test
public void testInterposedSynchronization() throws Exception {
final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, xads, transactionSynchronizationRegistry);
final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null);
factory.setValidationQuery("SELECT DUMMY FROM DUAL");
factory.setDefaultReadOnly(Boolean.TRUE);
factory.setDefaultAutoCommit(Boolean.TRUE);
// create the pool
try (final GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<>(factory)) {
factory.setPool(pool);
pool.setMaxTotal(10);
pool.setMaxWait(Duration.ofSeconds(1));
// finally create the datasource
try (final ManagedDataSource<PoolableConnection> ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry())) {
ds.setAccessToUnderlyingConnectionAllowed(true);
transactionManager.begin();
try (final DelegatingConnection<?> connectionA = (DelegatingConnection<?>) ds.getConnection()) {
// Close right away.
}
transactionManager.commit();
assertFalse(transactionManagerRegistered);
assertTrue(transactionSynchronizationRegistryRegistered);
}
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class PoolingDataSourceExample method setupDataSource.
public static DataSource setupDataSource(String connectURI) {
//
// First, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string passed in the command line
// arguments.
//
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, null);
//
// Next we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
//
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
//
// Now we'll need a ObjectPool that serves as the
// actual pool of connections.
//
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
// Set the factory's pool property to the owning pool
poolableConnectionFactory.setPool(connectionPool);
//
// Finally, we create the PoolingDriver itself,
// passing in the object pool we created.
//
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
return dataSource;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class PoolingDriverExample method setupDriver.
public static void setupDriver(String connectURI) throws Exception {
//
// First, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string passed in the command line
// arguments.
//
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, null);
//
// Next, we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
//
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
//
// Now we'll need a ObjectPool that serves as the
// actual pool of connections.
//
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
// Set the factory's pool property to the owning pool
poolableConnectionFactory.setPool(connectionPool);
//
// Finally, we create the PoolingDriver itself...
//
Class.forName("org.apache.commons.dbcp2.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
//
// ...and register our pool with it.
//
driver.registerPool("example", connectionPool);
//
// Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
// to access our pool of Connections.
//
}
Aggregations