net.liftmodules.transaction

TransactionProtocol

trait TransactionProtocol extends AnyRef

Trait that implements a JTA transaction service that obeys the transaction semantics defined in the transaction attribute types for the transacted methods according to the EJB 3 draft specification. The aspect handles UserTransaction, TransactionManager instance variable injection thru @javax.ejb.Inject (name subject to change as per EJB 3 spec) and method transaction levels thru @javax.ejb.TransactionAttribute.

This trait should be inherited to implement the getTransactionManager() method that should return a concrete javax.transaction.TransactionManager implementation (from JNDI lookup etc).

Transaction attribute semantics

(From http://www.kevinboone.com/ejb-transactions.html)

Required

'Required' is probably the best choice (at least initially) for an EJB method that will need to be transactional. In this case, if the method's caller is already part of a transaction, then the EJB method does not create a new transaction, but continues in the same transaction as its caller. If the caller is not in a transaction, then a new transaction is created for the EJB method. If something happens in the EJB that means that a rollback is required, then the extent of the rollback will include everything done in the EJB method, whatever the condition of the caller. If the caller was in a transaction, then everything done by the caller will be rolled back as well. Thus the 'required' attribute ensures that any work done by the EJB will be rolled back if necessary, and if the caller requires a rollback that too will be rolled back.

RequiresNew

'RequiresNew' will be appropriate if you want to ensure that the EJB method is rolled back if necessary, but you don't want the rollback to propogate back to the caller. This attribute results in the creation of a new transaction for the method, regardless of the transactional state of the caller. If the caller was operating in a transaction, then its transaction is suspended until the EJB method completes. Because a new transaction is always created, there may be a slight performance penalty if this attribute is over-used.

Mandatory

With the 'mandatory' attribute, the EJB method will not even start unless its caller is in a transaction. It will throw a TransactionRequiredException instead. If the method does start, then it will become part of the transaction of the caller. So if the EJB method signals a failure, the caller will be rolled back as well as the EJB.

Supports

With this attribute, the EJB method does not care about the transactional context of its caller. If the caller is part of a transaction, then the EJB method will be part of the same transaction. If the EJB method fails, the transaction will roll back. If the caller is not part of a transaction, then the EJB method will still operate, but a failure will not cause anything to roll back. 'Supports' is probably the attribute that leads to the fastest method call (as there is no transactional overhead), but it can lead to unpredicatable results. If you want a method to be isolated from transactions, that is, to have no effect on the transaction of its caller, then use 'NotSupported' instead.

NotSupported

With the 'NotSupported' attribute, the EJB method will never take part in a transaction. If the caller is part of a transaction, then the caller's transaction is suspended. If the EJB method fails, there will be no effect on the caller's transaction, and no rollback will occur. Use this method if you want to ensure that the EJB method will not cause a rollback in its caller. This is appropriate if, for example, the method does something non-essential, such as logging a message. It would not be helpful if the failure of this operation caused a transaction rollback.

Never

The 'NotSupported attribute will ensure that the EJB method is never called by a transactional caller. Any attempt to do so will result in a RemoteException being thrown. This attribute is probably less useful than NotSupported', in that NotSupported will assure that the caller's transaction is never affected by the EJB method (just as Never' does), but will allow a call from a transactional caller if necessary.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. TransactionProtocol
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  7. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. def commitOrRollBack (tm: TransactionManager): Unit

    Attributes
    protected
  9. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  10. def equals (arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  12. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef → Any
  13. def handleException (tm: TransactionManager, e: Exception): Nothing

    Attributes
    protected
  14. def hashCode (): Int

    Definition Classes
    AnyRef → Any
  15. def isInExistingTransaction (tm: TransactionManager): Boolean

    Checks if a transaction is an existing transaction.

    Checks if a transaction is an existing transaction.

    tm

    the transaction manager

    returns

    boolean

    Attributes
    protected
  16. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  17. def isRollbackOnly (tm: TransactionManager): Boolean

    Checks if current transaction is set to rollback only.

    Checks if current transaction is set to rollback only.

    tm

    the transaction manager

    returns

    boolean

    Attributes
    protected
  18. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  19. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  20. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  21. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  22. def toString (): String

    Definition Classes
    AnyRef → Any
  23. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  24. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  25. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  26. def withTxMandatory [T] (body: ⇒ T): T

    Wraps body in a transaction with MANDATORY semantics.

    Wraps body in a transaction with MANDATORY semantics.

    Throws a TransactionRequiredException if there is no transaction active in scope.

  27. def withTxNever [T] (body: ⇒ T): T

    Wraps body in a transaction with NEVER semantics.

    Wraps body in a transaction with NEVER semantics.

    Throws a SystemException in case of an existing transaction in scope.

  28. def withTxNotSupported [T] (body: ⇒ T): T

    Wraps body in a transaction with NOT_SUPPORTED semantics.

    Wraps body in a transaction with NOT_SUPPORTED semantics.

    Suspends existing transaction, invokes body, resumes transaction.

  29. def withTxRequired [T] (body: ⇒ T): T

    Wraps body in a transaction with REQUIRED semantics.

    Wraps body in a transaction with REQUIRED semantics.

    Creates a new transaction if no transaction is active in scope, else joins the outer transaction.

  30. def withTxRequiresNew [T] (body: ⇒ T): T

    Wraps body in a transaction with REQUIRES_NEW semantics.

    Wraps body in a transaction with REQUIRES_NEW semantics.

    Suspends existing transaction, starts a new transaction, invokes body, commits or rollbacks new transaction, finally resumes previous transaction.

  31. def withTxSupports [T] (body: ⇒ T): T

    Wraps body in a transaction with SUPPORTS semantics.

    Wraps body in a transaction with SUPPORTS semantics.

    Basicalla a No-op.

Inherited from AnyRef

Inherited from Any