org.wamblee.test.transactions
Class SimpleTransactionManager

java.lang.Object
  extended by org.wamblee.test.transactions.SimpleTransactionManager

public class SimpleTransactionManager
extends java.lang.Object

Simple transaction manager provides a simple mechanism to manage transactions in test code through the UserTransaction object. To construct the transaction manager use:

 SimpleTransactionManager manager = new SimpleTransactionManager(
     new DefaultUserTransactionFactory());
 

Next, add resources to manage using addResource(TransactionResource):

 manager.addResource(jpaTester.getJpaBuilder());
 

As you can see from the above, JpaBuilder is a resource that can be used so this mechanism can be used with JPA testing.

The next step is to manage transactions using the standard UserTransaction APIs:

      UserTransaction transaction = manager.getTransaction();
      transaction.begin();
     
      ... do work...
  
      transaction.commit();
 

Author:
Erik Brakkee

Constructor Summary
SimpleTransactionManager(UserTransactionFactory aFactory)
          Constructs the transaction manager.
 
Method Summary
 void addResource(TransactionResource aResource)
          Adds a resource to manage.
 javax.transaction.UserTransaction getTransaction()
          Gets the user transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTransactionManager

public SimpleTransactionManager(UserTransactionFactory aFactory)
Constructs the transaction manager.

Parameters:
aFactory - Factory to create transactions with.
Method Detail

addResource

public void addResource(TransactionResource aResource)
Adds a resource to manage. Adding resources is no longer allowed after the first transaction has started.

Parameters:
aResource - Resource.

getTransaction

public javax.transaction.UserTransaction getTransaction()
Gets the user transaction. This is a contextual reference, meaning that it will delegate to the appropriate thread-specific user transaction. It is also safe to store in a JNDI tree and for caching by applications.

Returns:
User transaction.


Copyright © 2010. All Rights Reserved.