Class DefaultTransactionStatus
- java.lang.Object
- org.springframework.transaction.support.AbstractTransactionStatus
- org.springframework.transaction.support.DefaultTransactionStatus
- All Implemented Interfaces:
Flushable
,SavepointManager
,TransactionExecution
,TransactionStatus
public class DefaultTransactionStatus extends AbstractTransactionStatus
Default implementation of theTransactionStatus
interface, used byAbstractPlatformTransactionManager
. 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 plainTransactionStatus
interface instead.- Since:
- 19.01.2004
- Author:
- Juergen Hoeller
- See Also:
AbstractPlatformTransactionManager
,SavepointManager
,getTransaction()
,AbstractTransactionStatus.createSavepoint()
,AbstractTransactionStatus.rollbackToSavepoint(java.lang.Object)
,AbstractTransactionStatus.releaseSavepoint(java.lang.Object)
,SimpleTransactionStatus
Constructor Summary
Constructors Constructor Description DefaultTransactionStatus(Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, Object suspendedResources)
Create a newDefaultTransactionStatus
instance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flush()
Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObject
interface.protected SavepointManager
getSavepointManager()
This implementation exposes theSavepointManager
interface of the underlying transaction object, if any.Object
getSuspendedResources()
Return the holder for resources that have been suspended for this transaction, if any.Object
getTransaction()
Return the underlying transaction object.boolean
hasTransaction()
Return whether there is an actual transaction active.boolean
isDebug()
Return whether the progress of this transaction is debugged.boolean
isGlobalRollbackOnly()
Determine the rollback-only flag via checking the transaction object, provided that the latter implements theSmartTransactionObject
interface.boolean
isNewSynchronization()
Return if a new transaction synchronization has been opened for this transaction.boolean
isNewTransaction()
Return whether the present transaction is new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.boolean
isReadOnly()
Return if this transaction is defined as read-only transaction.boolean
isTransactionSavepointManager()
Return whether the underlying transaction implements theSavepointManager
interface 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 Detail
DefaultTransactionStatus
public DefaultTransactionStatus(@Nullable Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, @Nullable Object suspendedResources)
Create a newDefaultTransactionStatus
instance.- Parameters:
transaction
- 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
Method Detail
getTransaction
public Object getTransaction()
Return the underlying transaction object.- Throws:
IllegalStateException
- if no transaction is active
hasTransaction
public boolean hasTransaction()
Return whether there is an actual transaction active.
isNewTransaction
public boolean isNewTransaction()
Description copied from interface:TransactionExecution
Return whether the present transaction is new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.
isNewSynchronization
public boolean isNewSynchronization()
Return if a new transaction synchronization has been opened for this transaction.
isReadOnly
public boolean isReadOnly()
Return if this transaction is defined as read-only transaction.
isDebug
public boolean isDebug()
Return whether the progress of this transaction is debugged. This is used byAbstractPlatformTransactionManager
as an optimization, to prevent repeated calls tologger.isDebugEnabled()
. Not really intended for client code.
getSuspendedResources
@Nullable public Object 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 theSmartTransactionObject
interface.Will return
true
if the global transaction itself has been marked rollback-only by the transaction coordinator, for example in case of a timeout.- Overrides:
isGlobalRollbackOnly
in classAbstractTransactionStatus
- See Also:
SmartTransactionObject.isRollbackOnly()
getSavepointManager
protected SavepointManager getSavepointManager()
This implementation exposes theSavepointManager
interface of the underlying transaction object, if any.- Overrides:
getSavepointManager
in classAbstractTransactionStatus
- Throws:
NestedTransactionNotSupportedException
- if savepoints are not supported- See Also:
isTransactionSavepointManager()
isTransactionSavepointManager
public boolean isTransactionSavepointManager()
Return whether the underlying transaction implements theSavepointManager
interface and therefore supports savepoints.- See Also:
getTransaction()
,getSavepointManager()
flush
public void flush()
Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObject
interface.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceTransactionStatus
- Overrides:
flush
in classAbstractTransactionStatus
- See Also:
SmartTransactionObject.flush()