org.openanzo.jdbc.utils.batchable
Class BatchExecuter

java.lang.Object
  extended by org.openanzo.jdbc.utils.batchable.BatchExecuter

public class BatchExecuter
extends java.lang.Object

Commits a List of batchable rdb statements (DDL, inserts, updates and deletes) to the database using optimal jdbc prepared statement batching. This is useful in situations where a application is building up a bunch of changes to database tables and may contain multiple calls to individual prepared statements. This executer will sort the prepared statement calls and execute calls to the same prepared statement together in a batch.

Author:
Joe Betz
See Also:
Batchable

Nested Class Summary
static interface BatchExecuter.BatchHandler
          Methods that get run before and after the executor executes the batchables
 
Constructor Summary
BatchExecuter()
           
 
Method Summary
static void execute(PreparedStatementCache cache, Batchable.BatchOperation op)
          Execute a single BatchOperation
static void execute(PreparedStatementCache cache, Batchable batchItem)
          Execute a single Batchable.
static void execute(PreparedStatementCache cache, BatchOperationQueue boq)
          Execute the contents of a BatchOperationQueue
static boolean execute(PreparedStatementCache cache, BatchOperationQueue boq, BatchExecuter.BatchHandler handler)
          Execute the contents of a BatchOperationQueue
static void executeUnsorted(PreparedStatementCache cache, Batchable batchItem)
          Execute a single Batchable, without first sorting and merging any operations with the Batchable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchExecuter

public BatchExecuter()
Method Detail

execute

public static void execute(PreparedStatementCache cache,
                           Batchable.BatchOperation op)
                    throws java.sql.SQLException
Execute a single BatchOperation

Parameters:
cache - source of preparedStatements
op - operation to execute
Throws:
java.sql.SQLException - if there was an error executing the operation

execute

public static void execute(PreparedStatementCache cache,
                           Batchable batchItem)
                    throws RdbException
Execute a single Batchable. Items in batchable are first added to a BatchOperationQueue, so that they are operated on in a sorted and merged order.

Parameters:
cache - source of preparedStatements
batchItem - Batchable to execute
Throws:
RdbException - if there was an error executing the operation

executeUnsorted

public static void executeUnsorted(PreparedStatementCache cache,
                                   Batchable batchItem)
                            throws RdbException
Execute a single Batchable, without first sorting and merging any operations with the Batchable.

Parameters:
cache - source of preparedStatements
batchItem - Batchable to execute
Throws:
RdbException - if there was an error executing the operation

execute

public static void execute(PreparedStatementCache cache,
                           BatchOperationQueue boq)
                    throws java.sql.SQLException
Execute the contents of a BatchOperationQueue

Parameters:
cache - source of preparedStatements
boq - BatchOperationQueue to execute
Throws:
java.sql.SQLException - if there was an exception executing queue

execute

public static boolean execute(PreparedStatementCache cache,
                              BatchOperationQueue boq,
                              BatchExecuter.BatchHandler handler)
                       throws java.sql.SQLException
Execute the contents of a BatchOperationQueue

Parameters:
cache - source of preparedStatements
boq - BatchOperationQueue to execute
handler - Callback handler that is called before and after executing the queue
Returns:
true if queue was executed successfully
Throws:
java.sql.SQLException - if there was an exception executing queue


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.