public class JtxTransactionManager
extends java.lang.Object
JtxTransaction
manager is responsible for handling transaction
propagation and resource managers. Holds various JTX configuration data.
Note that transactions are hold inside a thread-local transaction stack. Therefore, if one transaction is created after the other during the same thread, the second transaction will be aware that it is 'after' the first one.
Modifier and Type | Field and Description |
---|---|
protected boolean |
ignoreScope |
protected int |
maxResourcesPerTransaction |
protected boolean |
oneResourceManager |
protected TypeCache<JtxResourceManager> |
resourceManagers |
protected int |
totalTransactions |
protected java.lang.ThreadLocal<java.util.ArrayList<JtxTransaction>> |
txStack |
protected boolean |
validateExistingTransaction |
Constructor and Description |
---|
JtxTransactionManager()
Creates new transaction manager.
|
Modifier and Type | Method and Description |
---|---|
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,
java.lang.Object scope,
boolean active)
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 |
isIgnoreScope()
Returns if transaction scope should be ignored.
|
protected boolean |
isNewTxScope(JtxTransaction currentTx,
java.lang.Object destScope)
Returns
true if scope is specified and it is different then of existing transaction. |
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 scope)
Propagation: MANDATORY
None -> Error
T1 -> T1 (cont.)
|
protected JtxTransaction |
propNever(JtxTransaction currentTx,
JtxTransactionMode mode,
java.lang.Object scope)
Propagation: NEVER
None -> None
T1 -> Error
|
protected JtxTransaction |
propNotSupported(JtxTransaction currentTx,
JtxTransactionMode mode,
java.lang.Object scope)
Propagation: NOT_SUPPORTED
None -> None
T1 -> None
|
protected JtxTransaction |
propRequired(JtxTransaction currentTx,
JtxTransactionMode mode,
java.lang.Object scope)
Propagation: REQUIRED
None -> T2
T1 -> T1 (cont.)
|
protected JtxTransaction |
propRequiresNew(JtxTransaction currentTx,
JtxTransactionMode mode,
java.lang.Object scope)
Propagation: REQUIRES_NEW
None -> T2
T1 -> T2
|
protected JtxTransaction |
propSupports(JtxTransaction currentTx,
JtxTransactionMode mode,
java.lang.Object scope)
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 scope)
Requests transaction with specified
mode . |
void |
setIgnoreScope(boolean ignoreScope)
Sets if transaction scope should be ignored.
|
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.
|
protected int maxResourcesPerTransaction
protected boolean oneResourceManager
protected boolean validateExistingTransaction
protected boolean ignoreScope
protected TypeCache<JtxResourceManager> resourceManagers
protected final java.lang.ThreadLocal<java.util.ArrayList<JtxTransaction>> txStack
protected int totalTransactions
public JtxTransactionManager()
public int getMaxResourcesPerTransaction()
public void setMaxResourcesPerTransaction(int maxResourcesPerTransaction)
public boolean isValidateExistingTransaction()
public void setValidateExistingTransaction(boolean validateExistingTransaction)
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.
public boolean isSingleResourceManager()
true
if this transaction manager works with just one resource.public void setSingleResourceManager(boolean oneResourceManager)
public boolean isIgnoreScope()
public void setIgnoreScope(boolean ignoreScope)
null
public int totalThreadTransactions()
public int totalThreadTransactionsWithStatus(JtxStatus status)
public int totalActiveThreadTransactions()
public boolean isAssociatedWithThread(JtxTransaction tx)
true
if provided transaction
is associated with current thread.protected boolean removeTransaction(JtxTransaction tx)
public JtxTransaction getTransaction()
null
when thread has no associated transactions created
by this transaction manager.protected void associateTransaction(JtxTransaction tx)
public int totalTransactions()
protected JtxTransaction createNewTransaction(JtxTransactionMode tm, java.lang.Object scope, boolean active)
JtxTransaction
instance.
Custom implementations of manager may override this method for
creating custom transaction instances.public JtxTransaction requestTransaction(JtxTransactionMode mode)
public JtxTransaction requestTransaction(JtxTransactionMode mode, java.lang.Object scope)
mode
.
Depending on propagation behavior, it will return either existing or new transaction.
Only one transaction can be opened over one scope.
The exception may be thrown indicating propagation mismatch.protected boolean isNewTxScope(JtxTransaction currentTx, java.lang.Object destScope)
true
if scope is specified and it is different then of existing transaction.protected void continueTx(JtxTransaction sourceTx, JtxTransactionMode destMode)
setValidateExistingTransaction(boolean)
protected JtxTransaction propRequired(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> T2
T1 -> T1 (cont.)
protected JtxTransaction propRequiresNew(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> T2
T1 -> T2
protected JtxTransaction propSupports(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> None
T1 -> T1 (cont.)
protected JtxTransaction propMandatory(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> Error
T1 -> T1 (cont.)
protected JtxTransaction propNotSupported(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> None
T1 -> None
protected JtxTransaction propNever(JtxTransaction currentTx, JtxTransactionMode mode, java.lang.Object scope)
None -> None
T1 -> Error
public void registerResourceManager(JtxResourceManager resourceManager)
resource manager
.protected <E> JtxResourceManager<E> lookupResourceManager(java.lang.Class<E> resourceType)
public void close()
JtxResourceManager
will be closed.Copyright © 2003-present Jodd Team