com.subshell.persistence.runner
Class SimpleTransactionContextRunner

java.lang.Object
  extended by com.subshell.persistence.runner.SimpleTransactionContextRunner
All Implemented Interfaces:
TransactionContextRunner

public class SimpleTransactionContextRunner
extends Object
implements TransactionContextRunner

Runs a Runnable and provides it with a transaction context. This class will take care of setting up/destroying the transaction context. Additionally, it will commit/roll back the Transaction as necessary.

Note: The transaction must not be committed/rolled back by the Runnable.

Instances of this class are thread-safe, as must be instances of subclasses of this class.


Constructor Summary
SimpleTransactionContextRunner()
           
 
Method Summary
protected  Transaction openTransaction()
          Opens and returns a new transaction.
 void run(Runnable runnable)
          Runs the specified Runnable and provides it with a transaction context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTransactionContextRunner

public SimpleTransactionContextRunner()
Method Detail

run

public final void run(Runnable runnable)
               throws ErrorInRunnableException,
                      PersistenceException

Runs the specified Runnable and provides it with a transaction context. This method takes care of setting up/destroying the transaction context. It will also commit/roll back the transaction as necessary.

Note: The transaction must not be committed/rolled back by the Runnable.

Specified by:
run in interface TransactionContextRunner
Throws:
ErrorInRunnableException - when the Runnable itself has thrown an exception
PersistenceException - when there is a persistence-related error

openTransaction

protected Transaction openTransaction()
                               throws PersistenceException

Opens and returns a new transaction.

This method obtains a database from the database factory and uses it to open the transaction. Subclasses may override this method to provide an alternative implementation.

Throws:
PersistenceException - when there is a persistence-related error


Copyright © 2004-2005 subshell GmbH. All Rights Reserved.