planetj.dataengine.cache
Class PreparedStatementCache

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

public final class PreparedStatementCache
extends Object

Keeps track of the statements that have been prepared by a connection.


Nested Class Summary
static class PreparedStatementCache.OrderedStringMapping
          Contains a SQL String from which a PreparedStatement was prepared, and the last time that PreparedStatement was accessed.
 
Constructor Summary
PreparedStatementCache()
          PreparedStatementCache constructor comment.
 
Method Summary
 PreparedStatement getPreparedStatement(String sql, long time)
          Gets a prepared statement out of the cache.
 List getStatements()
          Gets a List of what statements have been prepared in this Connection.
 String setPreparedStatement(String sql, PreparedStatement statement, long time)
          Sets a prepared statement in the cache.
 int size()
          Returns the number of cached prepared statements.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStatementCache

public PreparedStatementCache()
PreparedStatementCache constructor comment.

Method Detail

getPreparedStatement

public PreparedStatement getPreparedStatement(String sql,
                                              long time)
Gets a prepared statement out of the cache.

Parameters:
sql - The SQL string from which the prepared statement has been (or should be) prepared
time - When the prepared statement was requested
Returns:
The prepared statement if it is in the cache, or null if it isn't

getStatements

public List getStatements()
Gets a List of what statements have been prepared in this Connection. The List contains PreparedStatementCache.OrderedStringMapping objects. The sql field holds the String from which the statement was prepared; the time field holds the time that prepared statement was last accessed.


setPreparedStatement

public String setPreparedStatement(String sql,
                                   PreparedStatement statement,
                                   long time)
                            throws SQLException
Sets a prepared statement in the cache. If the SQL String is mapped to an existing prepared statement, then this method does nothing.

Parameters:
sql - The SQL string from which the prepared statement has been (or should be) prepared
statement - The prepared statement
time - When the prepared statement was requested
Returns:
If adding the prepared statement caused a different prepared statement to be removed from the cache (because there wasn't enough room) the SQL String for the removed statement is returned. Otherwise null is returned.
SQLException

size

public int size()
Returns the number of cached prepared statements.