Class PooledConnectionImpl
- java.lang.Object
-
- org.apache.commons.dbcp.cpdsadapter.PooledConnectionImpl
-
- All Implemented Interfaces:
javax.sql.PooledConnection
,org.apache.commons.pool.KeyedPoolableObjectFactory
class PooledConnectionImpl extends java.lang.Object implements javax.sql.PooledConnection, org.apache.commons.pool.KeyedPoolableObjectFactory
Implementation of PooledConnection that is returned by PooledConnectionDataSource.- Version:
- $Revision: 899987 $ $Date: 2010-01-16 11:51:16 -0500 (Sat, 16 Jan 2010) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PooledConnectionImpl.PStmtKey
A key uniquely identifying {*link PreparedStatement}s.
-
Field Summary
Fields Modifier and Type Field Description private boolean
accessToUnderlyingConnectionAllowed
Controls access to the underlying connectionprivate static java.lang.String
CLOSED
private java.sql.Connection
connection
The JDBC database connection that represents the physical db connection.private DelegatingConnection
delegatingConnection
A DelegatingConnection used to create a PoolablePreparedStatementStubprivate java.util.Vector
eventListeners
ConnectionEventListeners(package private) boolean
isClosed
flag set to true, once close() is called.private java.sql.Connection
logicalConnection
The JDBC database logical connection.protected org.apache.commons.pool.KeyedObjectPool
pstmtPool
My pool of {*link PreparedStatement}s.private java.util.Vector
statementEventListeners
StatementEventListeners
-
Constructor Summary
Constructors Constructor Description PooledConnectionImpl(java.sql.Connection connection, org.apache.commons.pool.KeyedObjectPool pool)
Wrap the real connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateObject(java.lang.Object key, java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for activating {*link PreparedStatement}s.void
addConnectionEventListener(javax.sql.ConnectionEventListener listener)
void
addStatementEventListener(javax.sql.StatementEventListener listener)
private void
assertOpen()
Throws an SQLException, if isClosed is truevoid
close()
Closes the physical connection and marks thisPooledConnection
so that it may not be used to generate any more logicalConnection
s.protected java.lang.Object
createKey(java.lang.String sql)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.protected java.lang.Object
createKey(java.lang.String sql, int autoGeneratedKeys)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.protected java.lang.Object
createKey(java.lang.String sql, int[] columnIndexes)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.protected java.lang.Object
createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.protected java.lang.Object
createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.protected java.lang.Object
createKey(java.lang.String sql, java.lang.String[] columnNames)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.void
destroyObject(java.lang.Object key, java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for destroying {*link PreparedStatement}s.protected void
finalize()
Closes the physical connection and checks that the logical connection was closed as well.java.sql.Connection
getConnection()
Returns a JDBC connection.boolean
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.java.lang.Object
makeObject(java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for creating {*link PreparedStatement}s.protected java.lang.String
normalizeSQL(java.lang.String sql)
Normalize the given SQL statement, producing a cannonical form that is semantically equivalent to the original.(package private) void
notifyListeners()
sends a connectionClosed event.void
passivateObject(java.lang.Object key, java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for passivating {*link PreparedStatement}s.(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql)
Create or obtain aPreparedStatement
from my pool.(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int autoGeneratedKeys)
Create or obtain aPreparedStatement
from my pool.(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int[] columnIndexes)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
Create or obtain aPreparedStatement
from my pool.(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
void
removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
void
removeStatementEventListener(javax.sql.StatementEventListener listener)
void
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.boolean
validateObject(java.lang.Object key, java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for validating {*link PreparedStatement}s.
-
-
-
Field Detail
-
CLOSED
private static final java.lang.String CLOSED
- See Also:
- Constant Field Values
-
connection
private java.sql.Connection connection
The JDBC database connection that represents the physical db connection.
-
delegatingConnection
private final DelegatingConnection delegatingConnection
A DelegatingConnection used to create a PoolablePreparedStatementStub
-
logicalConnection
private java.sql.Connection logicalConnection
The JDBC database logical connection.
-
eventListeners
private final java.util.Vector eventListeners
ConnectionEventListeners
-
statementEventListeners
private final java.util.Vector statementEventListeners
StatementEventListeners
-
isClosed
boolean isClosed
flag set to true, once close() is called.
-
pstmtPool
protected org.apache.commons.pool.KeyedObjectPool pstmtPool
My pool of {*link PreparedStatement}s.
-
accessToUnderlyingConnectionAllowed
private boolean accessToUnderlyingConnectionAllowed
Controls access to the underlying connection
-
-
Method Detail
-
addConnectionEventListener
public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
- Specified by:
addConnectionEventListener
in interfacejavax.sql.PooledConnection
-
addStatementEventListener
public void addStatementEventListener(javax.sql.StatementEventListener listener)
- Specified by:
addStatementEventListener
in interfacejavax.sql.PooledConnection
-
close
public void close() throws java.sql.SQLException
Closes the physical connection and marks thisPooledConnection
so that it may not be used to generate any more logicalConnection
s.- Specified by:
close
in interfacejavax.sql.PooledConnection
- Throws:
java.sql.SQLException
- if an error occurs or the connection is already closed
-
assertOpen
private void assertOpen() throws java.sql.SQLException
Throws an SQLException, if isClosed is true- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Returns a JDBC connection.- Specified by:
getConnection
in interfacejavax.sql.PooledConnection
- Returns:
- The database connection.
- Throws:
java.sql.SQLException
- if the connection is not open or the previous logical connection is still open
-
removeConnectionEventListener
public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
- Specified by:
removeConnectionEventListener
in interfacejavax.sql.PooledConnection
-
removeStatementEventListener
public void removeStatementEventListener(javax.sql.StatementEventListener listener)
- Specified by:
removeStatementEventListener
in interfacejavax.sql.PooledConnection
-
finalize
protected void finalize() throws java.lang.Throwable
Closes the physical connection and checks that the logical connection was closed as well.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
notifyListeners
void notifyListeners()
sends a connectionClosed event.
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
Create or obtain aPreparedStatement
from my pool.- Parameters:
sql
- the SQL statement- Returns:
- a
PoolablePreparedStatement
- Throws:
java.sql.SQLException
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
Create or obtain aPreparedStatement
from my pool.- Parameters:
sql
- aString
object that is the SQL statement to be sent to the database; may contain one or more '?' IN parametersresultSetType
- 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
PoolablePreparedStatement
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String, int, int)
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Create or obtain aPreparedStatement
from my pool.- Parameters:
sql
- an SQL statement that may contain one or more '?' IN parameter placeholdersautoGeneratedKeys
- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYS
orStatement.NO_GENERATED_KEYS
- Returns:
- a
PoolablePreparedStatement
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String, int)
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
createKey
protected java.lang.Object createKey(java.lang.String sql, int autoGeneratedKeys)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
createKey
protected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
createKey
protected java.lang.Object createKey(java.lang.String sql, int[] columnIndexes)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
createKey
protected java.lang.Object createKey(java.lang.String sql, java.lang.String[] columnNames)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
createKey
protected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
createKey
protected java.lang.Object createKey(java.lang.String sql)
Create a {*link PooledConnectionImpl.PStmtKey} for the given arguments.
-
normalizeSQL
protected java.lang.String normalizeSQL(java.lang.String sql)
Normalize the given SQL statement, producing a cannonical form that is semantically equivalent to the original.
-
makeObject
public java.lang.Object makeObject(java.lang.Object obj) throws java.lang.Exception
My {*link KeyedPoolableObjectFactory} method for creating {*link PreparedStatement}s.- Specified by:
makeObject
in interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory
- Parameters:
obj
- the key for the {*link PreparedStatement} to be created- Throws:
java.lang.Exception
-
destroyObject
public void destroyObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
My {*link KeyedPoolableObjectFactory} method for destroying {*link PreparedStatement}s.- Specified by:
destroyObject
in interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory
- Parameters:
key
- ignoredobj
- the {*link PreparedStatement} to be destroyed.- Throws:
java.lang.Exception
-
validateObject
public boolean validateObject(java.lang.Object key, java.lang.Object obj)
My {*link KeyedPoolableObjectFactory} method for validating {*link PreparedStatement}s.- Specified by:
validateObject
in interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory
- Parameters:
key
- ignoredobj
- ignored- Returns:
- true
-
activateObject
public void activateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
My {*link KeyedPoolableObjectFactory} method for activating {*link PreparedStatement}s.- Specified by:
activateObject
in interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory
- Parameters:
key
- ignoredobj
- ignored- Throws:
java.lang.Exception
-
passivateObject
public void passivateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
My {*link KeyedPoolableObjectFactory} method for passivating {*link PreparedStatement}s. Currently invokes {*link PreparedStatement#clearParameters}.- Specified by:
passivateObject
in interfaceorg.apache.commons.pool.KeyedPoolableObjectFactory
- Parameters:
key
- ignoredobj
- a {*link PreparedStatement}- Throws:
java.lang.Exception
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying is allowed, false otherwise.
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false)- Parameters:
allow
- Access to the underlying connection is granted when true.
-
-