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

pack-priv abstract Class LogicalStatementEntity

extends Object
implements Statement
Class Inheritance
All Implemented Interfaces
java.sql.Statement, java.lang.AutoCloseable, java.sql.Wrapper
Known Direct Subclasses
org.apache.derby.client.am.LogicalPreparedStatement
Imports
java.sql.CallableStatement, .PreparedStatement, .SQLException, .Statement, org.apache.derby.client.am.stmtcache.JDBCStatementCache, .StatementKey, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager

Common class interacting with the JDBC statement cache for logical prepared statements and logical callable statements.

Note that getPhysPs and getPhysCs takes care of checking if the logical statement has been closed. The physical statement will take care of validating itself.

Beside from the above, special treatment of logical entities happens on close. This is the point where cache interaction takes place, and also where the appropriate methods are called on the physical statement to perform the necessary clean up for later reuse.

A note regarding the thread safety of this class, is that access to physicalPs and physicalCs is guarded by the instance of this class, but it is assumed that operation on/within the physical statement is synchronized in the physical statement itself .

Field Summary

Modifier and TypeField and Description
private final JDBCStatementCache
cache

Cache for physical statements.

private final boolean
hasCallableStmt

Tells if we're holding a callable statement or not.

private StatementCacheInteractor
owner

The owner of this logical entity.

private CallableStatement
physicalCs

Associated physical callable statement, if any.

private PreparedStatement
physicalPs

Associated physical prepared statement.

private final StatementKey
stmtKey

The key for the associated statement.

Constructor Summary

AccessConstructor and Description
protected
LogicalStatementEntity(PreparedStatement physicalPs, StatementKey
cache key for the physical statement
stmtKey
,
StatementCacheInteractor
creating statement cache interactor
cacheInteractor
)

Create a logical entity for a java.sql.PreparedStatement.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Implements java.sql.Statement.close.

Close the logical statement.
public void
closeOnCompletion()

Implements java.sql.Statement.closeOnCompletion.

Specifies that this Statement will be closed when all its dependent result sets are closed.
public long[]
executeLargeBatch()

Overrides default java.sql.Statement.executeLargeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.
public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int
a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.
public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row
columnIndexes
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
public long
getLargeMaxRows()

Overrides default java.sql.Statement.getLargeMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.
public long
getLargeUpdateCount()

Overrides default java.sql.Statement.getLargeUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.
pack-priv synchronized CallableStatement

Returns:

A callable statement.
getPhysCs
()

Returns the associated physical callable statement.

pack-priv synchronized PreparedStatement

Returns:

A prepared statement.
getPhysPs
()

Returns the associated physical prepared statement.

private synchronized Statement

Returns:

A statement.
getPhysStmt
()

Returns the associated physical statement.

public boolean
isCloseOnCompletion()

Implements java.sql.Statement.isCloseOnCompletion.

Returns a value indicating whether this Statement will be closed when all its dependent result sets are closed.
pack-priv synchronized boolean

Returns:

true if closed, false if open.
isLogicalEntityClosed
()

Tells if the logical entity is closed.

public boolean

Returns:

