com.jolbox.bonecp
Class StatementCache

java.lang.Object
  extended by com.jolbox.bonecp.StatementCache
All Implemented Interfaces:
IStatementCache

public class StatementCache
extends Object
implements IStatementCache

JDBC statement cache.

Author:
wallacew

Constructor Summary
StatementCache(int size, boolean maintainStats, Statistics statistics)
          Creates a statement cache of given size.
 
Method Summary
 String calculateCacheKey(String sql, int autoGeneratedKeys)
          Alternate version of autoGeneratedKeys.
 String calculateCacheKey(String sql, int[] columnIndexes)
          Calculate a cache key.
 String calculateCacheKey(String sql, int resultSetType, int resultSetConcurrency)
          Cache key calculation.
 String calculateCacheKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Simply appends the given parameters and returns it to obtain a cache key
 String calculateCacheKey(String sql, String[] columnNames)
          Calculate a cache key.
 void checkForProperClosure()
          Checks that the entries in the cache have been properly closed when the connection dies down.
 void clear()
          Clears the cache
 StatementHandle get(String key)
          Retrieves the cached statement identified by the given key
 StatementHandle get(String sql, int autoGeneratedKeys)
          Retrieves the cached statement identified by the given key
 StatementHandle get(String sql, int[] columnIndexes)
          Retrieves the cached statement identified by the given key
 StatementHandle get(String sql, int resultSetType, int resultSetConcurrency)
          Retrieves the cached statement identified by the given key
 StatementHandle get(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Retrieves the cached statement identified by the given key
 StatementHandle get(String sql, String[] columnNames)
          Retrieves the cached statement identified by the given key
 void putIfAbsent(String key, StatementHandle handle)
          Wrapper for map putIfAbsent.
 int size()
          Returns size of the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatementCache

public StatementCache(int size,
                      boolean maintainStats,
                      Statistics statistics)
Creates a statement cache of given size.

Parameters:
size - of cache.
maintainStats - if true, keep track of statistics.
statistics - statistics handle.
Method Detail

calculateCacheKey

public String calculateCacheKey(String sql,
                                int resultSetType,
                                int resultSetConcurrency,
                                int resultSetHoldability)
Simply appends the given parameters and returns it to obtain a cache key

Specified by:
calculateCacheKey in interface IStatementCache
Parameters:
sql -
resultSetConcurrency -
resultSetHoldability -
resultSetType -
Returns:
cache key to use

calculateCacheKey

public String calculateCacheKey(String sql,
                                int resultSetType,
                                int resultSetConcurrency)
Cache key calculation.

Specified by:
calculateCacheKey in interface IStatementCache
Parameters:
sql - string
resultSetType -
resultSetConcurrency -
Returns:
cache key

calculateCacheKey

public String calculateCacheKey(String sql,
                                int autoGeneratedKeys)
Alternate version of autoGeneratedKeys.

Specified by:
calculateCacheKey in interface IStatementCache
Parameters:
sql -
autoGeneratedKeys -
Returns:
cache key to use.

calculateCacheKey

public String calculateCacheKey(String sql,
                                int[] columnIndexes)
Calculate a cache key.

Specified by:
calculateCacheKey in interface IStatementCache
Parameters:
sql - to use
columnIndexes - to use
Returns:
cache key to use.

calculateCacheKey

public String calculateCacheKey(String sql,
                                String[] columnNames)
Calculate a cache key.

Specified by:
calculateCacheKey in interface IStatementCache
Parameters:
sql - to use
columnNames - to use
Returns:
cache key to use.

get

public StatementHandle get(String key)
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
key - SQL statement
Returns:
Statement, or null if not found.
See Also:
IStatementCache.get(java.lang.String)

get

public StatementHandle get(String sql,
                           int resultSetType,
                           int resultSetConcurrency,
                           int resultSetHoldability)
Description copied from interface: IStatementCache
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
sql - SQL Statement
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetHoldability - a ResultSet holdability constant; one of ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Returns:
Statement, or null if not found.

get

public StatementHandle get(String sql,
                           int resultSetType,
                           int resultSetConcurrency)
Description copied from interface: IStatementCache
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
sql - SQL Statement
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
Statement, or null if not found.

get

public StatementHandle get(String sql,
                           int autoGeneratedKeys)
Description copied from interface: IStatementCache
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
sql - SQL Statement
autoGeneratedKeys - a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
Returns:
Statement, or null if not found.

get

public StatementHandle get(String sql,
                           int[] columnIndexes)
Description copied from interface: IStatementCache
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
sql - SQL Statement
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row or rows
Returns:
Statement, or null if not found.

get

public StatementHandle get(String sql,
                           String[] columnNames)
Description copied from interface: IStatementCache
Retrieves the cached statement identified by the given key

Specified by:
get in interface IStatementCache
Parameters:
sql - SQL Statement
columnNames - an array of column names indicating the columns that should be returned from the inserted row or rows
Returns:
Statement, or null if not found.

size

public int size()
Returns size of the cache.

Specified by:
size in interface IStatementCache
Returns:
cache size
See Also:
IStatementCache.size()

clear

public void clear()
Clears the cache

Specified by:
clear in interface IStatementCache
See Also:
IStatementCache.clear()

checkForProperClosure

public void checkForProperClosure()
Description copied from interface: IStatementCache
Checks that the entries in the cache have been properly closed when the connection dies down.

Specified by:
checkForProperClosure in interface IStatementCache

putIfAbsent

public void putIfAbsent(String key,
                        StatementHandle handle)
Description copied from interface: IStatementCache
Wrapper for map putIfAbsent.

Specified by:
putIfAbsent in interface IStatementCache


Copyright © 2009-2011 JolBox. All Rights Reserved.