Class JDBCStatementCache
- java.lang.Object
-
- org.apache.derby.client.am.stmtcache.JDBCStatementCache
-
public final class JDBCStatementCache extends java.lang.ObjectA cache for JDBC statement objects.The entries in the cache contains objects implementing the
java.sql.PreparedStatementinterface, and they are inserted with a key object implementing the interfaceStatementKey. The cached objects can be eitherjava.sql.PreparedStatementorjava.sql.CallableStatement. These two should be separated by using different types of keys.The cache only contains free statement objects, and on a successful request for a cached statement the statement is removed from the cache. The cache is not intended to hold duplicate statements. The physical prepared statement should be (re-)inserted into the cache when
closeis called on the logical prepared statement using it.There is a maximum number of cached statements associated with the cache. If this number is exceeded, the oldest entry will be thrown out. One can always throw out an entry, because the fact that it is in the cache means it is free and not in use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classJDBCStatementCache.BoundedLinkedHashMapALinkedHashMapwith an upper bound on the number of entries.
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedHashMap<StatementKey,java.sql.PreparedStatement>statementsStructure holding the cached prepared statement objects.
-
Constructor Summary
Constructors Constructor Description JDBCStatementCache(int maxSize)Creates a new, empty JDBC statement cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancacheStatement(StatementKey statementKey, java.sql.PreparedStatement ps)Cache the prepared statement if it does not already exist.java.sql.PreparedStatementgetCached(StatementKey statementKey)Retrieves a cached prepared statement if one exists.
-
-
-
Field Detail
-
statements
private final java.util.LinkedHashMap<StatementKey,java.sql.PreparedStatement> statements
Structure holding the cached prepared statement objects.
-
-
Method Detail
-
getCached
public java.sql.PreparedStatement getCached(StatementKey statementKey)
Retrieves a cached prepared statement if one exists.- Parameters:
statementKey- key for the prepared statement to look up- Returns:
- A cached statement if one exists,
nullotherwise.
-
cacheStatement
public boolean cacheStatement(StatementKey statementKey, java.sql.PreparedStatement ps)
Cache the prepared statement if it does not already exist.- Parameters:
statementKey- key to insert prepared statement withps- prepared statement to cache- Returns:
trueif added to the cache,falseif not.
-
-