true if this instance implements iface, or false otherwise
isWrapperFor
(Class<?>
a class defining an interface
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Check whether this instance wraps an object that implements the interface specified by iface.
public void
setLargeMaxRows(long
the new max rows limit; zero means there is no limit
maxRows
)

Overrides default java.sql.Statement.setLargeMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.
public <T> T

Returns:

an object that implements the interface
unwrap
(Class<T>
a class defining an interface
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an instance of the specified interface if this instance is a wrapper for the interface.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private final JDBCStatementCache cache

Cache for physical statements.

hasCallableStmtback to summary
private final boolean hasCallableStmt

Tells if we're holding a callable statement or not.

Used for sanity checking.

ownerback to summary
private StatementCacheInteractor owner

The owner of this logical entity.

physicalCsback to summary
private CallableStatement physicalCs

Associated physical callable statement, if any.

This is a convenience reference, to avoid having to cast on every invocation of getPhysCs if the logical entity represents a callable statement.

physicalPsback to summary
private PreparedStatement physicalPs

Associated physical prepared statement.

If this is null, the logical entity is closed.

stmtKeyback to summary
private final StatementKey stmtKey

The key for the associated statement.

Constructor Detail

LogicalStatementEntityback to summary
protected LogicalStatementEntity(PreparedStatement physicalPs, StatementKey stmtKey, StatementCacheInteractor cacheInteractor)

Create a logical entity for a java.sql.PreparedStatement.

Parameters
physicalPs:PreparedStatement

a physical java.sql.PreparedStatement

stmtKey:StatementKey

cache key for the physical statement

cacheInteractor:StatementCacheInteractor

creating statement cache interactor

Exceptions
IllegalArgumentException:
if cache is null

Method Detail

closeback to summary
public synchronized void close() throws SQLException

Implements java.sql.Statement.close.

Close the logical statement.

Exceptions
SQLException:
if closing the statement fails
closeOnCompletionback to summary
public void closeOnCompletion() throws SQLException

Implements java.sql.Statement.closeOnCompletion.

Doc from java.sql.Statement.closeOnCompletion.

Specifies that this Statement will be closed when all its dependent result sets are closed. If execution of the Statement does not produce any result sets, this method has no effect.

Note

Multiple calls to closeOnCompletion do not toggle the effect on this Statement. However, a call to closeOnCompletion does effect both the subsequent execution of statements, and statements that currently have open, dependent, result sets.

Exceptions
SQLException:
if this method is called on a closed Statement
executeLargeBatchback to summary
public long[] executeLargeBatch() throws SQLException

Overrides default java.sql.Statement.executeLargeBatch.

Doc from java.sql.Statement.executeLargeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The long elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeLargeBatch may be one of the following:

  1. A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
  2. A value of SUCCESS_NO_INFO -- indicates that the command was processed successfully but that the number of rows affected is unknown

    If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getLargeUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following:

  3. A value of EXECUTE_FAILED -- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

The default implementation will throw UnsupportedOperationException

Returns:long[]

an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement or the driver does not support batch statements. Throws BatchUpdateException (a subclass of SQLException) if one of the commands sent to the database fails to execute properly or attempts to return a result set.
executeLargeUpdateback to summary
public long executeLargeUpdate(String sql) throws SQLException

Overrides default java.sql.Statement.executeLargeUpdate.

Doc from java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

Note

This method cannot be called on a PreparedStatement or CallableStatement.

The default implementation will throw UnsupportedOperationException

Parameters
sql:String

an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Returns:long

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement, the given SQL statement produces a ResultSet object, the method is called on a PreparedStatement or CallableStatement
executeLargeUpdateback to summary
public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException

Overrides default java.sql.Statement.executeLargeUpdate.

Doc from java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval. The driver will ignore the flag 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).

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

Note

This method cannot be called on a PreparedStatement or CallableStatement.

The default implementation will throw SQLFeatureNotSupportedException

Parameters
sql:String

an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

autoGeneratedKeys:int

a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS

Returns:long

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement, the given SQL statement returns a ResultSet object, the given constant is not one of those allowed, the method is called on a PreparedStatement or CallableStatement
executeLargeUpdateback to summary
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException

Overrides default java.sql.Statement.executeLargeUpdate.

Doc from java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. 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).

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

Note

This method cannot be called on a PreparedStatement or CallableStatement.

The default implementation will throw SQLFeatureNotSupportedException

Parameters
sql:String

an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

columnIndexes:int[]

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

Returns:long

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement, the SQL statement returns a ResultSet object,the second argument supplied to this method is not an int array whose elements are valid column indexes, the method is called on a PreparedStatement or CallableStatement
executeLargeUpdateback to summary
public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException

Overrides default java.sql.Statement.executeLargeUpdate.

Doc from java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. This array contains the names 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).

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

Note

This method cannot be called on a PreparedStatement or CallableStatement.

The default implementation will throw SQLFeatureNotSupportedException

Parameters
sql:String

an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

columnNames:String[]

an array of the names of the columns that should be returned from the inserted row

Returns:long

