Class PoolingConnection
java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
org.datanucleus.store.rdbms.datasource.dbcp2.DelegatingConnection<Connection>
org.datanucleus.store.rdbms.datasource.dbcp2.PoolingConnection
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper, KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>, TrackedUse
public class PoolingConnection
extends DelegatingConnection<Connection>
implements 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
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields 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, PooledObject<DelegatingPreparedStatement> pooledObject) KeyedPooledObjectFactorymethod for activating pooled statements.voidclose()Closes and frees allPreparedStatements orCallableStatements from the pool, and close the underlying connection.protected PStmtKeyCreates a PStmtKey for the given arguments.protected PStmtKeyprotected PStmtKeyCreates a PStmtKey for the given arguments.protected PStmtKeyCreates a PStmtKey for the given arguments.protected PStmtKeyCreates a PStmtKey for the given arguments.protected PStmtKeycreateKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType) Creates a PStmtKey for the given arguments.protected PStmtKeycreateKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType) Creates a PStmtKey for the given arguments.protected PStmtKeyCreates a PStmtKey for the given arguments.protected PStmtKeycreateKey(String sql, PoolingConnection.StatementType statementType) Creates a PStmtKey for the given arguments.voiddestroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) KeyedPooledObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements.private Stringprivate StringmakeObject(PStmtKey key) KeyedPooledObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements.protected StringnormalizeSQL(String sql) Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original.voidpassivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) prepareCall(String sql) Creates or obtains aCallableStatementfrom the pool.prepareCall(String sql, int resultSetType, int resultSetConcurrency) Creates or obtains aCallableStatementfrom the pool.prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates or obtains aCallableStatementfrom the pool.prepareStatement(String sql) Creates or obtains aPreparedStatementfrom the pool.prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) Creates or obtains aPreparedStatementfrom the pool.prepareStatement(String sql, int resultSetType, int resultSetConcurrency) Creates or obtains aPreparedStatementfrom the pool.prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates or obtains aPreparedStatementfrom the pool.prepareStatement(String sql, String[] columnNames) Creates or obtains aPreparedStatementfrom the pool.voidSets the prepared statement pool.toString()Returns a string representation of the metadata associated with the innermost delegate connection.booleanvalidateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) KeyedPooledObjectFactorymethod for validating pooled statements.Methods inherited from class DelegatingConnection
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, handleExceptionNoThrow, 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, unwrapMethods inherited from class AbandonedTrace
addTrace, clearTrace, getLastUsed, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
pstmtPool
Pool ofPreparedStatements. andCallableStatements
-
-
Constructor Details
-
PoolingConnection
Constructor.- Parameters:
connection- the underlyingConnection.
-
-
Method Details
-
activateObject
public void activateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception KeyedPooledObjectFactorymethod for activating pooled statements.- Specified by:
activateObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredpooledObject- wrapped pooled statement to be activated- Throws:
Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
-
close
Closes and frees allPreparedStatements orCallableStatements from the pool, and close the underlying connection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classDelegatingConnection<Connection>- Throws:
SQLException
-
createKey
-
createKey
-
createKey
-
createKey
Creates a PStmtKey for the given arguments.- Parameters:
sql- the SQL string used to define the statementresultSetType- result set typeresultSetConcurrency- result set concurrency- Returns:
- the PStmtKey created for the given arguments.
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates a PStmtKey for the given arguments.- Parameters:
sql- the SQL string used to define the statementresultSetType- result set typeresultSetConcurrency- result set concurrencyresultSetHoldability- result set holdability- Returns:
- the PStmtKey created for the given arguments.
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType) Creates a PStmtKey for the given arguments.- Parameters:
sql- the SQL string used to define the statementresultSetType- result set typeresultSetConcurrency- result set concurrencyresultSetHoldability- result set holdabilitystatementType- statement type- Returns:
- the PStmtKey created for the given arguments.
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType) Creates a PStmtKey for the given arguments.- Parameters:
sql- the SQL string used to define the statementresultSetType- result set typeresultSetConcurrency- result set concurrencystatementType- statement type- Returns:
- the PStmtKey created for the given arguments.
-
createKey
Creates a PStmtKey for the given arguments.- Parameters:
sql- the SQL string used to define the statementstatementType- statement type- Returns:
- the PStmtKey created for the given arguments.
-
createKey
-
destroyObject
public void destroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception KeyedPooledObjectFactorymethod for destroying PoolablePreparedStatements and PoolableCallableStatements. Closes the underlying statement.- Specified by:
destroyObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredpooledObject- the wrapped pooled statement to be destroyed.- Throws:
Exception- should be avoided as it may be swallowed by the pool implementation.- See Also:
-
getCatalogOrNull
-
getSchemaOrNull
-
makeObject
KeyedPooledObjectFactorymethod for creatingPoolablePreparedStatements orPoolableCallableStatements. ThestmtTypefield in the key determines whether a PoolablePreparedStatement or PoolableCallableStatement is created.- Specified by:
makeObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- the key for thePreparedStatementto be created- Returns:
- a
PooledObjectwrapping an instance that can be served by the pool. - Throws:
Exception- if there is a problem creating a new instance, this will be propagated to the code requesting an object.- See Also:
-
normalizeSQL
-
passivateObject
public void passivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception KeyedPooledObjectFactorymethod for passivatingPreparedStatements orCallableStatements. InvokesPreparedStatement.clearParameters().- Specified by:
passivateObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredpooledObject- a wrappedPreparedStatement- Throws:
Exception- if there is a problem passivatingobj, this exception may be swallowed by the pool.- See Also:
-
prepareCall
Creates or obtains 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- Wraps an underlying exception.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Creates or obtains 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- Wraps an underlying exception.
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Creates or obtains 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 concurrencyresultSetHoldability- result set holdability- Returns:
- a
PoolableCallableStatement - Throws:
SQLException- Wraps an underlying exception.
-
prepareStatement
Creates or obtains 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
Creates or obtains aPreparedStatementfrom the pool.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Parameters:
sql- the SQL string used to define the PreparedStatementcolumnIndexes- column indexes- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Creates or obtains 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
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Creates or obtains 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 concurrencyresultSetHoldability- result set holdability- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareStatement
Creates or obtains aPreparedStatementfrom the pool.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Parameters:
sql- the SQL string used to define the PreparedStatementcolumnNames- column names- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
setStatementPool
Sets the prepared statement pool.- Parameters:
pool- the prepared statement pool.
-
toString
Description copied from class:DelegatingConnectionReturns a string representation of the metadata associated with the innermost delegate connection.- Overrides:
toStringin classDelegatingConnection<Connection>
-
validateObject
KeyedPooledObjectFactorymethod for validating pooled statements. Currently always returns true.- Specified by:
validateObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredpooledObject- ignored- Returns:
true
-