Top Description Fields Constructors Methods
org.apache.derby.client.am

public final Class StatementCacheInteractor

extends Object
Class Inheritance
Imports
java.sql.CallableStatement, .PreparedStatement, .SQLException, java.util.ArrayList, org.apache.derby.client.am.stmtcache.JDBCStatementCache, .StatementKey, .StatementKeyFactory, org.apache.derby.client.ClientAutoloadedDriver, org.apache.derby.shared.common.sanity.SanityManager

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

Modifier and TypeField and Description
private final JDBCStatementCache
cache

Statement cache for the associated physical connection.

private boolean
connCloseInProgress

Tells if this interactor is in the process of shutting down.

private final ArrayList<LogicalStatementEntity>
openLogicalStatements

List of open logical statements created by this cache interactor.

private final ClientConnection
physicalConnection

The underlying physical connection.

Constructor Summary

AccessConstructor and Description
pack-priv
StatementCacheInteractor(JDBCStatementCache
statement cache
cache
,
ClientConnection
associated physical connection
physicalConnection
)

Creates a new JDBC statement cache interactor.

Method Summary

Modifier and TypeMethod and Description
pack-priv synchronized void
closeOpenLogicalStatements()

Closes all open logical statements created by this cache interactor.

private CallableStatement

Returns:

A logical callable statement.
createLogicalCallableStatement
(CallableStatement
the underlying physical callable statement
cs
,
StatementKey
the statement key for the physical statement
stmtKey
)

Creates a logical callable statement.

private PreparedStatement

Returns:

A logical prepared statement.
createLogicalPreparedStatement
(PreparedStatement
the underlying physical prepared statement
ps
,
StatementKey
the statement key for the physical statement
stmtKey
)

Creates a logical prepared statement.

pack-priv JDBCStatementCache

Returns:

A statement cache.
getCache
()

Returns the associated statement cache.

pack-priv synchronized void
markClosed(LogicalStatementEntity
the logical statement being closed
logicalStmt
)

Designates the specified logical statement as closed.

pack-priv synchronized CallableStatement
pack-priv synchronized CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency)

pack-priv synchronized CallableStatement
prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

pack-priv synchronized PreparedStatement
pack-priv synchronized PreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

pack-priv synchronized PreparedStatement
prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

pack-priv synchronized PreparedStatement
prepareStatement(String sql, int autoGeneratedKeys)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private final JDBCStatementCache cache

Statement cache for the associated physical connection.

connCloseInProgressback to summary
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.

openLogicalStatementsback to summary
private final ArrayList<LogicalStatementEntity> openLogicalStatements

List of open logical statements created by this cache interactor.

physicalConnectionback to summary
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.

Constructor Detail

StatementCacheInteractorback to summary
pack-priv StatementCacheInteractor(JDBCStatementCache cache, ClientConnection physicalConnection)

Creates a new JDBC statement cache interactor.

Parameters
cache:JDBCStatementCache

statement cache

physicalConnection:ClientConnection

associated physical connection

Method Detail

closeOpenLogicalStatementsback to summary
pack-priv synchronized void closeOpenLogicalStatements() throws SQLException

Closes all open logical statements created by this cache interactor.

A cache interactor is bound to a single (caching) logical connection.

Exceptions
SQLException:
if closing an open logical connection fails
createLogicalCallableStatementback to summary
private CallableStatement createLogicalCallableStatement(CallableStatement cs, StatementKey stmtKey) throws SQLException

Creates a logical callable statement.

Parameters
cs:CallableStatement

the underlying physical callable statement

stmtKey:StatementKey

the statement key for the physical statement

Returns:CallableStatement

A logical callable statement.

Exceptions
SQLException:
if creating a logical callable statement fails
createLogicalPreparedStatementback to summary
private PreparedStatement createLogicalPreparedStatement(PreparedStatement ps, StatementKey stmtKey) throws SQLException

Creates a logical prepared statement.

Parameters
ps:PreparedStatement

the underlying physical prepared statement

stmtKey:StatementKey

the statement key for the physical statement

Returns:PreparedStatement

A logical prepared statement.

Exceptions
SQLException:
if creating a logical prepared statement fails
getCacheback to summary
pack-priv JDBCStatementCache getCache()

Returns the associated statement cache.

Returns:JDBCStatementCache

A statement cache.

markClosedback to summary
pack-priv synchronized void markClosed(LogicalStatementEntity logicalStmt)

Designates the specified logical statement as closed.

Parameters
logicalStmt:LogicalStatementEntity

the logical statement being closed

prepareCallback to summary
pack-priv synchronized CallableStatement prepareCall(String sql) throws SQLException
See Also
java.sql.Connection#prepareCall(String)
prepareCallback to summary
pack-priv synchronized CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
See Also
java.sql.Connection#prepareCall(String, int, int)
prepareCallback to summary
pack-priv synchronized CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
See Also
java.sql.Connection#prepareCall(String, int, int, int)
prepareStatementback to summary
pack-priv synchronized PreparedStatement prepareStatement(String sql) throws SQLException
See Also
java.sql.Connection#prepareStatement(String)
prepareStatementback to summary
pack-priv synchronized PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
See Also
java.sql.Connection#prepareStatement(String, int, int)
prepareStatementback to summary
pack-priv synchronized PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
See Also
java.sql.Connection#prepareStatement(String, int, int, int)
prepareStatementback to summary
pack-priv synchronized PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
See Also
java.sql.Connection#prepareStatement(String, int)