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

public Class CachingLogicalConnection

extends LogicalConnection
Class Inheritance
Imports
java.sql.CallableStatement, .PreparedStatement, .SQLException, org.apache.derby.client.ClientPooledConnection, org.apache.derby.client.am.stmtcache.JDBCStatementCache, org.apache.derby.shared.common.sanity.SanityManager

A logical connection used in a connection pool with capabilities for caching prepared statements.

An instance of this class is what is passed out the the client. It uses a JDBC statement object cache to avoid re-preparing commonly used queries. The cache has scope of a physical connection, and is lost when the pooled connection is closed (which includes closing the physical connection).

See Also
StatementCacheInteractor

Field Summary

Modifier and TypeField and Description
private StatementCacheInteractor
cacheInteractor

JDBC statement cache interactor used to prepare statements and calls.

Inherited from org.apache.derby.client.am.LogicalConnection:
physicalConnection_

Constructor Summary

AccessConstructor and Description
public
CachingLogicalConnection(ClientConnection
underlying physical database connection
physicalConnection
,
ClientPooledConnection
associated pooled connection
pooledConnection
,
JDBCStatementCache
associated statement cache
stmtCache
)

Creates a new logical connection which caches prepared statements.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Overrides org.apache.derby.client.am.LogicalConnection.close.

