Class PooledConnectionImpl
java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.cpdsadapter.PooledConnectionImpl
- All Implemented Interfaces:
PooledConnection, KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>
class PooledConnectionImpl
extends Object
implements PooledConnection, KeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>
Implementation of PooledConnection that is returned by PooledConnectionDataSource.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanControls access to the underlying connection.private booleanFlag set to true, onceclose()is called.private static final Stringprivate ConnectionThe JDBC database connection that represents the physical db connection.private final DelegatingConnection<?> A DelegatingConnection used to create a PoolablePreparedStatementStub.private final Vector<ConnectionEventListener> ConnectionEventListeners.private ConnectionThe JDBC database logical connection.My pool ofPreparedStatements.private final Vector<StatementEventListener> StatementEventListeners. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) MyKeyedPooledObjectFactorymethod for activatingPreparedStatements.voidvoidprivate voidThrows an SQLException, if isClosed is truevoidclose()Closes the physical connection and marks thisPooledConnectionso that it may not be used to generate any more logicalConnections.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeycreateKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType) Creates aPStmtKeyfor the given arguments.protected PStmtKeycreateKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType) Creates aPStmtKeyfor the given arguments.protected PStmtKeyCreates aPStmtKeyfor the given arguments.protected PStmtKeycreateKey(String sql, PoolingConnection.StatementType statementType) Creates aPStmtKeyfor the given arguments.voiddestroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) MyKeyedPooledObjectFactorymethod for destroyingPreparedStatements.protected voidfinalize()Closes the physical connection and checks that the logical connection was closed as well.private StringReturns a JDBC connection.private StringbooleanReturns the value of the accessToUnderlyingConnectionAllowed property.makeObject(PStmtKey key) MyKeyedPooledObjectFactorymethod for creatingPreparedStatements.protected StringnormalizeSQL(String sql) Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original.(package private) voidSends a connectionClosed event.voidpassivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) MyKeyedPooledObjectFactorymethod for passivatingPreparedStatements.(package private) CallableStatementprepareCall(String sql) Creates or obtains aCallableStatementfrom my pool.(package private) CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency) Creates or obtains aCallableStatementfrom my pool.(package private) CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates or obtains aCallableStatementfrom my pool.(package private) PreparedStatementprepareStatement(String sql) Creates or obtains aPreparedStatementfrom my pool.(package private) PreparedStatementprepareStatement(String sql, int autoGeneratedKeys) Creates or obtains aPreparedStatementfrom my pool.(package private) PreparedStatementprepareStatement(String sql, int[] columnIndexes) (package private) PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency) Creates or obtains aPreparedStatementfrom my pool.(package private) PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) (package private) PreparedStatementprepareStatement(String sql, String[] columnNames) voidvoidvoidsetAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property.voidsetStatementPool(KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> statementPool) toString()booleanvalidateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) MyKeyedPooledObjectFactorymethod for validatingPreparedStatements.
-
Field Details
-
CLOSED
- See Also:
-
connection
The JDBC database connection that represents the physical db connection. -
delegatingConnection
A DelegatingConnection used to create a PoolablePreparedStatementStub. -
logicalConnection
The JDBC database logical connection. -
eventListeners
ConnectionEventListeners. -
statementEventListeners
StatementEventListeners. -
closed
private boolean closedFlag set to true, onceclose()is called. -
pStmtPool
My pool ofPreparedStatements. -
accessToUnderlyingConnectionAllowed
private boolean accessToUnderlyingConnectionAllowedControls access to the underlying connection.
-
-
Constructor Details
-
PooledConnectionImpl
PooledConnectionImpl(Connection connection) Wraps the real connection.- Parameters:
connection- the connection to be wrapped.
-
-
Method Details
-
activateObject
public void activateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception MyKeyedPooledObjectFactorymethod for activatingPreparedStatements.- Specified by:
activateObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- Ignored.pooledObject- Ignored.- Throws:
Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
-
addConnectionEventListener
- Specified by:
addConnectionEventListenerin interfacePooledConnection
-
addStatementEventListener
- Specified by:
addStatementEventListenerin interfacePooledConnection
-
assertOpen
Throws an SQLException, if isClosed is true- Throws:
SQLException
-
close
Closes the physical connection and marks thisPooledConnectionso that it may not be used to generate any more logicalConnections.- Specified by:
closein interfacePooledConnection- Throws:
SQLException- Thrown when an error occurs or the connection is already closed.
-
createKey
-
createKey
Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.autoGeneratedKeys- A flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYSorStatement.NO_GENERATED_KEYS.- Returns:
- a key to uniquely identify a prepared statement.
-
createKey
Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.columnIndexes- An array of column indexes indicating the columns that should be returned from the inserted row or rows.- Returns:
- a key to uniquely identify a prepared statement.
-
createKey
Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.resultSetType- A result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- A concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.- Returns:
- a key to uniquely identify a prepared statement.
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.resultSetType- a result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- A concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLEresultSetHoldability- One of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMIT.- Returns:
- a key to uniquely identify a prepared statement.
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType) Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.resultSetType- a result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEresultSetConcurrency- A concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.resultSetHoldability- One of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMIT.statementType- The SQL statement type, prepared or callable.- Returns:
- a key to uniquely identify a prepared statement.
- Since:
- 2.4.0
-
createKey
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType) Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.resultSetType- A result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- A concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.statementType- The SQL statement type, prepared or callable.- Returns:
- a key to uniquely identify a prepared statement.
- Since:
- 2.4.0
-
createKey
Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.statementType- The SQL statement type, prepared or callable.- Returns:
- a key to uniquely identify a prepared statement.
-
createKey
Creates aPStmtKeyfor the given arguments.- Parameters:
sql- The SQL statement.columnNames- An array of column names indicating the columns that should be returned from the inserted row or rows.- Returns:
- a key to uniquely identify a prepared statement.
-
destroyObject
public void destroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception MyKeyedPooledObjectFactorymethod for destroyingPreparedStatements.- Specified by:
destroyObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- ignoredpooledObject- the wrappedPreparedStatementto be destroyed.- Throws:
Exception- should be avoided as it may be swallowed by the pool implementation.- See Also:
-
finalize
-
getCatalogOrNull
-
getSchemaOrNull
-
getConnection
Returns a JDBC connection.- Specified by:
getConnectionin interfacePooledConnection- Returns:
- The database connection.
- Throws:
SQLException- if the connection is not open or the previous logical connection is still open
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying is allowed, false otherwise.
-
makeObject
MyKeyedPooledObjectFactorymethod for creatingPreparedStatements.- 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.
-
normalizeSQL
-
notifyListeners
void notifyListeners()Sends a connectionClosed event. -
passivateObject
public void passivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception MyKeyedPooledObjectFactorymethod for passivatingPreparedStatements. Currently 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 my pool.- Parameters:
sql- an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is specified using JDBC call escape syntax.- Returns:
- a default
CallableStatementobject containing the pre-compiled SQL statement. - Throws:
SQLException- Thrown if a database access error occurs or this method is called on a closed connection.- Since:
- 2.4.0
-
prepareCall
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Creates or obtains aCallableStatementfrom my pool.- Parameters:
sql- aStringobject that is the SQL statement to be sent to the database; may contain on or more '?' parameters.resultSetType- a result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- a concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.- Returns:
- a
CallableStatementobject containing the pre-compiled SQL statement that will produceResultSetobjects with the given type and concurrency. - Throws:
SQLException- Thrown if a database access error occurs, this method is called on a closed connection or the given parameters are notResultSetconstants indicating type and concurrency.- Since:
- 2.4.0
-
prepareCall
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException Creates or obtains aCallableStatementfrom my pool.- Parameters:
sql- aStringobject that is the SQL statement to be sent to the database; may contain on or more '?' parameters.resultSetType- one of the followingResultSetconstants:ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- one of the followingResultSetconstants:ResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.resultSetHoldability- one of the followingResultSetconstants:ResultSet.HOLD_CURSORS_OVER_COMMITorResultSet.CLOSE_CURSORS_AT_COMMIT.- Returns:
- a new
CallableStatementobject, containing the pre-compiled SQL statement, that will generateResultSetobjects with the given type, concurrency, and holdability. - Throws:
SQLException- Thrown if a database access error occurs, this method is called on a closed connection or the given parameters are notResultSetconstants indicating type, concurrency, and holdability.- Since:
- 2.4.0
-
prepareStatement
Creates or obtains aPreparedStatementfrom my pool.- Parameters:
sql- the SQL statement.- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException
-
prepareStatement
Creates or obtains aPreparedStatementfrom my pool.- Parameters:
sql- an SQL statement that may contain one or more '?' IN parameter placeholders.autoGeneratedKeys- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYSorStatement.NO_GENERATED_KEYS.- Returns:
- a
PoolablePreparedStatement - Throws:
SQLException- See Also:
-
prepareStatement
- Throws:
SQLException
-
prepareStatement
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException Creates or obtains aPreparedStatementfrom my pool.- Parameters:
sql- aStringobject that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters.resultSetType- a result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE.resultSetConcurrency- a concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE.- Returns:
- a
PoolablePreparedStatement. - Throws:
SQLException- See Also:
-
prepareStatement
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Throws:
SQLException
-
prepareStatement
- Throws:
SQLException
-
removeConnectionEventListener
- Specified by:
removeConnectionEventListenerin interfacePooledConnection
-
removeStatementEventListener
- Specified by:
removeStatementEventListenerin interfacePooledConnection
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false.)- Parameters:
allow- Access to the underlying connection is granted when true.
-
setStatementPool
-
validateObject
MyKeyedPooledObjectFactorymethod for validatingPreparedStatements.- Specified by:
validateObjectin interfaceKeyedPooledObjectFactory<PStmtKey, DelegatingPreparedStatement>- Parameters:
key- Ignored.pooledObject- Ignored.- Returns:
true
-
toString
-