planetj.dataengine.cache
Class PreparedStatementCache

java.lang.Object
  extended byplanetj.dataengine.cache.PreparedStatementCache

public final class PreparedStatementCache
extends java.lang.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
 java.sql.PreparedStatement getPreparedStatement(java.lang.String sql, long time)
          Gets a prepared statement out of the cache.
 java.util.List getStatements()
          Gets a List of what statements have been prepared in this Connection.
 java.lang.String setPreparedStatement(java.lang.String sql, java.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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStatementCache

public PreparedStatementCache()
PreparedStatementCache constructor comment.

Method Detail

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.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 java.util.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 java.lang.String setPreparedStatement(java.lang.String sql,
                                             java.sql.PreparedStatement statement,
                                             long time)
                                      throws java.sql.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.
Throws:
java.sql.SQLException

size

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