com.sap.sql
Class BatchExecutionContext

java.lang.Object
  |
  +--sqlj.runtime.ExecutionContext
        |
        +--com.sap.sql.BatchExecutionContext

public class BatchExecutionContext
extends ExecutionContext

The class BatchExecutionContext allows for batching in Open SQL / SQLJ. In Open SQL / SQLJ, batching is only possible for statements executed using an instance of this class as their execution context.

In contrast to batching as specified in the ISO/IEC 9075-10, the BatchExecutionContext does not perform an implicit execution of a statement batch, if it is atempted to execute an batch incompatible statement. Two statements are regarded to be batch compatible iff they have exactly the same source code position. Typically, batching with Open SQL / SQLJ will be used in a loop.

Example:

 String names[] = { "Hugo", "Emil", Paul", Egon" };
 BatchExecutionContext btx = new BatchExecutionContext();
 
 for(int i = 0; i < names.length; i++) {
    #sql [ctx, btx] { UPDATE dbtab SET name = :(names[i]) WHERE key = :i };
 }
 btx.executeBatch();
 

See Also:
ExecutionContext, ExecutionContext.executeBatch()

Fields inherited from class sqlj.runtime.ExecutionContext
ADD_BATCH_COUNT, AUTO_BATCH, EXCEPTION_COUNT, EXEC_BATCH_COUNT, NEW_BATCH_COUNT, QUERY_COUNT, UNLIMITED_BATCH
 
Constructor Summary
BatchExecutionContext()
          Creates a new BatchExecutionContext object.
 
Method Summary
 int getBatchLimit()
          Returns the current batch limit that was set for this BatchExecutionContext object.
 sqlj.runtime.profile.RTStatement registerStatement(ConnectionContext connCtx, java.lang.Object profileKey, int stmtNdx)
          This methods is for internal use of the SQLJ runtime an must not be called by an application.
 void setBatching(boolean doBatch)
          On an BatchExecutionContext object, batching cannot be switched of.
 void setBatchLimit(int batchLimit)
          Sets the maximum batch size on this batch context object.
 
Methods inherited from class sqlj.runtime.ExecutionContext
cancel, execute, executeBatch, executeQuery, executeUpdate, getBatchUpdateCounts, getFetchDirection, getFetchSize, getMaxFieldSize, getMaxRows, getNextResultSet, getQueryTimeout, getUpdateCount, getWarnings, isBatching, releaseStatement, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setQueryTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchExecutionContext

public BatchExecutionContext()
Creates a new BatchExecutionContext object. On the newly created object, batching is allway switched on and cannot be switched off. The batch size is set to ExcutionContext.UNLIMITED_BATCH
See Also:
ExecutionContext, ExecutionContext.UNLIMITED_BATCH
Method Detail

setBatchLimit

public void setBatchLimit(int batchLimit)
Sets the maximum batch size on this batch context object. When the maximum batch size is exceeded, implicit batch execution is performed.

Overrides:
setBatchLimit in class ExecutionContext
Parameters:
batchLimit - ExecutionContext.UNLIMITED_BATCH if the maximum batch size is unlimited, ExecutionContext.AUTO_BATCH if the maximum batch size is finite and implementation dependent, or n > 0 for a maximum batch size of n.
See Also:
ExecutionContext, ExecutionContext.UNLIMITED_BATCH, ExecutionContext.AUTO_BATCH

getBatchLimit

public int getBatchLimit()
Returns the current batch limit that was set for this BatchExecutionContext object.

Overrides:
getBatchLimit in class ExecutionContext
Returns:
Cases:
  • If the maximum batch size is unlimited, then ExecutionContext.UNLIMITED_BATCH.
  • If the maximum batch size is finite and implementation-dependent, then ExecutionContext.AUTO_BATCH.
  • Otherwise, a maximum batch size n > 0.
See Also:
ExecutionContext, ExecutionContext.UNLIMITED_BATCH, ExecutionContext.AUTO_BATCH

setBatching

public void setBatching(boolean doBatch)
On an BatchExecutionContext object, batching cannot be switched of. If this methos is invoked with false, a runtime exception will be thrown.
Overrides:
setBatching in class ExecutionContext
Following copied from class: sqlj.runtime.ExecutionContext
Parameters:
doBatch - true if batching should be enabled; false if batching should be disabled
See Also:
BatchExecutionContext

registerStatement

public sqlj.runtime.profile.RTStatement registerStatement(ConnectionContext connCtx,
                                                          java.lang.Object profileKey,
                                                          int stmtNdx)
                                                   throws java.sql.SQLException
This methods is for internal use of the SQLJ runtime an must not be called by an application.
Overrides:
registerStatement in class ExecutionContext
Following copied from class: sqlj.runtime.ExecutionContext
Parameters:
connCtx - the connection context that contains the profile that contains the statement to register.
profileKey - the key of the connected profile within the connection context.
stmtNdx - the 0-based index of the statement within the profile to be registered.
Throws:
java.sql.SQLException - if the max fields size, max rows, or query timeout cannot be set on the registered statement.
See Also:
ExecutionContext.releaseStatement(), ConnectedProfile.getStatement(int, java.util.Map), ConnectionContext.getConnectedProfile(java.lang.Object)