com.subshell.persistence.runner
Class SelfContainedTransactionContextRunner

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

public class SelfContainedTransactionContextRunner
extends Object
implements TransactionContextRunner

Runs a Runnable and provides it with a self-contained transaction context. That is, the transaction context of the current thread will not be affected in any way. This class will take care of setting up/destroying the new transaction context. Additionally, it will commit/roll back the Transaction as necessary.

Instances of SelfContainedTransactionContextRunner may be nested, that is, a Runnable which is run in a SelfContainedTransactionContextRunner may itself use a SelfContainedTransactionContextRunner, and so on.

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
SelfContainedTransactionContextRunner()
           
 
Method Summary
protected  TransactionContextRunner createTransactionContextRunner()
          Creates and returns a new transaction context runner to be used inside the self-contained transaction context runner.
 void run(Runnable runnable)
          Runs the specified Runnable and provides it with a self-contained transaction context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelfContainedTransactionContextRunner

public SelfContainedTransactionContextRunner()
Method Detail

run

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

Runs the specified Runnable and provides it with a self-contained transaction context. That is, the transaction context of the current thread will not be affected in any way. This method takes care of setting up/destroying the new 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

createTransactionContextRunner

protected TransactionContextRunner createTransactionContextRunner()

Creates and returns a new transaction context runner to be used inside the self-contained transaction context runner.

This method creates a new SimpleTransactionContextRunner. Subclasses may override this method to provide an alternative implementation.



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