org.apache.commons.dbcp
Class PoolingConnection

java.lang.Object
  extended by org.apache.commons.dbcp.AbandonedTrace
      extended by org.apache.commons.dbcp.DelegatingConnection
          extended by org.apache.commons.dbcp.PoolingConnection
All Implemented Interfaces:
java.sql.Connection, java.sql.Wrapper

public class PoolingConnection
extends DelegatingConnection
implements java.sql.Connection

A DelegatingConnection that pools PreparedStatements.

The prepareStatement(java.lang.String) and prepareCall(java.lang.String) methods, rather than creating a new PreparedStatement each time, may actually pull the statement from a pool of unused statements. The Statement.close() method of the returned statement doesn't actually close the statement, but rather returns it to the pool. (See PoolablePreparedStatement, PoolableCallableStatement.)

Version:
$Revision: 885261 $ $Date: 2009-11-29 15:07:02 -0500 (Sun, 29 Nov 2009) $
Author:
Rodney Waldhoff, Dirk Verbeeck
See Also:
PoolablePreparedStatement

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
PoolingConnection(java.sql.Connection c)
          Constructor.
PoolingConnection(java.sql.Connection c, KeyedObjectPool pool)
          Constructor.
 
Method Summary
 void activateObject(java.lang.Object key, java.lang.Object obj)
          KeyedPoolableObjectFactory method for activating pooled statements.
 void close()
          Close and free all PreparedStatements or CallableStatement from the pool, and close the underlying connection.
 void destroyObject(java.lang.Object key, java.lang.Object obj)
          KeyedPoolableObjectFactory method for destroying PoolablePreparedStatements and PoolableCallableStatements.
 java.lang.Object makeObject(java.lang.Object obj)
          KeyedPoolableObjectFactory method for creating PoolablePreparedStatements or PoolableCallableStatements.
 void passivateObject(java.lang.Object key, java.lang.Object obj)
          KeyedPoolableObjectFactory method for passivating PreparedStatements or CallableStatements.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          Create or obtain a CallableStatement from the pool.
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Create or obtain a CallableStatement from the pool.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Create or obtain a PreparedStatement from the pool.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Create or obtain a PreparedStatement from the pool.
 java.lang.String toString()
          Returns a string representation of the metadata associated with the innnermost delegate connection.
 boolean validateObject(java.lang.Object key, java.lang.Object obj)
          KeyedPoolableObjectFactory method for validating pooled statements.
 
Methods inherited from class org.apache.commons.dbcp.DelegatingConnection
clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, equals, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getDelegate, getHoldability, getInnermostDelegate, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, hashCode, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setDelegate, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap, unwrap
 
Methods inherited from class org.apache.commons.dbcp.AbandonedTrace
printStackTrace
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.sql.Connection
clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Constructor Detail

PoolingConnection

public PoolingConnection(java.sql.Connection c)
Constructor.

Parameters:
c - the underlying Connection.

PoolingConnection

public PoolingConnection(java.sql.Connection c,
                         KeyedObjectPool pool)
Constructor.

Parameters:
c - the underlying Connection.
pool - KeyedObjectPool of PreparedStatements and CallableStatements.
Method Detail

activateObject

public void activateObject(java.lang.Object key,
                           java.lang.Object obj)
                    throws java.lang.Exception
KeyedPoolableObjectFactory method for activating pooled statements.

Parameters:
key - ignored
obj - pooled statement to be activated
Throws:
java.lang.Exception

close

public void close()
           throws java.sql.SQLException
Close and free all PreparedStatements or CallableStatement from the pool, and close the underlying connection.

Specified by:
close in interface java.sql.Connection
Overrides:
close in class DelegatingConnection
Throws:
java.sql.SQLException

destroyObject

public void destroyObject(java.lang.Object key,
                          java.lang.Object obj)
                   throws java.lang.Exception
KeyedPoolableObjectFactory method for destroying PoolablePreparedStatements and PoolableCallableStatements. Closes the underlying statement.

Parameters:
key - ignored
obj - the pooled statement to be destroyed.
Throws:
java.lang.Exception

makeObject

public java.lang.Object makeObject(java.lang.Object obj)
                            throws java.lang.Exception
KeyedPoolableObjectFactory method for creating PoolablePreparedStatements or PoolableCallableStatements. The stmtType field in the key determines whether a PoolablePreparedStatement or PoolableCallableStatement is created.

Parameters:
obj - the key for the PreparedStatement to be created
Throws:
java.lang.Exception
See Also:
createKey(String, int, int, byte)

passivateObject

public void passivateObject(java.lang.Object key,
                            java.lang.Object obj)
                     throws java.lang.Exception
KeyedPoolableObjectFactory method for passivating PreparedStatements or CallableStatements. Invokes PreparedStatement.clearParameters().

Parameters:
key - ignored
obj - a PreparedStatement
Throws:
java.lang.Exception

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Create or obtain a CallableStatement from the pool.

Specified by:
prepareCall in interface java.sql.Connection
Overrides:
prepareCall in class DelegatingConnection
Parameters:
sql - the sql string used to define the CallableStatement
Returns:
a PoolableCallableStatement
Throws:
java.sql.SQLException
Since:
1.3

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
Create or obtain a CallableStatement from the pool.

Specified by:
prepareCall in interface java.sql.Connection
Overrides:
prepareCall in class DelegatingConnection
Parameters:
sql - the sql string used to define the CallableStatement
resultSetType - result set type
resultSetConcurrency - result set concurrency
Returns:
a PoolableCallableStatement
Throws:
java.sql.SQLException
Since:
1.3

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Create or obtain a PreparedStatement from the pool.

Specified by:
prepareStatement in interface java.sql.Connection
Overrides:
prepareStatement in class DelegatingConnection
Parameters:
sql - the sql string used to define the PreparedStatement
Returns:
a PoolablePreparedStatement
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Create or obtain a PreparedStatement from the pool.

Specified by:
prepareStatement in interface java.sql.Connection
Overrides:
prepareStatement in class DelegatingConnection
Parameters:
sql - the sql string used to define the PreparedStatement
resultSetType - result set type
resultSetConcurrency - result set concurrency
Returns:
a PoolablePreparedStatement
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
Description copied from class: DelegatingConnection
Returns a string representation of the metadata associated with the innnermost delegate connection.

Overrides:
toString in class DelegatingConnection

validateObject

public boolean validateObject(java.lang.Object key,
                              java.lang.Object obj)
KeyedPoolableObjectFactory method for validating pooled statements. Currently always returns true.

Parameters:
key - ignored
obj - ignored
Returns:
true


Copyright © 2001-2004 Apache Software Foundation. Documenation generated June 10 2013.