org.apache.openejb.core.transaction
Interface TransactionPolicy

All Known Subinterfaces:
BeanTransactionPolicy
All Known Implementing Classes:
JtaTransactionPolicy, SpringBeanTransactionPolicy, SpringTransactionPolicy, TxBeanManaged, TxMandatory, TxNever, TxNotSupported, TxRequired, TxRequiresNew, TxSupports

public interface TransactionPolicy

TransactionPolicy represents a JEE container managed or bean manage transaction.

This class can be used to query the transaction status, set the transaction rollback only flag, associate resources with the transaction and to register a listener for transaction completion events.


Nested Class Summary
static interface TransactionPolicy.TransactionSynchronization
          TransactionSynchronization receives notifications as the Transaction completes.
 
Method Summary
 void commit()
          Commits or rolls back this TransactionPolicy.
 void enlistResource(XAResource xaResource)
          Enlists a XAResource in the actual active transaction.
 Object getResource(Object key)
          Gets a resource associated with the specified key.
 TransactionType getTransactionType()
          Gets the TransactionType for this policy.
 boolean isClientTransaction()
          Is this policy running in an inhreited transaction? Some TransactionTypes, such as Required or Supported, use the caller's transaction instead of starting a new transaction.
 boolean isNewTransaction()
          Is this a new transaction and not an inhreited transaction or no transaction? Some TransactionTypes, such as Required or Supported, use the caller's transaction instead of starting a new transaction.
 boolean isRollbackOnly()
          If true, this TransactionPolicy will ultimately end with rollback.
 boolean isTransactionActive()
          Is there a actual transaction active?
 void putResource(Object key, Object value)
          Associates the specified resource with the specified key.
 void registerSynchronization(TransactionPolicy.TransactionSynchronization synchronization)
          Registers a listener for transaction synchronization events.
 Object removeResource(Object key)
          Removes and returns the resource associated with the specified key.
 void setRollbackOnly()
          Sets this TransactionPolicy to rollback when completed
 

Method Detail

getTransactionType

TransactionType getTransactionType()
Gets the TransactionType for this policy.

Returns:
the TransactionType for this policy

isNewTransaction

boolean isNewTransaction()
Is this a new transaction and not an inhreited transaction or no transaction? Some TransactionTypes, such as Required or Supported, use the caller's transaction instead of starting a new transaction. If there is no active transaction (e.g., TransactionType is NotSupported), this method will

Returns:
true if this not an inherited transaction

isClientTransaction

boolean isClientTransaction()
Is this policy running in an inhreited transaction? Some TransactionTypes, such as Required or Supported, use the caller's transaction instead of starting a new transaction. If there is no active transaction (e.g., TransactionType is NotSupported), this method will return false.

Returns:
true if this is an inherited transaction

isTransactionActive

boolean isTransactionActive()
Is there a actual transaction active?

Returns:
true if there is an actual transaction active

isRollbackOnly

boolean isRollbackOnly()
If true, this TransactionPolicy will ultimately end with rollback.

Returns:
true if this TransactionPolicy will ultimately end with rollback

setRollbackOnly

void setRollbackOnly()
Sets this TransactionPolicy to rollback when completed


commit

void commit()
            throws ApplicationException,
                   SystemException
Commits or rolls back this TransactionPolicy. If there the actual transaction is completed or there is no actual transaction, the registered TransactionSynchronization are called. Otherwise, the registered TransactionSynchronization are called when the actual transaction is completed.

Throws:
ApplicationException - if recoverable exception is encountered
SystemException - if an unrecoverable exception is encountered

getResource

Object getResource(Object key)
Gets a resource associated with the specified key. If there is an actual transaction active, the resource associated with the transaction is returned; otherwise the resource is scoped to this TransactionPolicy.

Parameters:
key - the resource key
Returns:
the resource or null if no resource was associated with the key

putResource

void putResource(Object key,
                 Object value)
Associates the specified resource with the specified key. If there is an actual transaction active, the resource associated with the transaction is set; otherwise the resource is scoped to this TransactionPolicy.

Parameters:
key - the resource key
value - the resource

removeResource

Object removeResource(Object key)
Removes and returns the resource associated with the specified key. If there is an actual transaction active, the resource associated with the transaction is returned; otherwise the resource is scoped to this TransactionPolicy.

Parameters:
key - the resource key
Returns:
the resource previously associated with the key

registerSynchronization

void registerSynchronization(TransactionPolicy.TransactionSynchronization synchronization)
Registers a listener for transaction synchronization events. If there is an actual transaction active, the events are fired when the acutal transaction is commited; otherwise the events are fired when this TransactionPolicy completes.

Parameters:
synchronization - the transaction synchronization listener

enlistResource

void enlistResource(XAResource xaResource)
                    throws SystemException
Enlists a XAResource in the actual active transaction. This only works if the TransactionPolicy is associated with an actual transaction and the TransactionPolicy supports XAResouce enlistment.

Parameters:
xaResource - the XAResource to enlist
Throws:
SystemException - if the xaResource could not be enlisted in the transaction


Copyright © 1999-2013 The Apache OpenEJB development community. All Rights Reserved.