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  int totalTransactions
           
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.
protected  boolean checkValidTxContext(JtxTransaction currentTx, java.lang.Object destContext)
          Returns true if context is specified and it is different then of existing transaction.
 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, java.lang.Object context)
          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 isAssociatedWithThread(JtxTransaction tx)
          Returns true if provided transaction is associated with current thread.
 boolean isSingleResourceManager()
          Returns true if this transaction manager works with just one resource.
 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(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: MANDATORY None -> Error T1 -> T1 (cont.)
protected  JtxTransaction propNever(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: NEVER None -> None T1 -> Error
protected  JtxTransaction propNotSupported(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: NOT_SUPPORTED None -> None T1 -> None
protected  JtxTransaction propRequired(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: REQUIRED None -> T2 T1 -> T1 (cont.)
protected  JtxTransaction propRequiresNew(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: REQUIRES_NEW None -> T2 T1 -> T2
protected  JtxTransaction propSupports(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object context)
          Propagation: SUPPORTS 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)
           
 JtxTransaction requestTransaction(JtxTransactionMode mode, java.lang.Object context)
          Requests transaction with specified mode.
 void setMaxResourcesPerTransaction(int maxResourcesPerTransaction)
          Sets max number of resources per transaction.
 void setSingleResourceManager(boolean oneResourceManager)
          Specifies if transaction manager works with just one resource.
 void setValidateExistingTransaction(boolean validateExistingTransaction)
          Sets whether existing transactions should be validated before participating in them.
 int totalActiveThreadTransactions()
          Returns total number of active transactions associated with current thread.
 int totalThreadTransactions()
          Returns total number of transactions associated with current thread.
 int totalThreadTransactionsWithStatus(JtxStatus status)
          Returns total number of transactions of the specified status associated with current thread.
 int totalTransactions()
          Returns total number of transactions issued by this transaction manager.
 
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

totalTransactions

protected int totalTransactions
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()
Returns true if this transaction manager works with just one resource.


setSingleResourceManager

public void setSingleResourceManager(boolean oneResourceManager)
Specifies if transaction manager works with just one resource.


totalThreadTransactions

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


totalThreadTransactionsWithStatus

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


totalActiveThreadTransactions

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


isAssociatedWithThread

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


removeTransaction

protected boolean removeTransaction(JtxTransaction tx)
Removes transaction association with current thread. Transaction should be properly handled (committed or rolledback) before removing from 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.


totalTransactions

public int totalTransactions()
Returns total number of transactions issued by this transaction manager.


createNewTransaction

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


requestTransaction

public JtxTransaction requestTransaction(JtxTransactionMode mode)

requestTransaction

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


checkValidTxContext

protected boolean checkValidTxContext(JtxTransaction currentTx,
                                      java.lang.Object destContext)
Returns true if context is specified and it is different then of existing transaction.


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(JtxTransaction currentTx,
                                      JtxTransactionMode mode,
                                      java.lang.Object context)
Propagation: REQUIRED
 None -> T2
 T1   -> T1 (cont.)
 


propRequiresNew

protected JtxTransaction propRequiresNew(JtxTransaction currentTx,
                                         JtxTransactionMode mode,
                                         java.lang.Object context)
Propagation: REQUIRES_NEW
 None -> T2
 T1   -> T2
 


propSupports

protected JtxTransaction propSupports(JtxTransaction currentTx,
                                      JtxTransactionMode mode,
                                      java.lang.Object context)
Propagation: SUPPORTS
 None -> None
 T1   -> T1 (cont.)
 


propMandatory

protected JtxTransaction propMandatory(JtxTransaction currentTx,
                                       JtxTransactionMode mode,
                                       java.lang.Object context)
Propagation: MANDATORY
 None -> Error
 T1   -> T1 (cont.)
 


propNotSupported

protected JtxTransaction propNotSupported(JtxTransaction currentTx,
                                          JtxTransactionMode mode,
                                          java.lang.Object context)
Propagation: NOT_SUPPORTED
 None -> None
 T1   -> None
 


propNever

protected JtxTransaction propNever(JtxTransaction currentTx,
                                   JtxTransactionMode mode,
                                   java.lang.Object context)
Propagation: NEVER
 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 © 2003-2011 Jodd Team