Class DefaultTransactionStatus
- All Implemented Interfaces:
Flushable,SavepointManager,TransactionExecution,TransactionStatus
TransactionStatus
interface, used by AbstractPlatformTransactionManager. Based on the concept
of an underlying "transaction object".
Holds all status information that AbstractPlatformTransactionManager
needs internally, including a generic transaction object determined by the
concrete transaction manager implementation.
Supports delegating savepoint-related methods to a transaction object
that implements the SavepointManager interface.
NOTE: This is not intended for use with other PlatformTransactionManager
implementations, in particular not for mock transaction managers in testing environments.
Use the alternative SimpleTransactionStatus class or a mock for the plain
TransactionStatus interface instead.
- Since:
- 19.01.2004
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObjectinterface.protected SavepointManagerThis implementation exposes theSavepointManagerinterface of the underlying transaction object, if any.Return the holder for resources that have been suspended for this transaction, if any.Return the underlying transaction object.Return the defined name of the transaction (possibly an empty String).booleanReturn whether there is an actual transaction active: this is meant to cover a new transaction as well as participation in an existing transaction, only returningfalsewhen not running in an actual transaction at all.booleanisDebug()Return whether the progress of this transaction is debugged.booleanDetermine the rollback-only flag via checking the transaction object, provided that the latter implements theSmartTransactionObjectinterface.booleanisNested()Return if this transaction executes in a nested fashion within another.booleanReturn if a new transaction synchronization has been opened for this transaction.booleanReturn whether the transaction manager considers the present transaction as new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.booleanReturn if this transaction is defined as read-only transaction.booleanReturn whether the underlying transaction implements theSavepointManagerinterface and therefore supports savepoints.Methods inherited from class org.springframework.transaction.support.AbstractTransactionStatus
createAndHoldSavepoint, createSavepoint, getSavepoint, hasSavepoint, isCompleted, isLocalRollbackOnly, isRollbackOnly, releaseHeldSavepoint, releaseSavepoint, rollbackToHeldSavepoint, rollbackToSavepoint, setCompleted, setRollbackOnly, setSavepoint
-
Constructor Details
-
DefaultTransactionStatus
public DefaultTransactionStatus(@Nullable String transactionName, @Nullable Object transaction, boolean newTransaction, boolean newSynchronization, boolean nested, boolean readOnly, boolean debug, @Nullable Object suspendedResources) Create a newDefaultTransactionStatusinstance.- Parameters:
transactionName- the defined name of the transactiontransaction- underlying transaction object that can hold state for the internal transaction implementationnewTransaction- if the transaction is new, otherwise participating in an existing transactionnewSynchronization- if a new transaction synchronization has been opened for the given transactionreadOnly- whether the transaction is marked as read-onlydebug- should debug logging be enabled for the handling of this transaction? Caching it in here can prevent repeated calls to ask the logging system whether debug logging should be enabled.suspendedResources- a holder for resources that have been suspended for this transaction, if any- Since:
- 6.1
-
-
Method Details
-
getTransactionName
Description copied from interface:TransactionExecutionReturn the defined name of the transaction (possibly an empty String).In case of Spring's declarative transactions, the exposed name will be the
fully-qualified class name + "." + method name(by default).The default implementation returns an empty String.
- See Also:
-
getTransaction
Return the underlying transaction object.- Throws:
IllegalStateException- if no transaction is active
-
hasTransaction
public boolean hasTransaction()Description copied from interface:TransactionExecutionReturn whether there is an actual transaction active: this is meant to cover a new transaction as well as participation in an existing transaction, only returningfalsewhen not running in an actual transaction at all.The default implementation returns
true. -
isNewTransaction
public boolean isNewTransaction()Description copied from interface:TransactionExecutionReturn whether the transaction manager considers the present transaction as new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.This is primarily here for transaction manager state handling. Prefer the use of
TransactionExecution.hasTransaction()for application purposes since this is usually semantically appropriate.The "new" status can be transaction manager specific, for example, returning
truefor an actual nested transaction but potentiallyfalsefor a savepoint-based nested transaction scope if the savepoint management is explicitly exposed (such as onTransactionStatus). A combined check for any kind of nested execution is provided byTransactionExecution.isNested().The default implementation returns
true. -
isNewSynchronization
public boolean isNewSynchronization()Return if a new transaction synchronization has been opened for this transaction. -
isNested
public boolean isNested()Description copied from interface:TransactionExecutionReturn if this transaction executes in a nested fashion within another.The default implementation returns
false. -
isReadOnly
public boolean isReadOnly()Description copied from interface:TransactionExecutionReturn if this transaction is defined as read-only transaction.The default implementation returns
false.- See Also:
-
isDebug
public boolean isDebug()Return whether the progress of this transaction is debugged. This is used byAbstractPlatformTransactionManageras an optimization, to prevent repeated calls tologger.isDebugEnabled(). Not really intended for client code. -
getSuspendedResources
Return the holder for resources that have been suspended for this transaction, if any. -
isGlobalRollbackOnly
public boolean isGlobalRollbackOnly()Determine the rollback-only flag via checking the transaction object, provided that the latter implements theSmartTransactionObjectinterface.Will return
trueif the global transaction itself has been marked rollback-only by the transaction coordinator, for example in case of a timeout.- Overrides:
isGlobalRollbackOnlyin classAbstractTransactionStatus- See Also:
-
getSavepointManager
This implementation exposes theSavepointManagerinterface of the underlying transaction object, if any.- Overrides:
getSavepointManagerin classAbstractTransactionStatus- Throws:
NestedTransactionNotSupportedException- if savepoints are not supported- See Also:
-
isTransactionSavepointManager
public boolean isTransactionSavepointManager()Return whether the underlying transaction implements theSavepointManagerinterface and therefore supports savepoints.- See Also:
-
flush
public void flush()Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObjectinterface.- See Also:
-