jodd.jtx
Class JtxTransactionManager

java.lang.Object
  extended by jodd.jtx.JtxTransactionManager
Direct Known Subclasses:
DbJtxTransactionManager

public class JtxTransactionManager
extends java.lang.Object

Simple JtxTransaction manager is responsible for transactions propagation and resource managers. It also holds various configuration data. It can be considered that all work is done global-wide.


Field Summary
protected  int maxResourcesPerTransaction
           
protected  boolean oneResourceManager
           
protected  java.util.Map<java.lang.Class,JtxResourceManager> resourceManagers
           
protected  java.lang.ThreadLocal<java.util.LinkedList<JtxTransaction>> TXSTACK
           
protected  boolean validateExistingTransaction
           
 
Constructor Summary
JtxTransactionManager()
          Creates new transaction manager.
 
Method Summary
protected  void associateTransaction(JtxTransaction tx)
          Associate transaction to current thread.
 void close()
          Closes transaction manager.
protected  void continueTx(JtxTransaction sourceTx, JtxTransactionMode destMode)
          Check if propagation of a transaction is possible, due to source and destination transaction modes.
protected  JtxTransaction createNewTransaction(JtxTransactionMode tm)
          Creates new JtxTransaction instance.
 int getMaxResourcesPerTransaction()
          Returns max number of resources per transaction.
 JtxTransaction getTransaction()
          Returns last transaction associated with current thread or null when thread has no associated transactions created by this transaction manager.
 boolean isAssociated(JtxTransaction tx)
          Returns true if provided transaction is associated with current thread.
 boolean isEmpty()
          Returns true if no transaction is associated with current thread.
 boolean isSingleResourceManager()
           
 boolean isValidateExistingTransaction()
          Returns whether existing transactions should be validated before participating in them.
protected
<E> JtxResourceManager<E>
lookupResourceManager(java.lang.Class<E> resourceType)
          Lookups resource manager for provided type.
protected  JtxTransaction propMandatory(JtxTransactionMode mode)
           None -> Error T1 -> T1 (cont.)
protected  JtxTransaction propNever(JtxTransactionMode mode)
           None -> None T1 -> Error
protected  JtxTransaction propNotSupported(JtxTransactionMode mode)
           None -> None T1 -> None
protected  JtxTransaction propRequired(JtxTransactionMode mode)
           None -> T2 T1 -> T1 (cont.)
protected  JtxTransaction propRequiresNew(JtxTransactionMode mode)
           None -> T2 T1 -> T2
protected  JtxTransaction propSupports(JtxTransactionMode mode)
           None -> None T1 -> T1 (cont.)
 void registerResourceManager(JtxResourceManager resourceManager)
          Registers new resource manager.
protected  boolean removeTransaction(JtxTransaction tx)
          Removes transaction association with current thread.
 JtxTransaction requestTransaction(JtxTransactionMode mode)
          Requests transaction with specified mode.
 void setMaxResourcesPerTransaction(int maxResourcesPerTransaction)
          Sets max number of resources per transaction.
 void setSingleResourceManager(boolean oneResourceManager)
           
 void setValidateExistingTransaction(boolean validateExistingTransaction)
          Sets whether existing transactions should be validated before participating in them.
 int totalActiveTransactions()
          Returns total number of active transactions.
 int totalTransactions()
          Returns total number of transactions associated with current thread.
 int totalTransactionsWithStatus(JtxStatus status)
          Returns total number of transactions of the specified status associated with current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxResourcesPerTransaction

protected int maxResourcesPerTransaction

oneResourceManager

protected boolean oneResourceManager

validateExistingTransaction

protected boolean validateExistingTransaction

resourceManagers

protected java.util.Map<java.lang.Class,JtxResourceManager> resourceManagers

TXSTACK

protected final java.lang.ThreadLocal<java.util.LinkedList<JtxTransaction>> TXSTACK
Constructor Detail

