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:
Connection, Wrapper, KeyedPoolableObjectFactory

public class PoolingConnection
extends DelegatingConnection
implements Connection, KeyedPoolableObjectFactory

A DelegatingConnection that pools PreparedStatements.

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

Version:
$Revision: 498524 $ $Date: 2007-01-21 21:44:45 -0700 (Sun, 21 Jan 2007) $
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(Connection c)
          Constructor.
PoolingConnection(Connection c, KeyedObjectPool pool)
          Constructor.
 
Method Summary
 void activateObject(Object key, Object obj)
          My KeyedPoolableObjectFactory method for activating PreparedStatements.
 void close()
          Close and free all PreparedStatements from my pool, and close my underlying connection.
 void destroyObject(Object key, Object obj)
          My KeyedPoolableObjectFactory method for destroying PreparedStatements.
 Object makeObject(Object obj)
          My KeyedPoolableObjectFactory method for creating PreparedStatements.
 void passivateObject(Object key, Object obj)
          My KeyedPoolableObjectFactory method for passivating PreparedStatements.
 PreparedStatement prepareStatement(String sql)
          Create or obtain a PreparedStatement from my pool.
 PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
          Create or obtain a PreparedStatement from my pool.
 String toString()
          Returns a string representation of the metadata associated with the innnermost delegate connection.
 boolean validateObject(Object key, Object obj)
          My KeyedPoolableObjectFactory method for validating PreparedStatements.
 
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, prepareCall, 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, prepareCall, 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(Connection c)
Constructor.

Parameters:
c - the underlying Connection.

PoolingConnection

public PoolingConnection(Connection c,
                         KeyedObjectPool pool)
Constructor.

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

activateObject

public void activateObject(Object key,
                           Object obj)
                    throws Exception
My KeyedPoolableObjectFactory method for activating PreparedStatements. (Currently a no-op.)

Specified by:
activateObject in interface KeyedPoolableObjectFactory
Parameters:
key - ignored
obj - ignored
Throws:
Exception

close

public void close()
           throws SQLException
Close and free all PreparedStatements from my pool, and close my underlying connection.

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

destroyObject

public void destroyObject(Object key,
                          Object obj)
                   throws Exception
My KeyedPoolableObjectFactory method for destroying PreparedStatements.

Specified by:
destroyObject in interface KeyedPoolableObjectFactory
Parameters:
key - ignored
obj - the PreparedStatement to be destroyed.
Throws:
Exception

makeObject

public Object makeObject(Object obj)
                  throws Exception
My KeyedPoolableObjectFactory method for creating PreparedStatements.

Specified by:
makeObject in interface KeyedPoolableObjectFactory
Parameters:
obj - the key for the PreparedStatement to be created
Throws:
Exception

passivateObject

public void passivateObject(Object key,
                            Object obj)
                     throws Exception
My KeyedPoolableObjectFactory method for passivating PreparedStatements. Currently invokes PreparedStatement.clearParameters().

Specified by:
passivateObject in interface KeyedPoolableObjectFactory
Parameters:
key - ignored
obj - a PreparedStatement
Throws:
Exception

prepareStatement

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

Specified by:
prepareStatement in interface Connection
Overrides:
prepareStatement in class DelegatingConnection
Returns:
a PoolablePreparedStatement
Throws:
SQLException

prepareStatement

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

Specified by:
prepareStatement in interface Connection
Overrides:
prepareStatement in class DelegatingConnection
Returns:
a PoolablePreparedStatement
Throws:
SQLException

toString

public 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(Object key,
                              Object obj)
My KeyedPoolableObjectFactory method for validating PreparedStatements.

Specified by:
validateObject in interface KeyedPoolableObjectFactory
Parameters:
key - ignored
obj - ignored
Returns:
true


Copyright © 2001-2004 Apache Software Foundation. Documenation generated January 29 2009.