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 boolean
private final PooledConnectionImpl
The object that instantiated this objectFields inherited from interface java.sql.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 TypeMethodDescriptionvoid
close()
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.boolean
If false, getDelegate() and getInnermostDelegate() will return null.prepareCall
(String sql) If pooling ofCallableStatement
s 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 ofCallableStatement
s 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 ofCallableStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.prepareStatement
(String sql) If pooling ofPreparedStatement
s 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 ofPreparedStatement
s 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 org.datanucleus.store.rdbms.datasource.dbcp2.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, unwrap
Methods inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
addTrace, clearTrace, getLastUsed, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsed
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Overrides:
close
in classDelegatingConnection<Connection>
- Throws:
SQLException
- The database connection couldn't be closed.
-
prepareCall
If pooling ofCallableStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.- Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in 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
CallableStatement
object 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 ofCallableStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.- Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in classDelegatingConnection<Connection>
- Parameters:
sql
- aString
object 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_ONLY
orResultSet.CONCUR_UPDATABLE
.- Returns:
- a
CallableStatement
object containing the pre-compiled SQL statement that will produceResultSet
objects 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 notResultSet
constants indicating type and concurrency.- Since:
- 2.4.0
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException If pooling ofCallableStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.- Specified by:
prepareCall
in interfaceConnection
- Overrides:
prepareCall
in classDelegatingConnection<Connection>
- Parameters:
sql
- aString
object that is the SQL statement to be sent to the database; may contain on or more '?' parameters.resultSetType
- one of the followingResultSet
constants:ResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
, orResultSet.TYPE_SCROLL_SENSITIVE
.resultSetConcurrency
- one of the followingResultSet
constants:ResultSet.CONCUR_READ_ONLY
orResultSet.CONCUR_UPDATABLE
.resultSetHoldability
- one of the followingResultSet
constants:ResultSet.HOLD_CURSORS_OVER_COMMIT
orResultSet.CLOSE_CURSORS_AT_COMMIT
.- Returns:
- a new
CallableStatement
object, containing the pre-compiled SQL statement, that will generateResultSet
objects 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 notResultSet
constants indicating type, concurrency, and holdability.- Since:
- 2.4.0
-
prepareStatement
If pooling ofPreparedStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in 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 ofPreparedStatement
s is turned on in theDriverAdapterCPDS
, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection
.- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in 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:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Overrides:
prepareStatement
in 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:
getDelegate
in classDelegatingConnection<Connection>
- Returns:
- the internal connection, or null if access is not allowed.
- See Also:
-
getInnermostDelegate
Get the innermost connection, if allowed.- Overrides:
getInnermostDelegate
in classDelegatingConnection<Connection>
- Returns:
- the innermost internal connection, or null if access is not allowed.
- See Also:
-