org.slim3.transaction.jta
Class JtaTransactionController

java.lang.Object
  extended by org.slim3.transaction.controller.AbstractTransactionController
      extended by org.slim3.transaction.jta.JtaTransactionController
All Implemented Interfaces:
TransactionController

public class JtaTransactionController
extends AbstractTransactionController

An implementation class for TransactionController using JTA.

Since:
3.0
Author:
koichik, higa

Field Summary
protected  TransactionManager transactionManager
          The transaction manager.
protected  UserTransaction userTransaction
          The user transaction.
 
Constructor Summary
JtaTransactionController(UserTransaction userTransaction, TransactionManager transactionManager)
          Constructor.
 
Method Summary
protected  boolean begin()
          Begins a new transaction.
protected  void end()
          Commits or rolls back a transaction.
protected  boolean hasTransaction()
          Returns true if the current thread has a transaction.
 Object notSupported(TransactionAction action)
          Executes the action within a transaction.
 Object required(TransactionAction action)
          Executes the action within a transaction.
 Object requiresNew(TransactionAction action)
          Executes the action within a transaction.
protected  void resume(Transaction transaction)
          Resumes the transaction.
 void setRollbackOnly()
          Modify the transaction such that the transaction is rolled back.
protected  Transaction suspend()
          Suspends the current transaction.
 
Methods inherited from class org.slim3.transaction.controller.AbstractTransactionController
execute, mandatory, never
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userTransaction

protected UserTransaction userTransaction
The user transaction.


transactionManager

protected TransactionManager transactionManager
The transaction manager.

Constructor Detail

JtaTransactionController

public JtaTransactionController(UserTransaction userTransaction,
                                TransactionManager transactionManager)
                         throws NullPointerException
Constructor.

Parameters:
userTransaction - the user transaction
transactionManager - the transaction manager
Throws:
NullPointerException - if the userTransaction parameter is null or if the transactionManager parameter is null
Method Detail

required

public Object required(TransactionAction action)
                throws NotSupportedException,
                       Exception
Description copied from interface: TransactionController
Executes the action within a transaction. If the client is not associated with a transaction, the controller starts a new transaction before execute the action.

Parameters:
action - the action
Returns:
a result which the action returns
Throws:
NotSupportedException - if nested transaction is not supported
Exception - if an exception is encountered

requiresNew

public Object requiresNew(TransactionAction action)
                   throws Exception
Description copied from interface: TransactionController
Executes the action within a transaction. Even if the client is associated with a transaction or not, the controller starts a new transaction before executing the action.

Parameters:
action - the action
Returns:
a result which the action returns
Throws:
Exception - if an exception is encountered

notSupported

public Object notSupported(TransactionAction action)
                    throws Exception
Description copied from interface: TransactionController
Executes the action within a transaction. If the client is not associated with a transaction, the controller suspends the client’s transaction before executing the action. After the action has completed, the controller resumes the client’s transaction. If the client is not associated with a transaction, the controller does not start a new transaction.

Parameters:
action - the action
Returns:
a result which the action returns
Throws:
Exception - if an exception is encountered

setRollbackOnly

public void setRollbackOnly()
Description copied from interface: TransactionController
Modify the transaction such that the transaction is rolled back.


hasTransaction

protected boolean hasTransaction()
                          throws Exception
Description copied from class: AbstractTransactionController
Returns true if the current thread has a transaction.

Specified by:
hasTransaction in class AbstractTransactionController
Returns:
whether the current thread has a transaction
Throws:
Exception - if an exception is encountered
See Also:
UserTransaction.getStatus()

begin

protected boolean begin()
                 throws Exception
Begins a new transaction. Returns true If a new transaction began.

Returns:
whether a new transaction began
Throws:
NotSupportedException - if nested transaction is not supported
Exception - if an exception is encountered
See Also:
UserTransaction.begin()

end

protected void end()
            throws Exception
Commits or rolls back a transaction.

Throws:
Exception - if an exception is encountered
See Also:
UserTransaction.commit(), UserTransaction.rollback()

suspend

protected Transaction suspend()
                       throws Exception
Suspends the current transaction.

Returns:
the suspended transaction
Throws:
Exception - if an exception is encountered
See Also:
TransactionManager.suspend()

resume

protected void resume(Transaction transaction)
               throws Exception
Resumes the transaction.

Parameters:
transaction - the transaction
Throws:
Exception - if an exception is encountered
See Also:
TransactionManager.resume(Transaction)


Copyright © 2008-2009 The Slim3 project. All Rights Reserved.