sqlj.runtime.ExecutionContext class

The sqlj.runtime.ExecutionContext class is defined for execution contexts. An execution context is used to control the execution of SQL statements.

Variables

ADD_BATCH_COUNT
Format:
public static final int ADD_BATCH_COUNT

A constant that can be returned by the getUpdateCount method. It indicates that the previous statement was not executed but was added to the existing statement batch.

AUTO_BATCH
Format:
public static final int AUTO_BATCH

A constant that can be passed to the setBatchLimit method. It indicates that implicit batch execution should be performed, and that SQLJ should determine the batch size.

DBDefault
Format:
public static final short DBDefault=-5;

A constant that can be assigned to an indicator variable. It specifies that the corresponding host variable value that is passed to the data server is the default value.

DBNonNull
Format:
public static final short DBNonNull=0;

A constant that can be assigned to an indicator variable. It specifies that the corresponding host variable value that is passed to the data server is a non-null value.

DBNull
Format:
public static final short DBNull=-1;

A constant that can be assigned to an indicator variable. It specifies that the corresponding host variable value that is passed to the data server is the SQL NULL value.

DBUnassigned
Format:
public static final short DBUnassigned=-7;

A constant that can be assigned to an indicator variable. It specifies that no value for the corresponding host variable is passed to the data server.

EXEC_BATCH_COUNT
Format:
public static final int EXEC_BATCH_COUNT

A constant that can be returned from the getUpdateCount method. It indicates that a statement batch was just executed.

EXCEPTION_COUNT
Format:
public static final int EXCEPTION_COUNT

A constant that can be returned from the getUpdateCount method. It indicates that an exception was thrown before the previous execution completed, or that no operation has been performed on the execution context object.

NEW_BATCH_COUNT
Format:
public static final int NEW_BATCH_COUNT

A constant that can be returned from the getUpdateCount method. It indicates that the previous statement was not executed, but was added to a new statement batch.

QUERY_COUNT
Format:
public static final int QUERY_COUNT

A constant that can be passed to the setBatchLimit method. It indicates that the previous execution produced a result set.

UNLIMITED_BATCH
Format:
public static final int UNLIMITED_BATCH

A constant that can be returned from the getUpdateCount method. It indicates that statements should continue to be added to a statement batch, regardless of the batch size.

Constructors:
ExecutionContext
Format:
public ExecutionContext()

Creates an ExecutionContext instance.

Methods

cancel
Format:
public void cancel() throws SQLException

Cancels an SQL operation that is currently being executed by a thread that uses the execution context object. If there is a pending statement batch on the execution context object, the statement batch is canceled and cleared.

The cancel method throws an SQLException if the statement cannot be canceled.

execute
Format:
public boolean execute ( ) throws SQLException

This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.

executeBatch
Format:
public synchronized int[] executeBatch() throws SQLException

Executes the pending statement batch and returns an array of update counts. If no pending statement batch exists, null is returned. When this method is called, the statement batch is cleared, even if the call results in an exception.

Each element in the returned array can be one of the following values:
-2
This value indicates that the SQL statement executed successfully, but the number of rows that were updated could not be determined.
-3
This value indicates that the SQL statement failed.
Other integer
This value is the number of rows that were updated by the statement.

The executeBatch method throws an SQLException if a database error occurs while the statement batch executes.

executeQuery
Format:
public RTResultSet executeQuery ( ) throws SQLException

This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.

executeUpdate
Format:
public int executeUpdate() throws SQLException

This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.

getBatchLimit
Format:
synchronized public int getBatchLimit()

Returns the number of statements that are added to a batch before the batch is implicitly executed.

The returned value is one of the following values:
UNLIMITED_BATCH
This value indicates that the batch size is unlimited.
AUTO_BATCH
This value indicates that the batch size is finite but unknown.
Other integer
The current batch limit.
getBatchUpdateCounts
Format:
public synchronized int[] getBatchUpdateCounts()

Returns an array that contains the number of rows that were updated by each statement that successfully executed in a batch. The order of elements in the array corresponds to the order in which statements were inserted into the batch. Returns null if no statements in the batch completed successfully.

Each element in the returned array can be one of the following values:
-2
This value indicates that the SQL statement executed successfully, but the number of rows that were updated could not be determined.
-3
This value indicates that the SQL statement failed.
Other integer
This value is the number of rows that were updated by the statement.
getFetchDirection
Format:
synchronized public int getFetchDirection() throws SQLException

