Top Description Fields Constructors Methods
org.springframework.transaction.support

public Class DefaultTransactionStatus

extends AbstractTransactionStatus
Class Inheritance
Imports
org.springframework.lang.Nullable, org.springframework.transaction.NestedTransactionNotSupportedException, .SavepointManager, org.springframework.util.Assert

Default implementation of the org.springframework.transaction.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 org.springframework.transaction.TransactionStatus interface instead.

Author
Juergen Hoeller
Since
19.01.2004
See Also
AbstractPlatformTransactionManager, org.springframework.transaction.SavepointManager, getTransaction, createSavepoint, rollbackToSavepoint, releaseSavepoint, SimpleTransactionStatus

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private final boolean
private final boolean
private final boolean
private final Object
private final Object
private final String

Constructor Summary

AccessConstructor and Description
public
DefaultTransactionStatus(String
the defined name of the transaction
transactionName
,
Object
underlying transaction object that can hold state for the internal transaction implementation
transaction
,
boolean
if the transaction is new, otherwise participating in an existing transaction
newTransaction
,
boolean
if a new transaction synchronization has been opened for the given transaction
newSynchronization
,
boolean nested, boolean
whether the transaction is marked as read-only
readOnly
,
boolean
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.
debug
,
Object
a holder for resources that have been suspended for this transaction, if any
suspendedResources
)

Create a new DefaultTransactionStatus instance.

public
DefaultTransactionStatus(Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, Object suspendedResources)
Deprecated for removal since 6.1.

Method Summary

Modifier and TypeMethod and Description
public void
flush()

Overrides default org.springframework.transaction.TransactionStatus.flush.

Delegate the flushing to the transaction object, provided that the latter implements the SmartTransactionObject interface.

protected SavepointManager
getSavepointManager()

Overrides org.springframework.transaction.support.AbstractTransactionStatus.getSavepointManager.

This implementation exposes the SavepointManager interface of the underlying transaction object, if any.

public Object
getSuspendedResources()

Return the holder for resources that have been suspended for this transaction, if any.

public Object
getTransaction()

Return the underlying transaction object.

public String
getTransactionName()

Overrides default org.springframework.transaction.TransactionExecution.getTransactionName.

Return the defined name of the transaction (possibly an empty String).

public boolean
hasTransaction()

Overrides default org.springframework.transaction.TransactionExecution.hasTransaction.

Return whether there is an actual transaction active: this is meant to cover a new transaction as well as participation in an existing transaction, only returning false when not running in an actual transaction at all.

public boolean
isDebug()

Return whether the progress of this transaction is debugged.

public boolean
isGlobalRollbackOnly()

Overrides org.springframework.transaction.support.AbstractTransactionStatus.isGlobalRollbackOnly.

Determine the rollback-only flag via checking the transaction object, provided that the latter implements the SmartTransactionObject interface.

public boolean
isNested()

Overrides default org.springframework.transaction.TransactionExecution.isNested.

Return if this transaction executes in a nested fashion within another.

public boolean
isNewSynchronization()

Return if a new transaction synchronization has been opened for this transaction.

public boolean
isNewTransaction()

Overrides default org.springframework.transaction.TransactionExecution.isNewTransaction.

Return 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.

public boolean
isReadOnly()

Overrides default org.springframework.transaction.TransactionExecution.isReadOnly.

Return if this transaction is defined as read-only transaction.

public boolean
isTransactionSavepointManager()

Return whether the underlying transaction implements the SavepointManager interface and therefore supports savepoints.

Inherited from org.springframework.transaction.support.AbstractTransactionStatus:
createAndHoldSavepointcreateSavepointgetSavepointhasSavepointisCompletedisLocalRollbackOnlyisRollbackOnlyreleaseHeldSavepointreleaseSavepointrollbackToHeldSavepointrollbackToSavepointsetCompletedsetRollbackOnlysetSavepoint

Field Detail

debugback to summary
private final boolean debug
nestedback to summary
private final boolean nested
newSynchronizationback to summary
private final boolean newSynchronization
newTransactionback to summary
private final boolean newTransaction
readOnlyback to summary
private final boolean readOnly
suspendedResourcesback to summary
private final Object suspendedResources
Annotations
@Nullable
transactionback to summary
private final Object transaction
Annotations
@Nullable
transactionNameback to summary
private final String transactionName
Annotations
@Nullable

Constructor Detail

DefaultTransactionStatusback to summary
public DefaultTransactionStatus(String transactionName, Object transaction, boolean newTransaction, boolean newSynchronization, boolean nested, boolean readOnly, boolean debug, Object suspendedResources)

