Class PoolingConnection
java.lang.Object
org.apache.commons.dbcp2.AbandonedTrace
org.apache.commons.dbcp2.DelegatingConnection<Connection>
org.apache.commons.dbcp2.PoolingConnection
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper, org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>, org.apache.commons.pool2.TrackedUse
public class PoolingConnection
extends DelegatingConnection<Connection>
implements org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>
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.)
- Since:
- 2.0
- Version:
- $Id: PoolingConnection.java 1658644 2015-02-10 08:59:07Z tn $
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) KeyedPooledObjectFactorymethod for activating pooled statements.voidclose()Close and free allPreparedStatements orCallableStatements from the pool, and close the underlying connection.voiddestroyObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) KeyedPooledObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements.org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) KeyedPooledObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements.voidpassivateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) 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 autoGeneratedKeys) prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Create or obtain aPreparedStatementfrom the pool.voidsetStatementPool(org.apache.commons.pool2.KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> pool) toString()Returns a string representation of the metadata associated with the innermost delegate connection.booleanvalidateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) KeyedPooledObjectFactorymethod for validating pooled statements.Methods inherited from class DelegatingConnection
abort, clearCachedState, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, unwrapMethods inherited from class AbandonedTrace
getLastUsedMethods inherited from interface Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Constructor Details
-
PoolingConnection
-
-
Method Details
-
setStatementPool
public void setStatementPool(org.apache.commons.pool2.KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> pool) -
close
Close and free allPreparedStatements orCallableStatements from the pool, and close the underlying connection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classDelegatingConnection<Connection>- Throws:
SQLException
-
prepareStatement
Create or obtain aPreparedStatementfrom the pool.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Parameters:
sql- the sql string used to define the PreparedStatement- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- 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<Connection>- 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<Connection>- Parameters:
sql- the sql string used to define the CallableStatement- Returns:
- a
PoolableCallableStatement - Throws:
SQLException
-
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<Connection>- Parameters:
sql- the sql string used to define the CallableStatementresultSetType- result set typeresultSetConcurrency- result set concurrency- Returns:
- a
PoolableCallableStatement - Throws:
SQLException
-
makeObject
public org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) throws Exception KeyedPooledObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements. ThestmtTypefield in the key determines whether a PoolablePreparedStatement or PoolableCallableStatement is created.- Specified by:
makeObjectin interfaceorg.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- the key for thePreparedStatementto be created- Throws:
Exception- See Also:
-
destroyObject
public void destroyObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws Exception KeyedPooledObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements. Closes the underlying statement.- Specified by:
destroyObjectin interfaceorg.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredp- the wrapped pooled statement to be destroyed.- Throws:
Exception
-
validateObject
public boolean validateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) KeyedPooledObjectFactorymethod for validating pooled statements. Currently always returns true.- Specified by:
validateObjectin interfaceorg.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredp- ignored- Returns:
true
-
activateObject
public void activateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws Exception KeyedPooledObjectFactorymethod for activating pooled statements.- Specified by:
activateObjectin interfaceorg.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredp- wrapped pooled statement to be activated- Throws:
Exception
-
passivateObject
public void passivateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws Exception KeyedPooledObjectFactorymethod for passivatingPreparedStatements orCallableStatements. InvokesPreparedStatement.clearParameters().- Specified by:
passivateObjectin interfaceorg.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredp- a wrappedPreparedStatement- Throws:
Exception
-
toString
Description copied from class:DelegatingConnectionReturns a string representation of the metadata associated with the innermost delegate connection.- Overrides:
toStringin classDelegatingConnection<Connection>
-