planetj.dataengine.cache
Class PreparedStatementManager

java.lang.Object
  |
  +--planetj.dataengine.cache.PreparedStatementManager

public final class PreparedStatementManager
extends Object

Manages prepared statements for a pool of connections. When a user needs a connection to run a prepared statement, this class tries to give that user a connection which already contains the prepared statement. If no such connections are available, then this class tries to give the user the connection in the pool which has the fewest number of prepared statements.


Constructor Summary
PreparedStatementManager(DataEngineConnectionPool pPool)
          PreparedStatementManager constructor comment.
 
Method Summary
 void addConnection(DataEngineConnection conn)
          Adds a connection to the list of connections whose prepared statements are managed
 Connection getConnection(String sql)
          Gets a Connection.
 void registerPreparedStatement(String sql, DataEngineConnection connection, boolean creation, boolean resort)
          Registers a relationship between a prepared statement and a connection.
 void removeConnection(DataEngineConnection conn)
          Removes a connection from the list of connections whose prepared statements are managed
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStatementManager

public PreparedStatementManager(DataEngineConnectionPool pPool)
PreparedStatementManager constructor comment.

Method Detail

addConnection

public void addConnection(DataEngineConnection conn)
Adds a connection to the list of connections whose prepared statements are managed


getConnection

public Connection getConnection(String sql)
                         throws DataEngineException
Gets a Connection. If there are any free connections which already contain a prepared statement for the SQL string, one of those connections is returned. Otherwise, a connection containing the fewest prepared statements is returned.

Parameters:
sql - An SQL statement for which a prepared statement should be created.
Returns:
A Connection
DataEngineException

registerPreparedStatement

public void registerPreparedStatement(String sql,
                                      DataEngineConnection connection,
                                      boolean creation,
                                      boolean resort)
Registers a relationship between a prepared statement and a connection. The Connection object should invoke this method when its creates/deletes a prepared statement

Parameters:
sql - The sql String from which the statement was prepared
connection - The connection in which the statement was prepared
creation - If this is true, it means the statement was just prepared, and we need to associate it with the connection. If this is false, it means the prepared statement was just removed from the connection, and we should remove the association between the two.
resort - If this is true, the ordered List of Connections will be resorted. In general, this should usually be true, unless this method is being invoked multiple times, in which case the List only needs to be resorted the last time.

removeConnection

public void removeConnection(DataEngineConnection conn)
Removes a connection from the list of connections whose prepared statements are managed