Create a new DefaultTransactionStatus instance.

Parameters
transactionName:String

the defined name of the transaction

transaction:Object

underlying transaction object that can hold state for the internal transaction implementation

newTransaction:boolean

if the transaction is new, otherwise participating in an existing transaction

newSynchronization:boolean

if a new transaction synchronization has been opened for the given transaction

readOnly:boolean

whether the transaction is marked as read-only

debug:boolean

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:Object

a holder for resources that have been suspended for this transaction, if any

Since
6.1
DefaultTransactionStatusback to summary
public DefaultTransactionStatus(Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, Object suspendedResources)

Deprecated

for removal since 6.1.

Annotations
@Deprecated
since:6.1
forRemoval:true

Method Detail

flushback to summary
public void flush()

Overrides default org.springframework.transaction.TransactionStatus.flush.

Delegate the flushing to the transaction object, provided that the latter implements the SmartTransactionObject interface.

Annotations
@Override
See Also
SmartTransactionObject#flush()
getSavepointManagerback to summary
protected SavepointManager getSavepointManager()

Overrides org.springframework.transaction.support.AbstractTransactionStatus.getSavepointManager.

This implementation exposes the SavepointManager interface of the underlying transaction object, if any.

Annotations
@Override
Exceptions
NestedTransactionNotSupportedException:
if savepoints are not supported
See Also
isTransactionSavepointManager()
getSuspendedResourcesback to summary
public Object getSuspendedResources()

Return the holder for resources that have been suspended for this transaction, if any.

Annotations
@Nullable
getTransactionback to summary
public Object getTransaction()

Return the underlying transaction object.

Exceptions
IllegalStateException:
if no transaction is active
getTransactionNameback to summary
public String getTransactionName()

Overrides default org.springframework.transaction.TransactionExecution.getTransactionName.

Doc from org.springframework.transaction.TransactionExecution.getTransactionName.

Return 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.

Annotations
@Override
hasTransactionback to summary
public boolean hasTransaction()

Overrides default org.springframework.transaction.TransactionExecution.hasTransaction.

Doc from org.springframework.transaction.TransactionExecution.hasTransaction.

Return whether there is an actual transaction active: this is meant to cover a new transaction as well as participation in an existing transaction, only returning false when not running in an actual transaction at all.

The default implementation returns true.

Annotations
@Override
isDebugback to summary
public boolean isDebug()

Return whether the progress of this transaction is debugged. This is used by AbstractPlatformTransactionManager as an optimization, to prevent repeated calls to logger.isDebugEnabled(). Not really intended for client code.

isGlobalRollbackOnlyback to summary
public boolean isGlobalRollbackOnly()

Overrides org.springframework.transaction.support.AbstractTransactionStatus.isGlobalRollbackOnly.

Determine the rollback-only flag via checking the transaction object, provided that the latter implements the SmartTransactionObject 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.

Annotations
@Override
See Also
SmartTransactionObject#isRollbackOnly()
isNestedback to summary
public boolean isNested()

Overrides default org.springframework.transaction.TransactionExecution.isNested.

Doc from org.springframework.transaction.TransactionExecution.isNested.

Return if this transaction executes in a nested fashion within another.

The default implementation returns false.

Annotations
@Override
isNewSynchronizationback to summary
public boolean isNewSynchronization()

Return if a new transaction synchronization has been opened for this transaction.

isNewTransactionback to summary
public boolean isNewTransaction()

Overrides default org.springframework.transaction.TransactionExecution.isNewTransaction.

Doc from org.springframework.transaction.TransactionExecution.isNewTransaction.

Return 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 hasTransaction() for application purposes since this is usually semantically appropriate.

The "new" status can be transaction manager specific, e.g. returning true for an actual nested transaction but potentially false for a savepoint-based nested transaction scope if the savepoint management is explicitly exposed (such as on TransactionStatus). A combined check for any kind of nested execution is provided by isNested().

The default implementation returns true.

Annotations
@Override
isReadOnlyback to summary
public boolean isReadOnly()

Overrides default org.springframework.transaction.TransactionExecution.isReadOnly.

Doc from org.springframework.transaction.TransactionExecution.isReadOnly.

Return if this transaction is defined as read-only transaction.

The default implementation returns false.

Annotations
@Override
isTransactionSavepointManagerback to summary
public boolean isTransactionSavepointManager()

Return whether the underlying transaction implements the SavepointManager interface and therefore supports savepoints.

See Also
getTransaction(), getSavepointManager()