org.springframework.transaction.support
Class DefaultTransactionStatus

java.lang.Object
  extended byorg.springframework.transaction.support.DefaultTransactionStatus
All Implemented Interfaces:
SavepointManager, TransactionStatus

public class DefaultTransactionStatus
extends Object
implements TransactionStatus

Default implementation of the TransactionStatus interface, used by AbstractPlatformTransactionManager.

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.

Since:
19.01.2004
Author:
Juergen Hoeller
See Also:
AbstractPlatformTransactionManager, SavepointManager, createSavepoint(), rollbackToSavepoint(java.lang.Object), releaseSavepoint(java.lang.Object), getTransaction()

Constructor Summary
DefaultTransactionStatus(Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, Object suspendedResources)
          Create a new TransactionStatus instance.
 
Method Summary
 void createAndHoldSavepoint()
          Create a savepoint and hold it for the transaction.
 Object createSavepoint()
          This implementation delegates to the transaction object if it implements the SavepointManager interface.
 Object getSavepoint()
          Get the savepoint for this transaction, if any.
protected  SavepointManager getSavepointManager()
          Return the underlying transaction as SavepointManager, if possible.
 Object getSuspendedResources()
           
 Object getTransaction()
          Return the underlying transaction object, e.g. a JTA UserTransaction.
 boolean hasSavepoint()
          Return whether this transaction carries a savepoint.
 boolean isCompleted()
          Return whether this transaction is completed, that is, committed or rolled back.
 boolean isDebug()
          Return whether the progress of this transaction is debugged.
 boolean isNewSynchronization()
          Return if a new transaction synchronization has been opened for this transaction.
 boolean isNewTransaction()
          Return if the transaction is new, else participating in an existing transaction.
 boolean isReadOnly()
          Return if this transaction is defined as read-only transaction.
 boolean isRollbackOnly()
          Determine the rollbackOnly flag via checking both this TransactionStatus and the transaction object, provided that the latter implements the SmartTransactionObject interface.
 boolean isTransactionSavepointManager()
          Return whether the underlying transaction implements the SavepointManager interface.
 void releaseHeldSavepoint()
          Release the savepoint that is held for the transaction.
 void releaseSavepoint(Object savepoint)
          This implementation delegates to the transaction object if it implements the SavepointManager interface.
 void rollbackToHeldSavepoint()
          Roll back to the savepoint that is held for the transaction.
 void rollbackToSavepoint(Object savepoint)
          This implementation delegates to the transaction object if it implements the SavepointManager interface.
 void setCompleted()
          Mark this transaction as completed, that is, committed or rolled back.
 void setRollbackOnly()
          Set the transaction rollback-only.
protected  void setSavepoint(Object savepoint)
          Set a savepoint for this transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTransactionStatus

public DefaultTransactionStatus(Object transaction,
                                boolean newTransaction,
                                boolean newSynchronization,
                                boolean readOnly,
                                boolean debug,
                                Object suspendedResources)
Create a new TransactionStatus instance.

Parameters:
transaction - underlying transaction object that can hold state for the internal transaction implementation
newTransaction - if the transaction is new, else participating in an existing transaction
newSynchronization - if a new transaction synchronization has been opened for the given transaction
debug - 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.
Method Detail

getTransaction

public Object getTransaction()
Return the underlying transaction object, e.g. a JTA UserTransaction.


isNewTransaction

public boolean isNewTransaction()
Description copied from interface: TransactionStatus
Return if the transaction is new, else participating in an existing transaction.

Specified by:
isNewTransaction in interface TransactionStatus

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 by AbstractPlatformTransactionManager as an optimization, to prevent repeated calls to logger.isDebug(). Not really intended for client code.


getSuspendedResources

public Object getSuspendedResources()

setRollbackOnly

public void setRollbackOnly()
Description copied from interface: TransactionStatus
Set the transaction rollback-only. This instructs the transaction manager that the only possible outcome of the transaction may be a rollback, proceeding with the normal applicaiton workflow though (i.e. no exception).

For transactions managed by TransactionTemplate or TransactionInterceptor. An alternative way to trigger a rollback is throwing an application exception.

Specified by:
setRollbackOnly in interface TransactionStatus
See Also:
TransactionCallback.doInTransaction(org.springframework.transaction.TransactionStatus), TransactionAttribute.rollbackOn(java.lang.Throwable)

isRollbackOnly

public boolean isRollbackOnly()
Determine the rollbackOnly flag via checking both this TransactionStatus and the transaction object, provided that the latter implements the SmartTransactionObject interface.

Specified by:
isRollbackOnly in interface TransactionStatus
See Also:
SmartTransactionObject.isRollbackOnly()

setCompleted

public void setCompleted()
Mark this transaction as completed, that is, committed or rolled back.


isCompleted

public boolean isCompleted()
Return whether this transaction is completed, that is, committed or rolled back.


setSavepoint

protected void setSavepoint(Object savepoint)
Set a savepoint for this transaction. Used for PROPAGATION_NESTED.

See Also:
TransactionDefinition.PROPAGATION_NESTED

getSavepoint

public Object getSavepoint()
Get the savepoint for this transaction, if any.


hasSavepoint

public boolean hasSavepoint()
Return whether this transaction carries a savepoint.


createSavepoint

public Object createSavepoint()
                       throws TransactionException
This implementation delegates to the transaction object if it implements the SavepointManager interface.

Specified by:
createSavepoint in interface SavepointManager
Returns:
a savepoint object, to be passed into rollbackToSavepoint or releaseSavepoint
Throws:
NestedTransactionNotSupportedException - if the underlying transaction does not support savepoints
TransactionException - if the savepoint could not be created, either because the backend does not support it or because the transaction is not in an appropriate state
See Also:
getTransaction(), SavepointManager

rollbackToSavepoint

public void rollbackToSavepoint(Object savepoint)
                         throws TransactionException
This implementation delegates to the transaction object if it implements the SavepointManager interface.

Specified by:
rollbackToSavepoint in interface SavepointManager
Parameters:
savepoint - the savepoint to roll back to
Throws:
TransactionException - if the rollback failed
See Also:
getTransaction(), SavepointManager

releaseSavepoint

public void releaseSavepoint(Object savepoint)
                      throws TransactionException
This implementation delegates to the transaction object if it implements the SavepointManager interface.

Specified by:
releaseSavepoint in interface SavepointManager
Parameters:
savepoint - the savepoint to release
Throws:
TransactionException - if the release failed
See Also:
getTransaction(), SavepointManager

createAndHoldSavepoint

public void createAndHoldSavepoint()
                            throws TransactionException
Create a savepoint and hold it for the transaction.

Throws:
NestedTransactionNotSupportedException - if the underlying transaction does not support savepoints
TransactionException

rollbackToHeldSavepoint

public void rollbackToHeldSavepoint()
                             throws TransactionException
Roll back to the savepoint that is held for the transaction.

Throws:
TransactionException

releaseHeldSavepoint

public void releaseHeldSavepoint()
                          throws TransactionException
Release the savepoint that is held for the transaction.

Throws:
TransactionException

getSavepointManager

protected SavepointManager getSavepointManager()
Return the underlying transaction as SavepointManager, if possible.

Throws:
NestedTransactionNotSupportedException - if the underlying transaction does not support savepoints

isTransactionSavepointManager

public boolean isTransactionSavepointManager()
Return whether the underlying transaction implements the SavepointManager interface.

See Also:
getTransaction(), SavepointManager


Copyright (C) 2003-2004 The Spring Framework Project.