org.apache.commons.dbcp

Class PoolingConnection

Implemented Interfaces:
Connection, KeyedPoolableObjectFactory

public class PoolingConnection
extends DelegatingConnection
implements Connection, KeyedPoolableObjectFactory

A DelegatingConnection that pools PreparedStatements.

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

Version:
$Revision: 1.14 $ $Date: 2004/03/07 15:26:38 $

Authors:
Rodney Waldhoff
Dirk Verbeeck

See Also:
PoolablePreparedStatement

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

Methods inherited from class org.apache.commons.dbcp.DelegatingConnection

clearWarnings, close, commit, createStatement, createStatement, createStatement, equals, getAutoCommit, getCatalog, getDelegate, getHoldability, getInnermostDelegate, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, hashCode, isClosed, isReadOnly, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setDelegate, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap

Methods inherited from class org.apache.commons.dbcp.AbandonedTrace

printStackTrace

Constructor Details

PoolingConnection

public PoolingConnection(Connection c)
Constructor.

Parameters:
c - the underlying Connection.


PoolingConnection

public PoolingConnection(Connection c,
                         KeyedObjectPool pool)
Constructor.

Parameters:
c - the underlying Connection.

Method Details

activateObject

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

Parameters:
key - ignored
obj - ignored


close

public void close()
            throws SQLException
Close and free all PreparedStatements from my pool, and close my underlying connection.
Overrides:
close in interface DelegatingConnection


destroyObject

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

Parameters:
key - ignored
obj - the PreparedStatement to be destroyed.


makeObject

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

Parameters:
obj - the key for the PreparedStatement to be created


passivateObject

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

Parameters:
key - ignored
obj - a PreparedStatement


prepareStatement

public PreparedStatement prepareStatement(String sql)
            throws SQLException
Create or obtain a PreparedStatement from my pool.
Overrides:
prepareStatement in interface DelegatingConnection

Returns:
a PoolablePreparedStatement


prepareStatement

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

Returns:
a PoolablePreparedStatement


toString

public String toString()


validateObject

public boolean validateObject(Object key,
                              Object obj)
My KeyedPoolableObjectFactory method for validating PreparedStatements.

Parameters:
key - ignored
obj - ignored

Returns:
true


Copyright © 2001-2003 Apache Software Foundation. Documenation generated May 22 2005.