org.apache.commons.dbcp

Class PoolingConnection

public class PoolingConnection extends DelegatingConnection implements Connection, KeyedPoolableObjectFactory

A {@link DelegatingConnection} that pools {@link PreparedStatement}s.

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

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

Author: Rodney Waldhoff Dirk Verbeeck

See Also: PoolablePreparedStatement

Constructor Summary
PoolingConnection(Connection c)
Constructor.
PoolingConnection(Connection c, KeyedObjectPool pool)
Constructor.
Method Summary
voidactivateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for activating {@link PreparedStatement}s.
voidclose()
Close and free all {@link PreparedStatement}s from my pool, and close my underlying connection.
voiddestroyObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for destroying {@link PreparedStatement}s.
ObjectmakeObject(Object obj)
My {@link KeyedPoolableObjectFactory} method for creating {@link PreparedStatement}s.
voidpassivateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for passivating {@link PreparedStatement}s.
PreparedStatementprepareStatement(String sql)
Create or obtain a {@link PreparedStatement} from my pool.
PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency)
Create or obtain a {@link PreparedStatement} from my pool.
StringtoString()
booleanvalidateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for validating {@link PreparedStatement}s.

Constructor Detail

PoolingConnection

public PoolingConnection(Connection c)
Constructor.

Parameters: c the underlying {@link Connection}.

PoolingConnection

public PoolingConnection(Connection c, KeyedObjectPool pool)
Constructor.

Parameters: c the underlying {@link Connection}. maxSleepingPerKey the maximum number of {@link PreparedStatement}s that may sit idle in my pool (per type)

Method Detail

activateObject

public void activateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for activating {@link PreparedStatement}s. (Currently a no-op.)

Parameters: key ignored obj ignored

close

public void close()
Close and free all {@link PreparedStatement}s from my pool, and close my underlying connection.

destroyObject

public void destroyObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for destroying {@link PreparedStatement}s.

Parameters: key ignored obj the {@link PreparedStatement} to be destroyed.

makeObject

public Object makeObject(Object obj)
My {@link KeyedPoolableObjectFactory} method for creating {@link PreparedStatement}s.

Parameters: obj the key for the {@link PreparedStatement} to be created

passivateObject

public void passivateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for passivating {@link PreparedStatement}s. Currently invokes {@link PreparedStatement#clearParameters}.

Parameters: key ignored obj a {@link PreparedStatement}

prepareStatement

public PreparedStatement prepareStatement(String sql)
Create or obtain a {@link PreparedStatement} from my pool.

Returns: a {@link PoolablePreparedStatement}

prepareStatement

public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
Create or obtain a {@link PreparedStatement} from my pool.

Returns: a {@link PoolablePreparedStatement}

toString

public String toString()

validateObject

public boolean validateObject(Object key, Object obj)
My {@link KeyedPoolableObjectFactory} method for validating {@link PreparedStatement}s.

Parameters: key ignored obj ignored

Returns: true

Copyright © 2001-2003 Apache Software Foundation. Documenation generated September 20 2007.