Class ConnectionImpl
java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
org.datanucleus.store.rdbms.datasource.dbcp2.DelegatingConnection<Connection>
org.datanucleus.store.rdbms.datasource.dbcp2.cpdsadapter.ConnectionImpl
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper, TrackedUse
This class is the
Connection that will be returned from
PooledConnectionImpl.getConnection(). Most methods are wrappers around the JDBC 1.x
Connection. A few exceptions include preparedStatement and close. In accordance with the JDBC
specification this Connection cannot be used after closed() is called. Any further usage will result in an
SQLException.
ConnectionImpl extends DelegatingConnection to enable access to the underlying connection.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final PooledConnectionImplThe object that instantiated this objectFields inherited from interface Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionConnectionImpl(PooledConnectionImpl pooledConnection, Connection connection, boolean accessToUnderlyingConnectionAllowed) Creates aConnectionImpl. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Marks the Connection as closed, and notifies the pool that the pooled connection is available.Get the delegated connection, if allowed.Get the innermost connection, if allowed.booleanIf false, getDelegate() and getInnermostDelegate() will return null.prepareCall(String sql) If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.prepareCall(String sql, int resultSetType, int resultSetConcurrency) If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.prepareStatement(String sql) If pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) prepareStatement(String sql, int resultSetType, int resultSetConcurrency) If pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql, String[] columnNames) 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, getDelegateInternal, getHoldability, 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, toString, 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
-
accessToUnderlyingConnectionAllowed
private final boolean accessToUnderlyingConnectionAllowed -
pooledConnection
The object that instantiated this object
-
-
Constructor Details
-
ConnectionImpl
ConnectionImpl(PooledConnectionImpl pooledConnection, Connection connection, boolean accessToUnderlyingConnectionAllowed) Creates aConnectionImpl.- Parameters:
pooledConnection- The PooledConnection that is calling the ctor.connection- The JDBC 1.x Connection to wrap.accessToUnderlyingConnectionAllowed- if true, then access is allowed to the underlying connection
-
-
Method Details
-
close
Marks the Connection as closed, and notifies the pool that the pooled connection is available.In accordance with the JDBC specification this Connection cannot be used after closed() is called. Any further usage will result in an SQLException.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classDelegatingConnection<Connection>- Throws:
SQLException- The database connection couldn't be closed.
-
prepareCall
If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection<Connection>- 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
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection<Connection>- 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
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classDelegatingConnection<Connection>- 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
If pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Parameters:
sql- SQL statement to be prepared- Returns:
- the prepared statement
- Throws:
SQLException- if this connection is closed or an error occurs in the wrapped connection.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException If pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Throws:
SQLException- if this connection is closed or an error occurs in the wrapped connection.
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classDelegatingConnection<Connection>- Throws:
SQLException
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()If false, getDelegate() and getInnermostDelegate() will return null.- Returns:
- true if access is allowed to the underlying connection
- See Also:
-
getDelegate
Get the delegated connection, if allowed.- Overrides:
getDelegatein classDelegatingConnection<Connection>- Returns:
- the internal connection, or null if access is not allowed.
- See Also:
-
getInnermostDelegate
Get the innermost connection, if allowed.- Overrides:
getInnermostDelegatein classDelegatingConnection<Connection>- Returns:
- the innermost internal connection, or null if access is not allowed.
- See Also:
-