public abstract class ConnectionCache extends Object
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.
Modifier | Constructor and Description |
---|---|
protected |
ConnectionCache(DatabaseConnectionFactory databaseConnectionFactory,
String sql)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected ConnectionCache(DatabaseConnectionFactory databaseConnectionFactory, String sql)
databaseConnectionFactory
- - connection factorysql
- - statement sqlpublic abstract Pair<Connection,PreparedStatement> getConnection()
public abstract void doneWith(Pair<Connection,PreparedStatement> pair)
pair
- is the resources to returnpublic abstract void destroy()
protected static void close(Pair<Connection,PreparedStatement> pair)
pair
- is the resources to close.protected Pair<Connection,PreparedStatement> makeNew()