Returns the current fetch direction for scrollable iterator objects that were generated from the given execution context. If a fetch direction was not set for the execution context, sqlj.runtime.ResultSetIterator.FETCH_FORWARD is returned.

getFetchSize
Format:
synchronized public int getFetchSize() throws SQLException

Returns the number of rows that should be fetched by SQLJ when more rows are needed. This value applies only to iterator objects that were generated from the given execution context. The returned value is the value that was set by the setFetchSize method, or 0 if no value was set by setFetchSize.

getMaxFieldSize
Format:
public synchronized int getMaxFieldSize()

Returns the maximum number of bytes that are returned for any string (character, graphic, or varying-length binary) column in queries that use the given execution context. If this limit is exceeded, SQLJ discards the remaining bytes. A value of 0 means that the maximum number of bytes is unlimited.

getMaxRows
Format:
public synchronized int getMaxRows()

Returns the maximum number of rows that are returned for any query that uses the given execution context. If this limit is exceeded, SQLJ discards the remaining rows. A value of 0 means that the maximum number of rows is unlimited.

getNextResultSet()
Format:
public ResultSet getNextResultSet() throws SQLException

After a stored procedure call, returns a result set from the stored procedure.

A null value is returned if any of the following conditions are true:
  • There are no more result sets to be returned.
  • The stored procedure call did not produce any result sets.
  • A stored procedure call has not been executed under the execution context.

When you invoke getNextResultSet(), SQLJ closes the currently-open result set and advances to the next result set.

If an error occurs during a call to getNextResultSet, resources for the current JDBC ResultSet object are released, and an SQLException is thrown. Subsequent calls to getNextResultSet return null.

getNextResultSet(int)
Formats:
public ResultSet getNextResultSet(int current)

After a stored procedure call, returns a result set from the stored procedure.

A null value is returned if any of the following conditions are true:
  • There are no more result sets to be returned.
  • The stored procedure call did not produce any result sets.
  • A stored procedure call has not been executed under the execution context.

If an error occurs during a call to getNextResultSet, resources for the current JDBC ResultSet object are released, and an SQLException is thrown. Subsequent calls to getNextResultSet return null.

Parameters:
current
Indicates what SQLJ does with the currently open result set before it advances to the next result set:
java.sql.Statement.CLOSE_CURRENT_RESULT
Specifies that the current ResultSet object is closed when the next ResultSet object is returned.
java.sql.Statement.KEEP_CURRENT_RESULT
Specifies that the current ResultSet object stays open when the next ResultSet object is returned.
java.sql.Statement.CLOSE_ALL_RESULTS
Specifies that all open ResultSet objects are closed when the next ResultSet object is returned.
getQueryTimeout
Format:
public synchronized int getQueryTimeout()

Returns the maximum number of seconds that SQL operations that use the given execution context object can execute. If an SQL operation exceeds the limit, an SQLException is thrown. The returned value is the value that was set by the setQueryTimeout method, or 0 if no value was set by setQueryTimeout. 0 means that execution time is unlimited.

getUpdateCount
Format:
public abstract int getUpdateCount() throws SQLException
Returns:
ExecutionContext.ADD_BATCH_COUNT
If the statement was added to an existing batch.
ExecutionContext.NEW_BATCH_COUNT
If the statement was the first statement in a new batch.
ExecutionContext.EXCEPTION_COUNT
If the previous statement generated an SQLException, or no previous statement was executed.
ExecutionContext.EXEC_BATCH_COUNT
If the statement was part of a batch, and the batch was executed.
ExecutionContext.QUERY_COUNT
If the previous statement created an iterator object or JDBC ResultSet.
Other integer
If the statement was executed rather than added to a batch. This value is the number of rows that were updated by the statement.
getWarnings
Format:
public synchronized SQLWarning getWarnings()

Returns the first warning that was reported by the last SQL operation that was executed using the given execution context. Subsequent warnings are chained to the first warning. If no warnings occurred, null is returned.

getWarnings is used to retrieve positive SQLCODEs.

isBatching
Format:
public synchronized boolean isBatching()

Returns true if batching is enabled for the execution context. Returns false if batching is disabled.

registerStatement
Format:
public RTStatement registerStatement(ConnectionContext connCtx, 
 Object profileKey, int stmtNdx)
 throws SQLException

This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.

