com.evanmclean.evlib.sql
Class PreparedStatementCache

java.lang.Object
  extended by com.evanmclean.evlib.sql.PreparedStatementCache

public class PreparedStatementCache
extends Object

Keeps a cache prepared statements, based on the SQL. Calling the close() method closes and removes all statements in the cache.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Constructor Summary
PreparedStatementCache(Connection conn)
          Initialise the cache to use the specified database connection.
 
Method Summary
 void close()
          Closes all statements in the cache.
 void close(String sql)
          Close a specific prepared statement, based on it's SQL.
 PreparedStatement get(String sql)
          Get the prepared statement based on the sql string.
 PreparedStatement get(String sql, int resultSetType, int resultSetConcurrency)
          Get the prepared statement based on the sql string.
 Connection getConnection()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedStatementCache

public PreparedStatementCache(Connection conn)
Initialise the cache to use the specified database connection.

Parameters:
conn -
Method Detail

close

public void close()
           throws SQLException
Closes all statements in the cache. If there is an exception for one or more of close calls, it will still try and close the rest of the statements in the cache.

Throws:
SQLException

close

public void close(String sql)
           throws SQLException
Close a specific prepared statement, based on it's SQL.

Parameters:
sql - The SQL of the statement to close.
Throws:
SQLException

get

public PreparedStatement get(String sql)
                      throws SQLException
Get the prepared statement based on the sql string. It is created the first time it is needed.

Parameters:
sql - The SQL for the statement.
Returns:
The prepared statement.
Throws:
SQLException

get

public PreparedStatement get(String sql,
                             int resultSetType,
                             int resultSetConcurrency)
                      throws SQLException
Get the prepared statement based on the sql string. It is created the first time it is needed. Note that the result set parameters only have effect if there is no statement already in the cache with the matching SQL, otherwise it is ignored.

Parameters:
sql - The SQL for the statement.
resultSetType -
resultSetConcurrency -
Returns:
The prepared statement.
Throws:
SQLException

getConnection

public Connection getConnection()
Returns:
The database connection this cache uses.