either the row count for INSERT, UPDATE, or DELETE statements, or 0 for SQL statements that return nothing

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement, the SQL statement returns a ResultSet object, the second argument supplied to this method is not a String array whose elements are valid column names, the method is called on a PreparedStatement or CallableStatement
getLargeMaxRowsback to summary
public long getLargeMaxRows() throws SQLException

Overrides default java.sql.Statement.getLargeMaxRows.

Doc from java.sql.Statement.getLargeMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain. If this limit is exceeded, the excess rows are silently dropped.

This method should be used when the returned row limit may exceed Integer#MAX_VALUE.

The default implementation will return 0

Returns:long

the current maximum number of rows for a ResultSet object produced by this Statement object; zero means there is no limit

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed Statement
getLargeUpdateCountback to summary
public long getLargeUpdateCount() throws SQLException

Overrides default java.sql.Statement.getLargeUpdateCount.

Doc from java.sql.Statement.getLargeUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned. This method should be called only once per result.

This method should be used when the returned row count may exceed Integer#MAX_VALUE.

The default implementation will throw UnsupportedOperationException

Returns:long

the current result as an update count; -1 if the current result is a ResultSet object or there are no more results

Exceptions
SQLException:
if a database access error occurs or this method is called on a closed Statement
getPhysCsback to summary
pack-priv synchronized CallableStatement getPhysCs() throws SQLException

Returns the associated physical callable statement.

Returns:CallableStatement

A callable statement.

Exceptions
SQLException:
if the logical statement has been closed
getPhysPsback to summary
pack-priv synchronized PreparedStatement getPhysPs() throws SQLException

Returns the associated physical prepared statement.

Returns:PreparedStatement

A prepared statement.

Exceptions
SQLException:
if the logical statement has been closed
getPhysStmtback to summary
private synchronized Statement getPhysStmt() throws SQLException

Returns the associated physical statement.

Returns:Statement

A statement.

Exceptions
SQLException:
if the logical statement has been closed
isCloseOnCompletionback to summary
public boolean isCloseOnCompletion() throws SQLException

Implements java.sql.Statement.isCloseOnCompletion.

Doc from java.sql.Statement.isCloseOnCompletion.

Returns a value indicating whether this Statement will be closed when all its dependent result sets are closed.

Returns:boolean

true if the Statement will be closed when all of its dependent result sets are closed; false otherwise

Exceptions
SQLException:
if this method is called on a closed Statement
isLogicalEntityClosedback to summary
pack-priv synchronized boolean isLogicalEntityClosed()

Tells if the logical entity is closed.

If this method is used to avoid the possibility of raising an exception because the logical statement has been closed and then invoke a method on the physical statement, one must synchronize on this instance in the calling code.

Returns:boolean

true if closed, false if open.

isWrapperForback to summary
public boolean isWrapperFor(Class<?> iface) throws SQLException

Implements java.sql.Wrapper.isWrapperFor.

Check whether this instance wraps an object that implements the interface specified by iface.

Parameters
iface:Class<?>

a class defining an interface

Returns:boolean

true if this instance implements iface, or false otherwise

Exceptions
SQLException:
if an error occurs while determining if this instance implements iface
setLargeMaxRowsback to summary
public void setLargeMaxRows(long maxRows) throws SQLException

Overrides default java.sql.Statement.setLargeMaxRows.

Doc from java.sql.Statement.setLargeMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number. If the limit is exceeded, the excess rows are silently dropped.

This method should be used when the row limit may exceed Integer#MAX_VALUE.

The default implementation will throw UnsupportedOperationException

Parameters
maxRows:long

the new max rows limit; zero means there is no limit

Exceptions
SQLException:
if a database access error occurs, this method is called on a closed Statement or the condition max >= 0 is not satisfied
unwrapback to summary
public <T> T unwrap(Class<T> iface) throws SQLException

Implements java.sql.Wrapper.unwrap.

Returns an instance of the specified interface if this instance is a wrapper for the interface.

Parameters
<T>

Doc from java.sql.Wrapper.unwrap. the type of the class modeled by this Class object

iface:Class<T>

a class defining an interface

Returns:T

an object that implements the interface

Exceptions
SQLException:
if no object is found that implements the interface