releaseStatement
Format:
public void releaseStatement() throws SQLException

This method is used by code that is generated by the SQLJ translator. It is not intended for direct use by application programs.

setBatching
Format:
public synchronized void setBatching(boolean batching)
Parameters:
batching
Indicates whether batchable statements that are registered with the given execution context can be added to a statement batch:
true
Statements can be added to a statement batch.
false
Statements are executed individually.

setBatching affects only statements that occur in the program after setBatching is called. It does not affect previous statements or an existing statement batch.

setBatchLimit
Format:
public synchronized void setBatchLimit(int batch-size)

Sets the maximum number of statements that are added to a batch before the batch is implicitly executed.

Parameters:
batch-size
One of the following values:
ExecutionContext.UNLIMITED_BATCH
Indicates that implicit execution occurs only when SQLJ encounters a statement that is batchable but incompatible, or not batchable. Setting this value is the same as not invoking setBatchLimit.
ExecutionContext.AUTO_BATCH
Indicates that implicit execution occurs when the number of statements in the batch reaches a number that is set by SQLJ.
Positive integer
The number of statements that are added to the batch before SQLJ executes the batch implicitly. The batch might be executed before this many statements have been added if SQLJ encounters a statement that is batchable but incompatible, or not batchable.
setBatchLimit affects only statements that occur in the program after setBatchLimit is called. It does not affect an existing statement batch.
setFetchDirection
Format:
public synchronized void setFetchDirection(int direction) throws SQLException

Gives SQLJ a hint as to the current fetch direction for scrollable iterator objects that were generated from the given execution context.

Parameters:
direction
One of the following values:
sqlj.runtime.ResultSetIterator.FETCH_FORWARD
Rows are fetched in a forward direction. This is the default.
sqlj.runtime.ResultSetIterator.FETCH_REVERSE
Rows are fetched in a backward direction.
sqlj.runtime.ResultSetIterator.FETCH_UNKNOWN
The order of fetching is unknown.
Any other input value results in an SQLException.
setFetchSize
Format:
synchronized public void setFetchSize(int number-of-rows) throws SQLException

Gives SQLJ a hint as to the number of rows that should be fetched when more rows are needed.

Parameters:
number-of-rows
The expected number of rows that SQLJ should fetch for the iterator that is associated with the given execution context.
If number-of-rows is less than 0 or greater than the maximum number of rows that can be fetched, an SQLException is thrown.
setMaxFieldSize
Format:
public void setMaxFieldSize(int max-bytes)

Specifies the maximum number of bytes that are returned for any string (character, graphic, or varying-length binary) column in queries that use the given execution context. If this limit is exceeded, SQLJ discards the remaining bytes.

Parameters:
max-bytes
The maximum number of bytes that SQLJ should return from a BINARY, VARBINARY, CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC column. A value of 0 means that the number of bytes is unlimited. 0 is the default.
setMaxRows
Format:
public synchronized void setMaxRows(int max-rows)

Specifies the maximum number of rows that are returned for any query that uses the given execution context. If this limit is exceeded, SQLJ discards the remaining rows.

When setMaxRows is invoked at run time on a statically executed SELECT statement, setMaxRows limits the maximum number of rows in the result table through IBM® Data Server Driver for JDBC and SQLJ processing only. Data server optimization that limits the number of rows in the result table does not occur unless the FETCH FIRST n ROWS ONLY clause is also added to the SELECT statement. If FETCH FIRST n rows ONLY is added to the SELECT statement, and setMaxRows(m) is called, the maximum number of rows is the smaller of n and m. The driver discards the rest of the rows.

Parameters:
max-rows
The maximum number of rows that SQLJ should return for a query that uses the given execution context. A value of 0 means that the number of rows is unlimited. 0 is the default.
setQueryTimeout
Format:
public synchronized void setQueryTimeout(int timeout-value)

Specifies the maximum number of seconds that SQL operations that use the given execution context object can execute. If an SQL operation exceeds the limit, an SQLException is thrown.

For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity on Db2® for z/OS® data servers, setQueryTimeout is supported only if Connection or DataSource property queryTimeoutInterruptProcessingMode is set to INTERRUPT_PROCESSING_MODE_CLOSE_SOCKET.

Parameters:
timeout-value
The maximum number of seconds that SQL operations that use the given execution context object can execute. 0 means that execution time is unlimited. 0 is the default.