org.springframework.transaction.jta.JtaTransactionManager .
This base class provides the following workflow handling:
Subclasses have to implement specific template methods for specific states of a transaction, e.g.: begin, suspend, resume, commit, rollback. The most important of them are abstract and must be provided by a concrete implementation; for the rest, defaults are provided, so overriding is optional.
Transaction synchronization is a generic mechanism for registering callbacks that get invoked at transaction completion time. This is mainly used internally by the data access support classes for JDBC, Hibernate, JPA, etc when running within a JTA transaction: They register resources that are opened within the transaction for closing at transaction completion time, allowing e.g. for reuse of the same Hibernate Session within the transaction. The same mechanism can also be leveraged for custom synchronization needs in an application.
The state of this class is serializable, to allow for serializing the
transaction strategy along with proxies that carry a transaction interceptor.
It is up to subclasses if they wish to make their state to be serializable too.
They should implement the java.io.Serializable marker interface in
that case, and potentially a private readObject() method (according
to Java serialization rules) if they need to restore any transient state.
setTransactionSynchronization, TransactionSynchronizationManager, org.springframework.transaction.jta.JtaTransactionManager
| Modifier and Type | Class and Description |
|---|---|
| protected static class | AbstractPlatformTransactionManager.SuspendedResourcesHolder
Holder for suspended resources. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Map | constants
Map of constant names to constant values for the transaction synchronization constants defined in this class. |
| private int | |
| private boolean | |
| private boolean | |
| protected transient Log | |
| private boolean | |
| private boolean | |
| public static final int | SYNCHRONIZATION_ALWAYS
Always activate transaction synchronization, even for "empty" transactions that result from PROPAGATION_SUPPORTS with no existing backend transaction. |
| public static final int | SYNCHRONIZATION_NEVER
Never active transaction synchronization, not even for actual transactions. |
| public static final int | SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
Activate transaction synchronization only for actual transactions, that is, not for empty ones that result from PROPAGATION_SUPPORTS with no existing backend transaction. |
| private Collection | |
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | cleanupAfterCompletion(DefaultTransactionStatus
object representing the transaction status)Clean up after completion, clearing synchronization if necessary, and invoking doCleanupAfterCompletion. |
| public final void | commit(TransactionStatus
object returned by the status)getTransaction methodImplements org. |
| protected int | Returns: the actual timeout to usethe transaction definition definition)Determine the actual timeout to use for the given definition. |
| protected abstract void | doBegin(Object
the transaction object returned by transaction, TransactionDefinition doGetTransactiona TransactionDefinition instance, describing propagation
behavior, isolation level, read-only flag, timeout, and transaction name definition)Begin a new transaction with semantics according to the given transaction definition. |
| protected void | doCleanupAfterCompletion(Object
the transaction object returned by transaction)doGetTransactionCleanup resources after transaction completion. |
| protected abstract void | doCommit(DefaultTransactionStatus
the status representation of the transaction status)Perform an actual commit of the given transaction. |
| protected abstract Object | Returns: the current transaction objectReturn a transaction object for the current transaction state. |
| protected void | |
| private void | doResumeSynchronization(List<TransactionSynchronization>
a List of TransactionSynchronization objects suspendedSynchronizations)Reactivate transaction synchronization for the current thread and resume all given synchronizations. |
| protected abstract void | doRollback(DefaultTransactionStatus
the status representation of the transaction status)Perform an actual rollback of the given transaction. |
| private void | doRollbackOnCommitException(DefaultTransactionStatus
object representing the transaction status, Throwable the thrown application exception or error ex)Invoke |
| protected void | doSetRollbackOnly(DefaultTransactionStatus
the status representation of the transaction status)Set the given transaction rollback-only. |
| protected Object | |
| private List | Returns: the List of suspended TransactionSynchronization objectsSuspend all current synchronizations and deactivate transaction synchronization for the current thread. |
| public final int | getDefaultTimeout()
Return the default timeout that this transaction manager should apply if there is no timeout specified at the transaction level, in seconds. |
| public final TransactionStatus | getTransaction(TransactionDefinition
the TransactionDefinition instance (can be definition)null for defaults),
describing propagation behavior, isolation level, timeout etc.Implements org. |
| public final Collection | getTransactionExecutionListeners()
Implements org. |
| public final int | getTransactionSynchronization()
Return if this transaction manager should activate the thread-bound transaction synchronization support. |
| private TransactionStatus | handleExistingTransaction(TransactionDefinition definition, Object transaction, boolean debugEnabled)
Create a TransactionStatus for an existing transaction. |
| protected final void | invokeAfterCompletion(List<TransactionSynchronization>
a List of TransactionSynchronization objects synchronizations, int the completion status according to the
constants in the TransactionSynchronization interface completionStatus)Actually invoke the |
| protected boolean | Returns: if there is an existing transactionthe transaction object returned by doGetTransaction transaction)Check if the given transaction object indicates an existing transaction (that is, a transaction which has already started). |
| public final boolean | isFailEarlyOnGlobalRollbackOnly()
Return whether to fail early in case of the transaction being globally marked as rollback-only. |
| public final boolean | isGlobalRollbackOnParticipationFailure()
Return whether to globally mark an existing transaction as rollback-only after a participating transaction failed. |
| public final boolean | |
| public final boolean | isRollbackOnCommitFailure()
Return whether |
| public final boolean | isValidateExistingTransaction()
Return whether existing transactions should be validated before participating in them. |
| private DefaultTransactionStatus | newTransactionStatus(TransactionDefinition definition, Object transaction, boolean newTransaction, boolean newSynchronization, boolean nested, boolean debug, Object suspendedResources)
Create a TransactionStatus instance for the given arguments. |
| protected void | prepareForCommit(DefaultTransactionStatus
the status representation of the transaction status)Make preparations for commit, to be performed before the
|
| protected void | prepareSynchronization(DefaultTransactionStatus status, TransactionDefinition definition)
Initialize transaction synchronization as appropriate. |
| private DefaultTransactionStatus | prepareTransactionStatus(TransactionDefinition definition, Object transaction, boolean newTransaction, boolean newSynchronization, boolean debug, Object suspendedResources)
Create a new TransactionStatus for the given arguments, also initializing transaction synchronization as appropriate. |
| private void | processCommit(DefaultTransactionStatus
object representing the transaction status)Process an actual commit. |
| private void | processRollback(DefaultTransactionStatus
object representing the transaction status, boolean unexpected)Process an actual rollback. |
| private void | |
| protected void | registerAfterCompletionWithExistingTransaction(Object
the transaction object returned by transaction, List<TransactionSynchronization> doGetTransactiona List of TransactionSynchronization objects synchronizations)Register the given list of transaction synchronizations with the existing transaction. |
| protected final void | resume(Object
the current transaction object transaction, AbstractPlatformTransactionManager.the object that holds suspended resources,
as returned by resourcesHoldersuspend (or null to just
resume synchronizations, if any)Resume the given transaction. |
| private void | resumeAfterBeginException(Object transaction, AbstractPlatformTransactionManager.
Resume outer transaction after inner transaction begin failed. |
| public final void | rollback(TransactionStatus
object returned by the status)getTransaction methodImplements org. |
| public final void | setDefaultTimeout(int defaultTimeout)
Specify the default timeout that this transaction manager should apply if there is no timeout specified at the transaction level, in seconds. |
| public final void | setFailEarlyOnGlobalRollbackOnly(boolean failEarlyOnGlobalRollbackOnly)
Set whether to fail early in case of the transaction being globally marked as rollback-only. |
| public final void | setGlobalRollbackOnParticipationFailure(boolean globalRollbackOnParticipationFailure)
Set whether to globally mark an existing transaction as rollback-only after a participating transaction failed. |
| public final void | setNestedTransactionAllowed(boolean nestedTransactionAllowed)
Set whether nested transactions are allowed. |
| public final void | setRollbackOnCommitFailure(boolean rollbackOnCommitFailure)
Set whether |
| public final void | setTransactionExecutionListeners(Collection<TransactionExecutionListener> listeners)
Implements org. |
| public final void | setTransactionSynchronization(int transactionSynchronization)
Set when this transaction manager should activate the thread-bound transaction synchronization support. |
| public final void | setTransactionSynchronizationName(String
name of the constant constantName)Set the transaction synchronization by the name of the corresponding constant
in this class — for example, |
| public final void | setValidateExistingTransaction(boolean validateExistingTransaction)
Set whether existing transactions should be validated before participating in them. |
| protected boolean | shouldCommitOnGlobalRollbackOnly()
Return whether to call |
| private TransactionStatus | startTransaction(TransactionDefinition definition, Object transaction, boolean nested, boolean debugEnabled, AbstractPlatformTransactionManager.
Start a new transaction. |
| protected final AbstractPlatformTransactionManager. | |
| private void | triggerAfterCommit(DefaultTransactionStatus
object representing the transaction status)Trigger |
| private void | triggerAfterCompletion(DefaultTransactionStatus
object representing the transaction status, int completion status according to TransactionSynchronization constants completionStatus)Trigger |
| protected final void | triggerBeforeCommit(DefaultTransactionStatus
object representing the transaction status)Trigger |
| protected final void | triggerBeforeCompletion(DefaultTransactionStatus
object representing the transaction status)Trigger |
| protected boolean |