Search in sources :

Example 1 with SwallowedExceptionLogger

use of org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger 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(), getValidationQueryTimeout(), isRollbackAfterValidation(), username, password);
    factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
    // 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.setMaxWaitMillis(getPerUserMaxWaitMillis(username));
    pool.setMinEvictableIdleTimeMillis(getPerUserMinEvictableIdleTimeMillis(username));
    pool.setMinIdle(getPerUserMinIdle(username));
    pool.setNumTestsPerEvictionRun(getPerUserNumTestsPerEvictionRun(username));
    pool.setSoftMinEvictableIdleTimeMillis(getPerUserSoftMinEvictableIdleTimeMillis(username));
    pool.setTestOnCreate(getPerUserTestOnCreate(username));
    pool.setTestOnBorrow(getPerUserTestOnBorrow(username));
    pool.setTestOnReturn(getPerUserTestOnReturn(username));
    pool.setTestWhileIdle(getPerUserTestWhileIdle(username));
    pool.setTimeBetweenEvictionRunsMillis(getPerUserTimeBetweenEvictionRunsMillis(username));
    pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
    final Object old = managers.put(getPoolKey(username), factory);
    if (old != null) {
        throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SwallowedExceptionLogger(org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger) GenericObjectPool(org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)

Aggregations

ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1 SwallowedExceptionLogger (org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger)1 GenericObjectPool (org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)1