Package org.apache.derby.client.am
Class StatementCacheInteractor
java.lang.Object
org.apache.derby.client.am.StatementCacheInteractor
Utility class encapsulating the logic for interacting with the JDBC statement
cache when creating new logical statements.
This class was introduced to share code between the pre-JDBC 4 and the JDBC 4+ versions of the JDBC classes.
The pattern for the prepareX
methods is:
- Generate a key for the statement to create.
- Consult cache to see if an existing statement can be used.
- Create new statement on physical connection if necessary.
- Return reference to existing or newly created statement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JDBCStatementCache
Statement cache for the associated physical connection.private boolean
Tells if this interactor is in the process of shutting down.private final ArrayList
<LogicalStatementEntity> List of open logical statements created by this cache interactor.private final ClientConnection
The underlying physical connection. -
Constructor Summary
ConstructorsConstructorDescriptionStatementCacheInteractor
(JDBCStatementCache cache, ClientConnection physicalConnection) Creates a new JDBC statement cache interactor. -
Method Summary
Modifier and TypeMethodDescription(package private) void
Closes all open logical statements created by this cache interactor.private CallableStatement
createLogicalCallableStatement
(CallableStatement cs, StatementKey stmtKey) Creates a logical callable statement.private PreparedStatement
createLogicalPreparedStatement
(PreparedStatement ps, StatementKey stmtKey) Creates a logical prepared statement.(package private) JDBCStatementCache
getCache()
Returns the associated statement cache.(package private) void
markClosed
(LogicalStatementEntity logicalStmt) Designates the specified logical statement as closed.(package private) CallableStatement
prepareCall
(String sql) (package private) CallableStatement
prepareCall
(String sql, int resultSetType, int resultSetConcurrency) (package private) CallableStatement
prepareCall
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) (package private) PreparedStatement
prepareStatement
(String sql) (package private) PreparedStatement
prepareStatement
(String sql, int autoGeneratedKeys) (package private) PreparedStatement
prepareStatement
(String sql, int resultSetType, int resultSetConcurrency) (package private) PreparedStatement
prepareStatement
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
-
Field Details
-
cache
Statement cache for the associated physical connection. -
physicalConnection
The underlying physical connection.Note that it is the responsibility of the logical statement assoiciated with this cache interactor to ensure the interactor methods are not invoked if the logical statement has been closed.
-
openLogicalStatements
List of open logical statements created by this cache interactor. -
connCloseInProgress
private boolean connCloseInProgressTells if this interactor is in the process of shutting down.If this is true, it means that the logical connection is being closed.
-
-
Constructor Details
-
StatementCacheInteractor
StatementCacheInteractor(JDBCStatementCache cache, ClientConnection physicalConnection) Creates a new JDBC statement cache interactor.- Parameters:
cache
- statement cachephysicalConnection
- associated physical connection
-
-
Method Details
-
prepareStatement
- Throws:
SQLException
- See Also:
-
prepareStatement
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Throws:
SQLException
- See Also:
-
prepareStatement
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Throws:
SQLException
- See Also:
-
prepareStatement
- Throws:
SQLException
- See Also:
-
prepareCall
- Throws:
SQLException
- See Also:
-
prepareCall
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Throws:
SQLException
- See Also:
-
prepareCall
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Throws:
SQLException
- See Also:
-
closeOpenLogicalStatements
Closes all open logical statements created by this cache interactor.A cache interactor is bound to a single (caching) logical connection.
- Throws:
SQLException
- if closing an open logical connection fails
-
markClosed
Designates the specified logical statement as closed.- Parameters:
logicalStmt
- the logical statement being closed
-
createLogicalPreparedStatement
private PreparedStatement createLogicalPreparedStatement(PreparedStatement ps, StatementKey stmtKey) throws SQLException Creates a logical prepared statement.- Parameters:
ps
- the underlying physical prepared statementstmtKey
- the statement key for the physical statement- Returns:
- A logical prepared statement.
- Throws:
SQLException
- if creating a logical prepared statement fails
-
createLogicalCallableStatement
private CallableStatement createLogicalCallableStatement(CallableStatement cs, StatementKey stmtKey) throws SQLException Creates a logical callable statement.- Parameters:
cs
- the underlying physical callable statementstmtKey
- the statement key for the physical statement- Returns:
- A logical callable statement.
- Throws:
SQLException
- if creating a logical callable statement fails
-
getCache
JDBCStatementCache getCache()Returns the associated statement cache.- Returns:
- A statement cache.
-