in src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java [416:455]
public PooledConnection getPooledConnection(final String pooledUserName, final String pooledUserPassword) throws SQLException {
getConnectionCalled = true;
if (connectionProperties != null) {
update(connectionProperties, Constants.KEY_USER, pooledUserName);
update(connectionProperties, Constants.KEY_PASSWORD, pooledUserPassword);
}
// Workaround for buggy WebLogic 5.1 class loader - ignore ClassCircularityError upon first invocation.
PooledConnectionImpl pooledConnection = null;
try {
pooledConnection = getPooledConnectionImpl(pooledUserName, pooledUserPassword);
} catch (final ClassCircularityError e) {
pooledConnection = getPooledConnectionImpl(pooledUserName, pooledUserPassword);
}
if (isPoolPreparedStatements()) {
final GenericKeyedObjectPoolConfig<DelegatingPreparedStatement> config = new GenericKeyedObjectPoolConfig<>();
config.setMaxTotalPerKey(Integer.MAX_VALUE);
config.setBlockWhenExhausted(false);
config.setMaxWait(Duration.ZERO);
config.setMaxIdlePerKey(getMaxIdle());
if (getMaxPreparedStatements() <= 0) {
// Since there is no limit, create a prepared statement pool with an eviction thread;
// evictor settings are the same as the connection pool settings.
config.setTimeBetweenEvictionRuns(getDurationBetweenEvictionRuns());
config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
config.setMinEvictableIdleDuration(getMinEvictableIdleDuration());
} else {
// Since there is a limit, create a prepared statement pool without an eviction thread;
// pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
// see org.apache.commons.pool2.impl.GenericKeyedObjectPool.clearOldest method
config.setMaxTotal(getMaxPreparedStatements());
config.setTimeBetweenEvictionRuns(Duration.ofMillis(-1));
config.setNumTestsPerEvictionRun(0);
config.setMinEvictableIdleDuration(Duration.ZERO);
}
@SuppressWarnings("resource") // PooledConnectionImpl closes
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> stmtPool = new GenericKeyedObjectPool<>(pooledConnection, config);
pooledConnection.setStatementPool(stmtPool);
}
return pooledConnection;
}