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 theConnectionthat 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 booleanaccessToUnderlyingConnectionAllowedprivate PooledConnectionImplpooledConnectionThe 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 voidclose()Marks the Connection as closed, and notifies the pool that the pooled connection is available.java.sql.ConnectiongetDelegate()Get the delegated connection, if allowed.java.sql.ConnectiongetInnermostDelegate()Get the innermost connection, if allowed.booleanisAccessToUnderlyingConnectionAllowed()If false, getDelegate() and getInnermostDelegate() will return null.java.sql.CallableStatementprepareCall(java.lang.String sql)If pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.java.sql.CallableStatementprepareCall(java.lang.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.java.sql.CallableStatementprepareCall(java.lang.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.java.sql.PreparedStatementprepareStatement(java.lang.String sql)If pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)java.sql.PreparedStatementprepareStatement(java.lang.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.java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)java.sql.PreparedStatementprepareStatement(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.SQLExceptionMarks 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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Connection- Overrides:
closein 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.SQLExceptionIf pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfacejava.sql.Connection- Overrides:
prepareCallin 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
CallableStatementobject 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.SQLExceptionIf pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfacejava.sql.Connection- Overrides:
prepareCallin classDelegatingConnection<java.sql.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:
java.sql.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 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLExceptionIf pooling ofCallableStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareCallin interfacejava.sql.Connection- Overrides:
prepareCallin classDelegatingConnection<java.sql.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:
java.sql.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
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLExceptionIf pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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.SQLExceptionIf pooling ofPreparedStatements is turned on in theDriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.xConnection.- Specified by:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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:
prepareStatementin interfacejava.sql.Connection- Overrides:
prepareStatementin 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:
getDelegatein 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:
getInnermostDelegatein classDelegatingConnection<java.sql.Connection>- Returns:
- the innermost internal connection, or null if access is not allowed.
- See Also:
isAccessToUnderlyingConnectionAllowed()
-
-