Class ConnectionImpl
- java.lang.Object
-
- org.apache.commons.dbcp.AbandonedTrace
-
- org.apache.commons.dbcp.DelegatingConnection
-
- org.apache.commons.dbcp.cpdsadapter.ConnectionImpl
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Connection
,java.sql.Wrapper
class ConnectionImpl extends DelegatingConnection
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.- Version:
- $Revision: 896266 $ $Date: 2010-01-05 18:20:12 -0500 (Tue, 05 Jan 2010) $
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
accessToUnderlyingConnectionAllowed
private PooledConnectionImpl
pooledConnection
The object that instantiated this object-
Fields inherited from class org.apache.commons.dbcp.DelegatingConnection
_closed, _conn
-
-
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.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.apache.commons.dbcp.DelegatingConnection
abort, activate, checkOpen, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, equals, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getDelegateInternal, getHoldability, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, hashCode, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, passivate, prepareCall, prepareCall, prepareCall, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrap
-
Methods inherited from class org.apache.commons.dbcp.AbandonedTrace
addTrace, clearTrace, getConfig, getLastUsed, getTrace, printStackTrace, removeTrace, setLastUsed, setLastUsed, setStackTrace
-
-
-
-
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 connectiion
-
-
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
- Throws:
java.sql.SQLException
- The database connection couldn't be closed.
-
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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- Returns:
- the innermost internal connection, or null if access is not allowed.
- See Also:
isAccessToUnderlyingConnectionAllowed()
-
-