Class PoolingConnection
java.lang.Object
org.apache.commons.dbcp.AbandonedTrace
org.apache.commons.dbcp.DelegatingConnection
org.apache.commons.dbcp.PoolingConnection
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper, org.apache.commons.pool.KeyedPoolableObjectFactory
public class PoolingConnection
extends DelegatingConnection
implements Connection, org.apache.commons.pool.KeyedPoolableObjectFactory
A
DelegatingConnection that pools PreparedStatements.
The prepareStatement(String) and prepareCall(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.)
- Version:
- $Revision: 885261 $ $Date: 2009-11-29 15:07:02 -0500 (Sun, 29 Nov 2009) $
- Author:
- Rodney Waldhoff, Dirk Verbeeck
- See Also:
-
Field Summary
Fields inherited from interface Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.PoolingConnection(Connection c, org.apache.commons.pool.KeyedObjectPool pool) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidactivateObject(Object key, Object obj) KeyedPoolableObjectFactorymethod for activating pooled statements.voidclose()Close and free allPreparedStatements orCallableStatementfrom the pool, and close the underlying connection.voiddestroyObject(Object key, Object obj) KeyedPoolableObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements.intmakeObject(Object obj) KeyedPoolableObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements.voidpassivateObject(Object key, Object obj) prepareCall(String sql) Create or obtain aCallableStatementfrom the pool.prepareCall(String sql, int resultSetType, int resultSetConcurrency) Create or obtain aCallableStatementfrom the pool.prepareStatement(String sql) Create or obtain aPreparedStatementfrom the pool.prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Create or obtain aPreparedStatementfrom the pool.voidsetNetworkTimeout(Executor executor, int milliseconds) voidtoString()Returns a string representation of the metadata associated with the innnermost delegate connection.booleanvalidateObject(Object key, Object obj) KeyedPoolableObjectFactorymethod for validating pooled statements.Methods inherited from class DelegatingConnection
clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, equals, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getDelegate, getHoldability, getInnermostDelegate, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, hashCode, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setDelegate, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap, unwrapMethods inherited from class AbandonedTrace
printStackTraceMethods inherited from interface Connection
beginRequest, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, endRequest, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setReadOnly, setSavepoint, setSavepoint, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTransactionIsolation, setTypeMapMethods inherited from interface Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
PoolingConnection
-
PoolingConnection
Constructor.- Parameters:
c- the underlyingConnection.pool-KeyedObjectPoolofPreparedStatements andCallableStatements.
-
-
Method Details
-
close
Close and free allPreparedStatements orCallableStatementfrom the pool, and close the underlying connection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classDelegatingConnection- Throws:
SQLException
-
prepareStatement
Create or obtain aPreparedStatementfrom the pool.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Parameters:
sql- the sql string used to define the PreparedStatement- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Create or obtain aPreparedStatementfrom the pool.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection- Parameters:
sql- the sql string used to define the PreparedStatementresultSetType- result set typeresultSetConcurrency- result set concurrency- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareCall
Create or obtain aCallableStatementfrom the pool.- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection- Parameters:
sql- the sql string used to define the CallableStatement- Returns:
- a
PoolableCallableStatement - Throws:
SQLException- Since:
- 1.3
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Create or obtain aCallableStatementfrom the pool.- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection- Parameters:
sql- the sql string used to define the CallableStatementresultSetType- result set typeresultSetConcurrency- result set concurrency- Returns:
- a
PoolableCallableStatement - Throws:
SQLException- Since:
- 1.3
-
makeObject
KeyedPoolableObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements. ThestmtTypefield in the key determines whether a PoolablePreparedStatement or PoolableCallableStatement is created.- Specified by:
makeObjectin interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory- Parameters:
obj- the key for thePreparedStatementto be created- Throws:
Exception- See Also:
-
destroyObject
KeyedPoolableObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements. Closes the underlying statement.- Specified by:
destroyObjectin interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory- Parameters:
key- ignoredobj- the pooled statement to be destroyed.- Throws:
Exception
-
validateObject
-
activateObject
KeyedPoolableObjectFactorymethod for activating pooled statements.- Specified by:
activateObjectin interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory- Parameters:
key- ignoredobj- pooled statement to be activated- Throws:
Exception
-
passivateObject
KeyedPoolableObjectFactorymethod for passivatingPreparedStatements orCallableStatements. InvokesPreparedStatement.clearParameters().- Specified by:
passivateObjectin interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory- Parameters:
key- ignoredobj- aPreparedStatement- Throws:
Exception
-
toString
Description copied from class:DelegatingConnectionReturns a string representation of the metadata associated with the innnermost delegate connection.- Overrides:
toStringin classDelegatingConnection
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Overrides:
getNetworkTimeoutin classDelegatingConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Overrides:
setNetworkTimeoutin classDelegatingConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Overrides:
abortin classDelegatingConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Overrides:
getSchemain classDelegatingConnection- Throws:
SQLException
-
setSchema
- Specified by:
setSchemain interfaceConnection- Overrides:
setSchemain classDelegatingConnection- Throws:
SQLException
-