long connIndex = connectionIndex.getAndIncrement();
if(poolStatements) {
conn = new PoolingConnection(conn);
GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
config.setMaxTotalPerKey(-1);
config.setBlockWhenExhausted(false);
config.setMaxWaitMillis(0);
config.setMaxIdlePerKey(1);
config.setMaxTotal(maxOpenPreparedStatements);
if (dataSourceJmxName != null) {
StringBuilder base = new StringBuilder(dataSourceJmxName.toString());
base.append(Constants.JMX_CONNECTION_BASE_EXT);
base.append(Long.toString(connIndex));
config.setJmxNameBase(base.toString());
config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
}
KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> stmtPool =
new GenericKeyedObjectPool<>((PoolingConnection)conn, config);
((PoolingConnection)conn).setStatementPool(stmtPool);
((PoolingConnection) conn).setCacheState(_cacheState);