Class ConnectionImpl
- java.lang.Object
-
- org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
-
- org.datanucleus.store.rdbms.datasource.dbcp2.DelegatingConnection<java.sql.Connection>
-
- org.datanucleus.store.rdbms.datasource.dbcp2.cpdsadapter.ConnectionImpl
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Connection
,java.sql.Wrapper
,TrackedUse
class ConnectionImpl extends DelegatingConnection<java.sql.Connection>
This class is theConnection
that will be returned fromPooledConnectionImpl.getConnection()
. Most methods are wrappers around the JDBC 1.xConnection
. 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
Fields Modifier and Type Field Description private boolean
accessToUnderlyingConnectionAllowed
private PooledConnectionImpl
pooledConnection
The object that instantiated this object
-
Constructor Summary
Constructors Constructor Description ConnectionImpl(PooledConnectionImpl pooledConnection, java.sql.Connection connection, boolean accessToUnderlyingConnectionAllowed)
Creates aConnectionImpl
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Marks the Connection as closed, and notifies the pool that the pooled connection is available.java.sql.Connection
getDelegate()
Get the delegated connection, if allowed.java.sql.Connection
getInnermostDelegate()
Get the innermost connection, if allowed.boolean
isAccessToUnderlyingConnectionAllowed()
If false, getDelegate() and getInnermostDelegate() will return null.java.sql.CallableStatement
prepareCall(java.lang.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
.java.sql.CallableStatement
prepareCall(java.lang.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
.java.sql.CallableStatement
prepareCall(java.lang.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
.java.sql.PreparedStatement
prepareStatement(java.lang.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
.java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int autoGeneratedKeys)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int[] columnIndexes)
java.sql.PreparedStatement
prepareStatement(java.lang.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
.java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
java.sql.PreparedStatement
prepareStatement(java.lang.String sql, java.lang.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
-
-
-
-
Field Detail
-
accessToUnderlyingConnectionAllowed
private final boolean accessToUnderlyingConnectionAllowed
-
pooledConnection
private final PooledConnectionImpl pooledConnection
The object that instantiated this object
-
-
Constructor Detail
-
ConnectionImpl
ConnectionImpl(PooledConnectionImpl pooledConnection, java.sql.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 Detail
-
close
public void close() throws java.sql.SQLException
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Connection
- Overrides:
close
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.SQLException
- The database connection couldn't be closed.
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.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 interfacejava.sql.Connection
- Overrides:
prepareCall
in classDelegatingConnection<java.sql.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:
java.sql.SQLException
- Thrown if a database access error occurs or this method is called on a closed connection.- Since:
- 2.4.0
-
prepareCall
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.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 interfacejava.sql.Connection
- Overrides:
prepareCall
in classDelegatingConnection<java.sql.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:
java.sql.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 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.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 interfacejava.sql.Connection
- Overrides:
prepareCall
in classDelegatingConnection<java.sql.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:
java.sql.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
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.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 interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Parameters:
sql
- SQL statement to be prepared- Returns:
- the prepared statement
- Throws:
java.sql.SQLException
- if this connection is closed or an error occurs in the wrapped connection.
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.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 interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.SQLException
- if this connection is closed or an error occurs in the wrapped connection.
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.SQLException
-
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Specified by:
prepareStatement
in interfacejava.sql.Connection
- Overrides:
prepareStatement
in classDelegatingConnection<java.sql.Connection>
- Throws:
java.sql.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:
ConnectionImpl
-
getDelegate
public java.sql.Connection getDelegate()
Get the delegated connection, if allowed.- Overrides:
getDelegate
in classDelegatingConnection<java.sql.Connection>
- Returns:
- the internal connection, or null if access is not allowed.
- See Also:
isAccessToUnderlyingConnectionAllowed()
-
getInnermostDelegate
public java.sql.Connection getInnermostDelegate()
Get the innermost connection, if allowed.- Overrides:
getInnermostDelegate
in classDelegatingConnection<java.sql.Connection>
- Returns:
- the innermost internal connection, or null if access is not allowed.
- See Also:
isAccessToUnderlyingConnectionAllowed()
-
-