class PooledConnectionImpl
extends java.lang.Object
implements javax.sql.PooledConnection, org.apache.commons.pool.KeyedPoolableObjectFactory
Modifier and Type | Class and Description |
---|---|
(package private) static class |
PooledConnectionImpl.PStmtKey
A key uniquely identifying {*link PreparedStatement}s.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
accessToUnderlyingConnectionAllowed
Controls access to the underlying connection
|
private 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 PoolablePreparedStatementStub
|
private 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 and Description |
---|
PooledConnectionImpl(java.sql.Connection connection,
org.apache.commons.pool.KeyedObjectPool pool)
Wrap the real connection.
|
Modifier and Type | Method and 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 true
|
void |
close()
Closes the physical connection and marks this
PooledConnection so that it may not be used
to generate any more logical Connection 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 a
PreparedStatement from my pool. |
(package private) java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
Create or obtain a
PreparedStatement 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 a
PreparedStatement 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.
|
private static final java.lang.String CLOSED
private java.sql.Connection connection
private final DelegatingConnection delegatingConnection
private java.sql.Connection logicalConnection
private final java.util.Vector eventListeners
private final java.util.Vector statementEventListeners
boolean isClosed
protected org.apache.commons.pool.KeyedObjectPool pstmtPool
private boolean accessToUnderlyingConnectionAllowed
PooledConnectionImpl(java.sql.Connection connection, org.apache.commons.pool.KeyedObjectPool pool)
connection
- the connection to be wrappedpool
- the pool to usepublic void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
addConnectionEventListener
in interface javax.sql.PooledConnection
public void addStatementEventListener(javax.sql.StatementEventListener listener)
addStatementEventListener
in interface javax.sql.PooledConnection
public void close() throws java.sql.SQLException
PooledConnection
so that it may not be used
to generate any more logical Connection
s.close
in interface javax.sql.PooledConnection
java.sql.SQLException
- if an error occurs or the connection is already closedprivate void assertOpen() throws java.sql.SQLException
java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.PooledConnection
java.sql.SQLException
- if the connection is not open or the previous logical connection is still openpublic void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
removeConnectionEventListener
in interface javax.sql.PooledConnection
public void removeStatementEventListener(javax.sql.StatementEventListener listener)
removeStatementEventListener
in interface javax.sql.PooledConnection
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
void notifyListeners()
java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
PreparedStatement
from my pool.sql
- the SQL statementPoolablePreparedStatement
java.sql.SQLException
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
PreparedStatement
from my pool.sql
- a String
object that is the SQL statement to
be sent to the database; may contain one or more '?' IN
parametersresultSetType
- a result set type; one of
ResultSet.TYPE_FORWARD_ONLY
,
ResultSet.TYPE_SCROLL_INSENSITIVE
, or
ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency
- a concurrency type; one of
ResultSet.CONCUR_READ_ONLY
or
ResultSet.CONCUR_UPDATABLE
PoolablePreparedStatement
java.sql.SQLException
Connection.prepareStatement(String, int, int)
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
PreparedStatement
from my pool.sql
- an SQL statement that may contain one or more '?' IN
parameter placeholdersautoGeneratedKeys
- a flag indicating whether auto-generated keys
should be returned; one of
Statement.RETURN_GENERATED_KEYS
or
Statement.NO_GENERATED_KEYS
PoolablePreparedStatement
java.sql.SQLException
Connection.prepareStatement(String, int)
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
java.sql.SQLException
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
java.sql.SQLException
java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.Object createKey(java.lang.String sql, int autoGeneratedKeys)
protected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
protected java.lang.Object createKey(java.lang.String sql, int[] columnIndexes)
protected java.lang.Object createKey(java.lang.String sql, java.lang.String[] columnNames)
protected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency)
protected java.lang.Object createKey(java.lang.String sql)
protected java.lang.String normalizeSQL(java.lang.String sql)
public java.lang.Object makeObject(java.lang.Object obj) throws java.lang.Exception
makeObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
obj
- the key for the {*link PreparedStatement} to be createdjava.lang.Exception
public void destroyObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
destroyObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- the {*link PreparedStatement} to be destroyed.java.lang.Exception
public boolean validateObject(java.lang.Object key, java.lang.Object obj)
validateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- ignoredpublic void activateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
activateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- ignoredjava.lang.Exception
public void passivateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
passivateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- a {*link PreparedStatement}java.lang.Exception
public boolean isAccessToUnderlyingConnectionAllowed()
public void setAccessToUnderlyingConnectionAllowed(boolean allow)
allow
- Access to the underlying connection is granted when true.