org.apache.derby.client.am
Class StatementCacheInteractor

java.lang.Object
  extended by 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:

  1. Generate a key for the statement to create.
  2. Consult cache to see if an existing statement can be used.
  3. Create new statement on physical connection if necessary.
  4. Return reference to existing or newly created statement.


Field Summary
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 openLogicalStatements
          List of open logical statements created by this cache interactor.
private  Connection physicalConnection
          The underlying physical connection.
 
Constructor Summary
StatementCacheInteractor(JDBCStatementCache cache, Connection physicalConnection)
          Creates a new JDBC statement cache interactor.
 
Method Summary
 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.
 void markClosed(LogicalStatementEntity logicalStmt)
          Designates the specified logical statement as closed.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private final JDBCStatementCache cache
Statement cache for the associated physical connection.


physicalConnection

private final 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

private final java.util.ArrayList 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,
                         Connection physicalConnection)
Creates a new JDBC statement cache interactor.

Parameters:
cache - statement cache
physicalConnection - associated physical connection
Method Detail

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(String)

prepareStatement

public 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

public 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

public 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

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException
See Also:
Connection.prepareCall(String)

prepareCall

public 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

public 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

public 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

public 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 statement
stmtKey - 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 statement
stmtKey - 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.

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.