JtxTransactionManager

public JtxTransactionManager()
Creates new transaction manager.

Method Detail

getMaxResourcesPerTransaction

public int getMaxResourcesPerTransaction()
Returns max number of resources per transaction.


setMaxResourcesPerTransaction

public void setMaxResourcesPerTransaction(int maxResourcesPerTransaction)
Sets max number of resources per transaction.


isValidateExistingTransaction

public boolean isValidateExistingTransaction()
Returns whether existing transactions should be validated before participating in them.


setValidateExistingTransaction

public void setValidateExistingTransaction(boolean validateExistingTransaction)
Sets whether existing transactions should be validated before participating in them.

When participating in an existing transaction (e.g. with PROPAGATION_REQUIRES or PROPAGATION_SUPPORTS encountering an existing transaction), this outer transaction's characteristics will apply even to the inner transaction scope. Validation will detect incompatible isolation level and read-only settings on the inner transaction definition and reject participation accordingly through throwing a corresponding exception.


isSingleResourceManager

public boolean isSingleResourceManager()

setSingleResourceManager

public void setSingleResourceManager(boolean oneResourceManager)

isEmpty

public boolean isEmpty()
Returns true if no transaction is associated with current thread.


totalTransactions

public int totalTransactions()
Returns total number of transactions associated with current thread.


totalTransactionsWithStatus

public int totalTransactionsWithStatus(JtxStatus status)
Returns total number of transactions of the specified status associated with current thread.


totalActiveTransactions

public int totalActiveTransactions()
Returns total number of active transactions.


isAssociated

public boolean isAssociated(JtxTransaction tx)
Returns true if provided transaction is associated with current thread.


removeTransaction

protected boolean removeTransaction(JtxTransaction tx)
Removes transaction association with current thread.


getTransaction

public JtxTransaction getTransaction()
Returns last transaction associated with current thread or null when thread has no associated transactions created by this transaction manager.


associateTransaction

protected void associateTransaction(JtxTransaction tx)
Associate transaction to current thread.


createNewTransaction

protected JtxTransaction createNewTransaction(JtxTransactionMode tm)
Creates new JtxTransaction instance. Custom implementations of manager may override this method for creating custom transaction instances.


requestTransaction

public JtxTransaction requestTransaction(JtxTransactionMode mode)
Requests transaction with specified mode. Depending on propagation behavior, it will return either existing or new transaction; or the exception may be thrown indicating propagation mismatch.


continueTx

protected void continueTx(JtxTransaction sourceTx,
                          JtxTransactionMode destMode)
Check if propagation of a transaction is possible, due to source and destination transaction modes.

See Also:
setValidateExistingTransaction(boolean)

propRequired

protected JtxTransaction propRequired(JtxTransactionMode mode)
 None -> T2
 T1   -> T1 (cont.)
 


propRequiresNew

protected JtxTransaction propRequiresNew(JtxTransactionMode mode)
 None -> T2
 T1   -> T2
 


propSupports

protected JtxTransaction propSupports(JtxTransactionMode mode)
 None -> None
 T1   -> T1 (cont.)
 


propMandatory

protected JtxTransaction propMandatory(JtxTransactionMode mode)
 None -> Error
 T1   -> T1 (cont.)
 


propNotSupported

protected JtxTransaction propNotSupported(JtxTransactionMode mode)
 None -> None
 T1   -> None
 


propNever

protected JtxTransaction propNever(JtxTransactionMode mode)
 None -> None
 T1   -> Error
 


registerResourceManager

public void registerResourceManager(JtxResourceManager resourceManager)
Registers new resource manager.


lookupResourceManager

protected <E> JtxResourceManager<E> lookupResourceManager(java.lang.Class<E> resourceType)
Lookups resource manager for provided type. Throws an exception if provider doesn't exists.


close

public void close()
Closes transaction manager. All registered JtxResourceManager will be closed.



Copyright ©2008 Jodd Team