net.esper.eql.db
Class ConnectionCache

java.lang.Object
  extended by net.esper.eql.db.ConnectionCache
Direct Known Subclasses:
ConnectionCacheImpl, ConnectionNoCacheImpl

public abstract class ConnectionCache
extends Object

Base class for a Connection and PreparedStatement cache.

Implementations control the lifecycle via lifecycle methods, or may simple obtain new resources and close new resources every time.

This is not a pool - a cache is associated with one client class and that class is expected to use cache methods in well-defined order of get, done-with and destroy.


Constructor Summary
protected ConnectionCache(DatabaseConnectionFactory databaseConnectionFactory, String sql)
          Ctor.
 
Method Summary
protected static void close(Pair<Connection,PreparedStatement> pair)
          Close resources.
abstract  void destroy()
          Destroys cache closing all resources cached, if any.
abstract  void doneWith(Pair<Connection,PreparedStatement> pair)
          Indicate to return the connection and statement pair after use.
abstract  Pair<Connection,PreparedStatement> getConnection()
          Returns a cached or new connection and statement pair.
protected  Pair<Connection,PreparedStatement> makeNew()
          Make a new pair of resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionCache

protected ConnectionCache(DatabaseConnectionFactory databaseConnectionFactory,
                          String sql)
Ctor.

Parameters:
databaseConnectionFactory - - connection factory
sql - - statement sql
Method Detail

getConnection

public abstract Pair<Connection,PreparedStatement> getConnection()
Returns a cached or new connection and statement pair.

Returns:
connection and statement pair

doneWith

public abstract void doneWith(Pair<Connection,PreparedStatement> pair)
Indicate to return the connection and statement pair after use.

Parameters:
pair - is the resources to return

destroy

public abstract void destroy()
Destroys cache closing all resources cached, if any.


close

protected static void close(Pair<Connection,PreparedStatement> pair)
Close resources.

Parameters:
pair - is the resources to close.

makeNew

protected Pair<Connection,PreparedStatement> makeNew()
Make a new pair of resources.

Returns:
pair of resources