public class PoolingConnection extends DelegatingConnection<Connection> implements KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
DelegatingConnection that pools PreparedStatements.
 
 The prepareStatement(java.lang.String) and prepareCall(java.lang.String) methods, rather than creating a new PreparedStatement each
 time, may actually pull the statement from a pool of unused statements. The Statement.close() method of
 the returned statement doesn't actually close the statement, but rather returns it to the pool. (See
 PoolablePreparedStatement, PoolableCallableStatement.)
 
PoolablePreparedStatement| Modifier and Type | Class and Description | 
|---|---|
static class  | 
PoolingConnection.StatementType
Statement types. 
 | 
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Constructor and Description | 
|---|
PoolingConnection(Connection connection)
Constructor. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
activateObject(PStmtKey key,
              PooledObject<DelegatingPreparedStatement> pooledObject)
KeyedPooledObjectFactory method for activating pooled statements. | 
void | 
close()
Closes and frees all  
PreparedStatements or CallableStatements from the pool, and close the
 underlying connection. | 
protected PStmtKey | 
createKey(String sql)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         int autoGeneratedKeys)  | 
protected PStmtKey | 
createKey(String sql,
         int[] columnIndexes)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         int resultSetType,
         int resultSetConcurrency)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         int resultSetType,
         int resultSetConcurrency,
         int resultSetHoldability)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         int resultSetType,
         int resultSetConcurrency,
         int resultSetHoldability,
         PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         int resultSetType,
         int resultSetConcurrency,
         PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments. 
 | 
protected PStmtKey | 
createKey(String sql,
         String[] columnNames)
Creates a PStmtKey for the given arguments. 
 | 
void | 
destroyObject(PStmtKey key,
             PooledObject<DelegatingPreparedStatement> pooledObject)
KeyedPooledObjectFactory method for destroying PoolablePreparedStatements and PoolableCallableStatements. | 
PooledObject<DelegatingPreparedStatement> | 
makeObject(PStmtKey key)
KeyedPooledObjectFactory method for creating PoolablePreparedStatements or
 PoolableCallableStatements. | 
protected String | 
normalizeSQL(String sql)
Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original. 
 | 
void | 
passivateObject(PStmtKey key,
               PooledObject<DelegatingPreparedStatement> pooledObject)
 | 
CallableStatement | 
prepareCall(String sql)
Creates or obtains a  
CallableStatement from the pool. | 
CallableStatement | 
prepareCall(String sql,
           int resultSetType,
           int resultSetConcurrency)
Creates or obtains a  
CallableStatement from the pool. | 
CallableStatement | 
prepareCall(String sql,
           int resultSetType,
           int resultSetConcurrency,
           int resultSetHoldability)
Creates or obtains a  
CallableStatement from the pool. | 
PreparedStatement | 
prepareStatement(String sql)
Creates or obtains a  
PreparedStatement from the pool. | 
PreparedStatement | 
prepareStatement(String sql,
                int autoGeneratedKeys)  | 
PreparedStatement | 
prepareStatement(String sql,
                int[] columnIndexes)
Creates or obtains a  
PreparedStatement from the pool. | 
PreparedStatement | 
prepareStatement(String sql,
                int resultSetType,
                int resultSetConcurrency)
Creates or obtains a  
PreparedStatement from the pool. | 
PreparedStatement | 
prepareStatement(String sql,
                int resultSetType,
                int resultSetConcurrency,
                int resultSetHoldability)
Creates or obtains a  
PreparedStatement from the pool. | 
PreparedStatement | 
prepareStatement(String sql,
                String[] columnNames)
Creates or obtains a  
PreparedStatement from the pool. | 
void | 
setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
Sets the prepared statement pool. 
 | 
String | 
toString()
Returns a string representation of the metadata associated with the innermost delegate connection. 
 | 
boolean | 
validateObject(PStmtKey key,
              PooledObject<DelegatingPreparedStatement> pooledObject)
KeyedPooledObjectFactory method for validating pooled statements. | 
abort, activate, checkOpen, clearCachedState, clearWarnings, closeInternal, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, innermostDelegateEquals, isClosed, isClosedInternal, isReadOnly, isValid, isWrapperFor, nativeSQL, passivate, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, unwrapaddTrace, clearTrace, getLastUsed, getTrace, removeTrace, setLastUsed, setLastUsedpublic PoolingConnection(Connection connection)
connection - the underlying Connection.public void activateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception
KeyedPooledObjectFactory method for activating pooled statements.activateObject in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - ignoredpooledObject - wrapped pooled statement to be activatedExceptionpublic void close() throws SQLException
PreparedStatements or CallableStatements from the pool, and close the
 underlying connection.close in interface AutoCloseableclose in interface Connectionclose in class DelegatingConnection<Connection>SQLExceptionprotected PStmtKey createKey(String sql)
