Arch4J 1.1

org.arch4j.dataaccess
Class TransactionalDatabaseManager

java.lang.Object
  |
  +--org.arch4j.dataaccess.DatabaseManager
        |
        +--org.arch4j.dataaccess.TransactionalDatabaseManager

public class TransactionalDatabaseManager
extends DatabaseManager

This extention of the DatabaseManager class adds joinable transaction functionality. Transactions are necessary anytime multiple operations against the database need to be atomic. All inserts, updates and deletes for a given transaction will succeed or fail together. Typical use is something like the following:

DatabaseManager transDBMgr = TransactionalDataAccessProvider.getProvider(); transDBMgr.executeTransaction( new AtomicOperationCommand() { public void execute() throws DataAccessException { // do multiple database operations using transDBMgr ... } } );

Author:
dcolwell

Field Summary
protected static LoggingCategory loggingCategory
          The logging category.
 
Fields inherited from class org.arch4j.dataaccess.DatabaseManager
connectionManager
 
Method Summary
protected  Connection beginDatabaseAction()
          Override the base implementation of this method to add transactional behaviour.
protected  void endDatabaseAction(ResultSet jdbcResultSet, Statement statement, Connection aConnection)
          Override the base implementation of this method to add transactional behaviour.
 BatchResult executeBatch(BatchQuery batchQuery)
          Extends the base class, DatabaseManager, by adding rollback functionality on failure.
 void executeTransaction(AtomicOperationCommand aCommand)
          Use this method to bound multiple database operations which need to execute as one atomic operation.
 boolean isMarkedForRollback()
          Knows if the current or just executed transaction is marked for rollback.
 void markForRollback()
          If this method is called at any time the transaction will rollback when endTransaction() is called.
 
Methods inherited from class org.arch4j.dataaccess.DatabaseManager
buildStatement, delete, execUpdate, execUpdate, execute, execute, execute, execute, execute, insert, notifyListener, select, select, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggingCategory

protected static LoggingCategory loggingCategory
The logging category.

Method Detail

executeTransaction

public void executeTransaction(AtomicOperationCommand aCommand)
                        throws DataAccessException
Use this method to bound multiple database operations which need to execute as one atomic operation. See the class documentation for example use.

DataAccessException

markForRollback

public void markForRollback()
If this method is called at any time the transaction will rollback when endTransaction() is called. In other words, it will never commit.


isMarkedForRollback

public boolean isMarkedForRollback()
Knows if the current or just executed transaction is marked for rollback.


executeBatch

public BatchResult executeBatch(BatchQuery batchQuery)
                         throws DataAccessException
Extends the base class, DatabaseManager, by adding rollback functionality on failure. Note that the JDBC specification does not specify if a BatchQuery will execute as an atomic operation or not. If a single statement fails, it is up to the implementation whether or not to continue with remaining statements. Executes the statements added to the batch query. All queries are submitted in a batch. If any one of them fails the transaction is rolled back. Add only those queries that are valid in a transaction context, Do not add select statements to the bactch as they not valid in a JDBC 2.0 batch call

Overrides:
executeBatch in class DatabaseManager
Returns:
A result object that contains the result of each query and an overall status
Throws:
DataAccessException - If a database error occurs.

beginDatabaseAction

protected Connection beginDatabaseAction()
                                  throws SQLException
Override the base implementation of this method to add transactional behaviour. Joins or begins a transaction and returns a reference to the connection.

Overrides:
beginDatabaseAction in class DatabaseManager
Returns:
A connection to the URL.
Throws:
SQLException - If unable to connect or no more connections available.

endDatabaseAction

protected void endDatabaseAction(ResultSet jdbcResultSet,
                                 Statement statement,
                                 Connection aConnection)
Override the base implementation of this method to add transactional behaviour. Releases the JDBC resources and ends the transaction, if it was started here.

Overrides:
endDatabaseAction in class DatabaseManager
Parameters:
jdbcResultSet - The data produced by a query.
statement - The pre-compiled SQL statement.

Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.