Search in sources :

Example 1 with SwallowedExceptionLogger

use of org.datanucleus.store.rdbms.datasource.dbcp2.SwallowedExceptionLogger in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method createConnectionPool.

/**
 * Creates a connection pool for this datasource.  This method only exists
 * so subclasses can replace the implementation class.
 *
 * This implementation configures all pool properties other than
 * timeBetweenEvictionRunsMillis.  Setting that property is deferred to
 * {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
 * to a positive value causes {@link GenericObjectPool}'s eviction timer
 * to be started.
 */
protected void createConnectionPool(PoolableConnectionFactory factory) {
    // Create an object pool to contain our active connections
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    updateJmxName(config);
    // Disable JMX on the underlying pool if the DS is not registered.
    config.setJmxEnabled(registeredJmxName != null);
    GenericObjectPool<PoolableConnection> gop;
    if (abandonedConfig != null && (abandonedConfig.getRemoveAbandonedOnBorrow() || abandonedConfig.getRemoveAbandonedOnMaintenance())) {
        gop = new GenericObjectPool<>(factory, config, abandonedConfig);
    } else {
        gop = new GenericObjectPool<>(factory, config);
    }
    gop.setMaxTotal(maxTotal);
    gop.setMaxIdle(maxIdle);
    gop.setMinIdle(minIdle);
    gop.setMaxWaitMillis(maxWaitMillis);
    gop.setTestOnCreate(testOnCreate);
    gop.setTestOnBorrow(testOnBorrow);
    gop.setTestOnReturn(testOnReturn);
    gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    gop.setLifo(lifo);
    gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
    gop.setEvictionPolicyClassName(evictionPolicyClassName);
    factory.setPool(gop);
    connectionPool = gop;
}
Also used : GenericObjectPoolConfig(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig)

Example 2 with SwallowedExceptionLogger

use of org.datanucleus.store.rdbms.datasource.dbcp2.SwallowedExceptionLogger in project datanucleus-rdbms by datanucleus.

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.datanucleus.store.rdbms.datasource.dbcp2.SwallowedExceptionLogger) GenericObjectPool(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool)

Example 3 with SwallowedExceptionLogger

use of org.datanucleus.store.rdbms.datasource.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(), 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);
    }
}
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)2 SwallowedExceptionLogger (org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger)1 GenericObjectPool (org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)1 SwallowedExceptionLogger (org.datanucleus.store.rdbms.datasource.dbcp2.SwallowedExceptionLogger)1 GenericObjectPool (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool)1 GenericObjectPoolConfig (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig)1