sql - the SQL string used to define the statementprotected PStmtKey createKey(String sql, int[] columnIndexes)
sql - the SQL string used to define the statementcolumnIndexes - column indexesprotected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency)
sql - the SQL string used to define the statementresultSetType - result set typeresultSetConcurrency - result set concurrencyprotected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
sql - the SQL string used to define the statementresultSetType - result set typeresultSetConcurrency - result set concurrencyresultSetHoldability - result set holdabilityprotected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType)
sql - the SQL string used to define the statementresultSetType - result set typeresultSetConcurrency - result set concurrencyresultSetHoldability - result set holdabilitystatementType - statement typeprotected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType)
sql - the SQL string used to define the statementresultSetType - result set typeresultSetConcurrency - result set concurrencystatementType - statement typeprotected PStmtKey createKey(String sql, PoolingConnection.StatementType statementType)
sql - the SQL string used to define the statementstatementType - statement typeprotected PStmtKey createKey(String sql, String[] columnNames)
sql - the SQL string used to define the statementcolumnNames - column namespublic void destroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception
KeyedPooledObjectFactory method for destroying PoolablePreparedStatements and PoolableCallableStatements.
 Closes the underlying statement.destroyObject in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - ignoredpooledObject - the wrapped pooled statement to be destroyed.Exceptionpublic PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) throws Exception
KeyedPooledObjectFactory method for creating PoolablePreparedStatements or
 PoolableCallableStatements. The stmtType field in the key determines whether a
 PoolablePreparedStatement or PoolableCallableStatement is created.makeObject in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - the key for the PreparedStatement to be createdExceptioncreateKey(String, int, int, StatementType)protected String normalizeSQL(String sql)
sql - The statement to be normalized.public void passivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception
KeyedPooledObjectFactory method for passivating PreparedStatements or CallableStatements.
 Invokes PreparedStatement.clearParameters().passivateObject in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - ignoredpooledObject - a wrapped PreparedStatementExceptionpublic CallableStatement prepareCall(String sql) throws SQLException
CallableStatement from the pool.prepareCall in interface ConnectionprepareCall in class DelegatingConnection<Connection>sql - the SQL string used to define the CallableStatementPoolableCallableStatementSQLException - Wraps an underlying exception.public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
CallableStatement from the pool.prepareCall in interface ConnectionprepareCall in class DelegatingConnection<Connection>sql - the SQL string used to define the CallableStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyPoolableCallableStatementSQLException - Wraps an underlying exception.public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
CallableStatement from the pool.prepareCall in interface ConnectionprepareCall in class DelegatingConnection<Connection>sql - the SQL string used to define the CallableStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyresultSetHoldability - result set holdabilityPoolableCallableStatementSQLException - Wraps an underlying exception.public PreparedStatement prepareStatement(String sql) throws SQLException
PreparedStatement from the pool.prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>sql - the SQL string used to define the PreparedStatementPoolablePreparedStatementSQLExceptionpublic PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>SQLExceptionpublic PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
PreparedStatement from the pool.prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>sql - the SQL string used to define the PreparedStatementcolumnIndexes - column indexesPoolablePreparedStatementSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
PreparedStatement from the pool.prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>sql - the SQL string used to define the PreparedStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyPoolablePreparedStatementSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
PreparedStatement from the pool.prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>sql - the SQL string used to define the PreparedStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyresultSetHoldability - result set holdabilityPoolablePreparedStatementSQLExceptionpublic PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
PreparedStatement from the pool.prepareStatement in interface ConnectionprepareStatement in class DelegatingConnection<Connection>sql - the SQL string used to define the PreparedStatementcolumnNames - column namesPoolablePreparedStatementSQLExceptionpublic void setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
pool - the prepared statement pool.public String toString()
DelegatingConnectiontoString in class DelegatingConnection<Connection>public boolean validateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject)
KeyedPooledObjectFactory method for validating pooled statements. Currently always returns true.validateObject in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - ignoredpooledObject - ignoredtrueCopyright © 2001–2018 The Apache Software Foundation. All rights reserved.