Implements java.sql.Connection.close.

Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
public synchronized CallableStatement
prepareCall(String
an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is specified using JDBC call escape syntax.
sql
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Creates a CallableStatement object for calling database stored procedures.
public synchronized CallableStatement
prepareCall(String
a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters
sql
,
int
a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetType
,
int
a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetConcurrency
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
public synchronized CallableStatement
prepareCall(String
a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters
sql
,
int
one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetType
,
int
one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetConcurrency
,
int
one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
resultSetHoldability
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency.
public synchronized PreparedStatement
prepareStatement(String
an SQL statement that may contain one or more '?' IN parameter placeholders
sql
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a PreparedStatement object for sending parameterized SQL statements to the database.
public synchronized PreparedStatement
prepareStatement(String
a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters
sql
,
int
a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetType
,
int
a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetConcurrency
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency.
public synchronized PreparedStatement
prepareStatement(String
a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters
sql
,
int
one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetType
,
int
one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetConcurrency
,
int
one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
resultSetHoldability
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.
public synchronized PreparedStatement
prepareStatement(String
an SQL statement that may contain one or more '?' IN parameter placeholders
sql
,
int
a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys.
public synchronized PreparedStatement
prepareStatement(String
an SQL statement that may contain one or more '?' IN parameter placeholders
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row or rows
columnIndexes
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.
public synchronized PreparedStatement
prepareStatement(String
an SQL statement that may contain one or more '?' IN parameter placeholders
sql
,
String[]
an array of column names indicating the columns that should be returned from the inserted row or rows
columnNames
)

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array.
Inherited from org.apache.derby.client.am.LogicalConnection:
abortcheckForNullPhysicalConnectionclearWarningscloseWithoutRecyclingToPoolcommitcreateArrayOfcreateBlobcreateClobcreateNClobcreateSQLXMLcreateStatementcreateStatementcreateStatementcreateStructfinalizegetAutoCommitgetCataloggetClientInfogetClientInfogetHoldabilitygetMetaDatagetNetworkTimeoutgetRealMetaDataObjectgetSchemagetServerVersiongetTransactionIDgetTransactionIsolationgetTypeMapgetWarningsisClosedisReadOnlyisValidisWrapperFornativeSQLnewLogicalDatabaseMetaDatanotifyExceptionnullPhysicalConnectionreleaseSavepointrollbackrollbacksetAutoCommitsetCatalogsetClientInfosetClientInfosetHoldabilitysetNetworkTimeoutsetReadOnlysetSavepointsetSavepointsetSchemasetTransactionIsolationsetTypeMapunwrap

Field Detail

cacheInteractorback to summary
private StatementCacheInteractor cacheInteractor

JDBC statement cache interactor used to prepare statements and calls.

Constructor Detail

CachingLogicalConnectionback to summary
public CachingLogicalConnection(ClientConnection physicalConnection, ClientPooledConnection pooledConnection, JDBCStatementCache stmtCache) throws SqlException

Creates a new logical connection which caches prepared statements.

Parameters
physicalConnection:ClientConnection

underlying physical database connection

pooledConnection:ClientPooledConnection

associated pooled connection

stmtCache:JDBCStatementCache

associated statement cache

Exceptions
SqlException:
if creating the logical connection fails

Method Detail

closeback to summary
public synchronized void close() throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.close.

Implements java.sql.Connection.close.

Doc from java.sql.Connection.close.

Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.

Calling the method close on a Connection object that is already closed is a no-op.

It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined.

Exceptions
SQLException:
if a database access error occurs
prepareCallback to summary
public synchronized CallableStatement prepareCall(String sql) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Doc from java.sql.Connection.prepareCall.

Creates a CallableStatement object for calling database stored procedures. The CallableStatement object provides methods for setting up its IN and OUT parameters, and methods for executing the call to a stored procedure.

Note

This method is optimized for handling stored procedure call statements. Some drivers may send the call statement to the database when the method prepareCall is done; others may wait until the CallableStatement object is executed. This has no direct effect on users; however, it does affect which method throws certain SQLExceptions.

Result sets created using the returned CallableStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is specified using JDBC call escape syntax.

Returns:CallableStatement

a new default CallableStatement object containing the pre-compiled SQL statement

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed connection
prepareCallback to summary
public synchronized CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Doc from java.sql.Connection.prepareCall.

Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the prepareCall method above, but it allows the default result set type and concurrency to be overridden. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters

resultSetType:int

a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency:int

a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

Returns:CallableStatement

a new CallableStatement object containing the pre-compiled SQL statement that will produce ResultSet objects with the given type and concurrency

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type and concurrency
prepareCallback to summary
public synchronized CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareCall.

Implements java.sql.Connection.prepareCall.

Doc from java.sql.Connection.prepareCall.

Creates a CallableStatement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the prepareCall method above, but it allows the default result set type, result set concurrency type and holdability to be overridden.

Parameters
sql:String

a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters

resultSetType:int

one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency:int

one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

resultSetHoldability:int

one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT

Returns:CallableStatement

a new CallableStatement object, containing the pre-compiled SQL statement, that will generate ResultSet objects with the given type, concurrency, and holdability

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type, concurrency, and holdability
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a PreparedStatement object for sending parameterized SQL statements to the database.

A SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note

This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLException objects.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

an SQL statement that may contain one or more '?' IN parameter placeholders

Returns:PreparedStatement

a new default PreparedStatement object containing the pre-compiled SQL statement

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed connection
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a PreparedStatement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the prepareStatement method above, but it allows the default result set type and concurrency to be overridden. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters

resultSetType:int

a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency:int

a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

Returns:PreparedStatement

a new PreparedStatement object containing the pre-compiled SQL statement that will produce ResultSet objects with the given type and concurrency

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type and concurrency
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a PreparedStatement object that will generate ResultSet objects with the given type, concurrency, and holdability.

This method is the same as the prepareStatement method above, but it allows the default result set type, concurrency, and holdability to be overridden.

Parameters
sql:String

a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN parameters

resultSetType:int

one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE

resultSetConcurrency:int

one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

resultSetHoldability:int

one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT

Returns:PreparedStatement

a new PreparedStatement object, containing the pre-compiled SQL statement, that will generate ResultSet objects with the given type, concurrency, and holdability

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type, concurrency, and holdability
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object that has the capability to retrieve auto-generated keys. The given constant tells the driver whether it should make auto-generated keys available for retrieval. This parameter is ignored if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

Note

This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

an SQL statement that may contain one or more '?' IN parameter placeholders

autoGeneratedKeys:int

a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS

Returns:PreparedStatement

a new PreparedStatement object, containing the pre-compiled SQL statement, that will have the capability of returning auto-generated keys

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed connection or the given parameter is not a Statement constant indicating whether auto-generated keys should be returned
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note

This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

an SQL statement that may contain one or more '?' IN parameter placeholders

columnIndexes:int[]

an array of column indexes indicating the columns that should be returned from the inserted row or rows

Returns:PreparedStatement

a new PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column indexes

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed connection
prepareStatementback to summary
public synchronized PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException

Overrides org.apache.derby.client.am.LogicalConnection.prepareStatement.

Implements java.sql.Connection.prepareStatement.

Doc from java.sql.Connection.prepareStatement.

Creates a default PreparedStatement object capable of returning the auto-generated keys designated by the given array. This array contains the names of the columns in the target table that contain the auto-generated keys that should be returned. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).

An SQL statement with or without IN parameters can be pre-compiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note

This method is optimized for handling parametric SQL statements that benefit from precompilation. If the driver supports precompilation, the method prepareStatement will send the statement to the database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be sent to the database until the PreparedStatement object is executed. This has no direct effect on users; however, it does affect which methods throw certain SQLExceptions.

Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY. The holdability of the created result sets can be determined by calling getHoldability.

Parameters
sql:String

an SQL statement that may contain one or more '?' IN parameter placeholders

columnNames:String[]

an array of column names indicating the columns that should be returned from the inserted row or rows

Returns:PreparedStatement

a new PreparedStatement object, containing the pre-compiled statement, that is capable of returning the auto-generated keys designated by the given array of column names

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed connection