use of javax.sql.ConnectionPoolDataSource in project tomcat by apache.
the class PerUserPoolDataSource method registerPool.
private synchronized void registerPool(final String userName, final String password) throws NamingException, SQLException {
final ConnectionPoolDataSource cpds = testCPDS(userName, password);
// 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)
final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeoutDuration(), isRollbackAfterValidation(), userName, password);
factory.setMaxConn(getMaxConnDuration());
// Create an object pool to contain our PooledConnections
final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory);
factory.setPool(pool);
pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(userName));
pool.setEvictionPolicyClassName(getPerUserEvictionPolicyClassName(userName));
pool.setLifo(getPerUserLifo(userName));
pool.setMaxIdle(getPerUserMaxIdle(userName));
pool.setMaxTotal(getPerUserMaxTotal(userName));
pool.setMaxWait(Duration.ofMillis(getPerUserMaxWaitMillis(userName)));
pool.setMinEvictableIdle(getPerUserMinEvictableIdleDuration(userName));
pool.setMinIdle(getPerUserMinIdle(userName));
pool.setNumTestsPerEvictionRun(getPerUserNumTestsPerEvictionRun(userName));
pool.setSoftMinEvictableIdle(getPerUserSoftMinEvictableIdleDuration(userName));
pool.setTestOnCreate(getPerUserTestOnCreate(userName));
pool.setTestOnBorrow(getPerUserTestOnBorrow(userName));
pool.setTestOnReturn(getPerUserTestOnReturn(userName));
pool.setTestWhileIdle(getPerUserTestWhileIdle(userName));
pool.setTimeBetweenEvictionRuns(getPerUserDurationBetweenEvictionRuns(userName));
pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
final PooledConnectionManager old = managers.put(getPoolKey(userName), factory);
if (old != null) {
throw new IllegalStateException("Pool already contains an entry for this user/password: " + userName);
}
}
use of javax.sql.ConnectionPoolDataSource in project mssql-jdbc by Microsoft.
the class JDBC43Test method connectionPoolDataSourceTest.
/**
* Tests that we are throwing the unsupported exception for createPooledConnectionBuilder()
* @throws SQLException
* @throws TestAbortedException
* @since 1.9
*/
@Test
public void connectionPoolDataSourceTest() throws TestAbortedException, SQLException {
assumeTrue(Util.supportJDBC43(connection));
ConnectionPoolDataSource ds = new SQLServerConnectionPoolDataSource();
try {
superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build();
} catch (SQLException e) {
assert (e.getMessage().contains("not implemented"));
}
try {
shardingKey = ds.createShardingKeyBuilder().subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR).build();
} catch (SQLException e) {
assert (e.getMessage().contains("not implemented"));
}
try {
PooledConnection con = ds.createPooledConnectionBuilder().user("rafa").password("tennis").shardingKey(shardingKey).superShardingKey(superShardingKey).build();
} catch (SQLException e) {
assert (e.getMessage().contains("not implemented"));
}
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class NSSecurityMechanismTest method getCPDS.
private javax.sql.ConnectionPoolDataSource getCPDS(String user, String password) {
HashMap<String, Object> attrs = new HashMap<String, Object>();
if (user != null)
attrs.put("user", user);
if (password != null)
attrs.put("password", password);
attrs = addRequiredAttributes(attrs);
ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
for (String property : attrs.keySet()) {
Object value = attrs.get(property);
JDBCDataSource.setBeanProperty(cpds, property, value);
}
return cpds;
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class DataSourcePropertiesTest method embeddedTestAttributesAsPasswordWithoutPassword_pooled.
/**
* Tests that the default password is not sent as an attribute string when
* <code>attributesAsPassword</code> is <code>true</code>. The test is run
* with a <code>ConnectionPoolDataSource</code>.
*/
public void embeddedTestAttributesAsPasswordWithoutPassword_pooled() throws Exception {
ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(ds, "password", "mypassword");
JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
// DERBY-1586 caused a malformed url error here
PooledConnection pc = ds.getPooledConnection();
Connection c = pc.getConnection();
c.close();
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class VerifySignatures method collectClassesFromConnectionPoolDataSource.
/**
* Obtain a connection from a <code>ConnectionPoolDataSource</code>
* object and perform JDBC operations on it. Collect the classes
* of all JDBC objects that are found.
*
* @param classes set into which classes are collected
* @exception SQLException if a database error occurs
*/
private static void collectClassesFromConnectionPoolDataSource(Set<ClassInfo> classes) throws SQLException {
ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
addClass(classes, cpds.getClass(), javax.sql.ConnectionPoolDataSource.class);
PooledConnection pc = cpds.getPooledConnection(TestConfiguration.getCurrent().getUserName(), TestConfiguration.getCurrent().getUserPassword());
addClass(classes, pc.getClass(), javax.sql.PooledConnection.class);
collectClassesFromConnection(pc.getConnection(), classes);
pc.close();
}
Aggregations