use of javax.sql.ConnectionPoolDataSource in project pgjdbc by pgjdbc.
the class PGDataSourceFactoryTest method testCreateConnectionPoolDataSourceConfigured.
@Test
public void testCreateConnectionPoolDataSourceConfigured() throws Exception {
Properties properties = new Properties();
properties.put(DataSourceFactory.JDBC_DATABASE_NAME, "db");
ConnectionPoolDataSource dataSource = dataSourceFactory.createConnectionPoolDataSource(properties);
Assert.assertNotNull(dataSource);
Assert.assertTrue(dataSource instanceof ConnectionPool);
ConnectionPool connectionPoolDataSource = (ConnectionPool) dataSource;
Assert.assertEquals("db", connectionPoolDataSource.getDatabaseName());
}
use of javax.sql.ConnectionPoolDataSource in project commons-dbcp by apache.
the class SharedPoolDataSource method registerPool.
private void registerPool(final String userName, final String password) throws NamingException, SQLException {
final ConnectionPoolDataSource cpds = testCPDS(userName, password);
// Create an object pool to contain our PooledConnections
factory = new KeyedCPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeoutDuration(), isRollbackAfterValidation());
factory.setMaxConn(getMaxConnDuration());
final GenericKeyedObjectPoolConfig<PooledConnectionAndInfo> config = new GenericKeyedObjectPoolConfig<>();
config.setBlockWhenExhausted(getDefaultBlockWhenExhausted());
config.setEvictionPolicyClassName(getDefaultEvictionPolicyClassName());
config.setLifo(getDefaultLifo());
config.setMaxIdlePerKey(getDefaultMaxIdle());
config.setMaxTotal(getMaxTotal());
config.setMaxTotalPerKey(getDefaultMaxTotal());
config.setMaxWait(getDefaultMaxWait());
config.setMinEvictableIdleTime(getDefaultMinEvictableIdleDuration());
config.setMinIdlePerKey(getDefaultMinIdle());
config.setNumTestsPerEvictionRun(getDefaultNumTestsPerEvictionRun());
config.setSoftMinEvictableIdleTime(getDefaultSoftMinEvictableIdleDuration());
config.setTestOnCreate(getDefaultTestOnCreate());
config.setTestOnBorrow(getDefaultTestOnBorrow());
config.setTestOnReturn(getDefaultTestOnReturn());
config.setTestWhileIdle(getDefaultTestWhileIdle());
config.setTimeBetweenEvictionRuns(getDefaultDurationBetweenEvictionRuns());
final KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> tmpPool = new GenericKeyedObjectPool<>(factory, config);
factory.setPool(tmpPool);
pool = tmpPool;
}
use of javax.sql.ConnectionPoolDataSource in project sqlite-jdbc by xerial.
the class SQLiteConnectionPoolDataSourceTest method proxyConnectionCloseTest.
@Disabled
@Test
public void proxyConnectionCloseTest() throws SQLException {
ConnectionPoolDataSource ds = new SQLiteConnectionPoolDataSource();
PooledConnection pooledConn = ds.getPooledConnection();
System.out.println("pooledConn: " + pooledConn.getClass());
Connection handle = pooledConn.getConnection();
System.out.println("pooledConn.getConnection: " + handle.getClass());
Statement st = handle.createStatement();
System.out.println("statement: " + st.getClass());
Connection stConn = handle.createStatement().getConnection();
System.out.println("statement connection:" + stConn.getClass());
// This closes the physical connection, not the proxy
stConn.close();
Connection handle2 = pooledConn.getConnection();
}
use of javax.sql.ConnectionPoolDataSource in project sqlite-jdbc by xerial.
the class SQLiteConnectionPoolDataSourceTest method connectionTest.
@Test
public void connectionTest() throws SQLException {
ConnectionPoolDataSource ds = new SQLiteConnectionPoolDataSource();
PooledConnection pooledConn = ds.getPooledConnection();
Connection handle = pooledConn.getConnection();
assertFalse(handle.isClosed());
assertTrue(handle.createStatement().execute("select 1"));
Connection handle2 = pooledConn.getConnection();
assertTrue(handle.isClosed());
try {
handle.createStatement().execute("select 1");
fail();
} catch (SQLException e) {
assertEquals("Connection is closed", e.getMessage());
}
assertTrue(handle2.createStatement().execute("select 1"));
handle2.close();
handle = pooledConn.getConnection();
assertTrue(handle.createStatement().execute("select 1"));
pooledConn.close();
assertTrue(handle.isClosed());
}
use of javax.sql.ConnectionPoolDataSource in project bboss by bbossgroups.
the class PerUserPoolDataSource method registerPool.
private synchronized void registerPool(String username, String password) throws javax.naming.NamingException, SQLException {
ConnectionPoolDataSource cpds = testCPDS(username, password);
Integer userMax = getPerUserMaxActive(username);
int maxActive = (userMax == null) ? getDefaultMaxActive() : userMax.intValue();
userMax = getPerUserMaxIdle(username);
int maxIdle = (userMax == null) ? getDefaultMaxIdle() : userMax.intValue();
userMax = getPerUserMaxWait(username);
int maxWait = (userMax == null) ? getDefaultMaxWait() : userMax.intValue();
// Create an object pool to contain our PooledConnections
GenericObjectPool pool = new GenericObjectPool(null);
pool.setMaxActive(maxActive);
pool.setMaxIdle(maxIdle);
pool.setMaxWait(maxWait);
pool.setWhenExhaustedAction(whenExhaustedAction(maxActive, maxWait));
pool.setTestOnBorrow(getTestOnBorrow());
pool.setTestOnReturn(getTestOnReturn());
pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
pool.setTestWhileIdle(getTestWhileIdle());
// Set up the factory we will use (passing the pool associates
// the factory with the pool, so we do not have to do so
// explicitly)
CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, pool, getValidationQuery(), isRollbackAfterValidation(), username, password);
Object old = managers.put(getPoolKey(username, password), factory);
if (old != null) {
throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
}
}
Aggregations