Package org.apache.derby.client.am
Class StatementCacheInteractor
- java.lang.Object
-
- org.apache.derby.client.am.StatementCacheInteractor
-
public final class StatementCacheInteractor extends java.lang.Object
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
Fields Modifier and Type Field Description private JDBCStatementCache
cache
Statement cache for the associated physical connection.private boolean
connCloseInProgress
Tells if this interactor is in the process of shutting down.private java.util.ArrayList<LogicalStatementEntity>
openLogicalStatements
List of open logical statements created by this cache interactor.private ClientConnection
physicalConnection
The underlying physical connection.
-
Constructor Summary
Constructors Constructor Description StatementCacheInteractor(JDBCStatementCache cache, ClientConnection physicalConnection)
Creates a new JDBC statement cache interactor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
closeOpenLogicalStatements()
Closes all open logical statements created by this cache interactor.private java.sql.CallableStatement
createLogicalCallableStatement(java.sql.CallableStatement cs, StatementKey stmtKey)
Creates a logical callable statement.private java.sql.PreparedStatement
createLogicalPreparedStatement(java.sql.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) java.sql.CallableStatement
prepareCall(java.lang.String sql)
(package private) java.sql.CallableStatement
prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
(package private) java.sql.CallableStatement
prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int autoGeneratedKeys)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
(package private) java.sql.PreparedStatement
prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
-
-
-
Field Detail
-
cache
private final JDBCStatementCache cache
Statement cache for the associated physical connection.
-
physicalConnection
private final ClientConnection 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
private final java.util.ArrayList<LogicalStatementEntity> openLogicalStatements
List of open logical statements created by this cache interactor.
-
connCloseInProgress
private boolean connCloseInProgress
Tells if this interactor is in the process of shutting down.If this is true, it means that the logical connection is being closed.
-
-
Constructor Detail
-
StatementCacheInteractor
StatementCacheInteractor(JDBCStatementCache cache, ClientConnection physicalConnection)
Creates a new JDBC statement cache interactor.- Parameters:
cache
- statement cachephysicalConnection
- associated physical connection
-
-
Method Detail
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String)
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String,int,int)
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String,int,int,int)
-
prepareStatement
java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareStatement(String,int)
-
prepareCall
java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareCall(String)
-
prepareCall
java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareCall(String,int,int)
-
prepareCall
java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
- Throws:
java.sql.SQLException
- See Also:
Connection.prepareCall(String,int,int,int)
-
closeOpenLogicalStatements
void closeOpenLogicalStatements() throws java.sql.SQLException
Closes all open logical statements created by this cache interactor.A cache interactor is bound to a single (caching) logical connection.
- Throws:
java.sql.SQLException
- if closing an open logical connection fails
-
markClosed
void markClosed(LogicalStatementEntity logicalStmt)
Designates the specified logical statement as closed.- Parameters:
logicalStmt
- the logical statement being closed
-
createLogicalPreparedStatement
private java.sql.PreparedStatement createLogicalPreparedStatement(java.sql.PreparedStatement ps, StatementKey stmtKey) throws java.sql.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:
java.sql.SQLException
- if creating a logical prepared statement fails
-
createLogicalCallableStatement
private java.sql.CallableStatement createLogicalCallableStatement(java.sql.CallableStatement cs, StatementKey stmtKey) throws java.sql.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:
java.sql.SQLException
- if creating a logical callable statement fails
-
getCache
JDBCStatementCache getCache()
Returns the associated statement cache.- Returns:
- A statement cache.
-
-