Package org.springframework.transaction.support

# Class AbstractTransactionStatus

java.lang.Object
org.springframework.transaction.support.AbstractTransactionStatus

All Implemented Interfaces:
  `Flushable`, `SavepointManager`, `TransactionExecution`, `TransactionStatus`

Direct Known Subclasses:
  `DefaultTransactionStatus`, `SimpleTransactionStatus`

public abstract class AbstractTransactionStatus extends Object implements TransactionStatus
Abstract base implementation of the `TransactionStatus` interface.

Pre-implements the handling of local rollback-only and completed flags, and delegation to an underlying `SavepointManager`. Also offers the option of a holding a savepoint within the transaction.

Does not assume any specific internal transaction handling, such as an underlying transaction object, and no transaction synchronization mechanism.

Since:
  1.2.3
Author:
  Juergen Hoeller
See Also:
  - `setRollbackOnly()`
  - `isRollbackOnly()`
  - `setCompleted()`
  - `isCompleted()`
  - `getSavepointManager()`
  - `SimpleTransactionStatus`
  - `DefaultTransactionStatus`

## Constructor Summary

Constructors
Constructor
Description
`AbstractTransactionStatus()`

## Method Summary

Modifier and Type
Method
Description
`void`
`createAndHoldSavepoint()`
Create a savepoint and hold it for the transaction.
`Object`
`createSavepoint()`
This implementation delegates to a SavepointManager for the underlying transaction, if possible.
`protected Object`
`getSavepoint()`
Get the savepoint for this transaction, if any.
`protected SavepointManager`
`getSavepointManager()`
Return a SavepointManager for the underlying transaction, if possible.
`boolean`
`hasSavepoint()`
Return whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint.
`boolean`
`isCompleted()`
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.
`boolean`
`isGlobalRollbackOnly()`
Template method for determining the global rollback-only flag of the underlying transaction, if any.
`boolean`
`isLocalRollbackOnly()`
Determine the rollback-only flag via checking this TransactionStatus.
`boolean`
`isRollbackOnly()`
Determine the rollback-only flag via checking both the local rollback-only flag of this TransactionStatus and the global rollback-only flag of the underlying transaction, if any.
`void`
`releaseHeldSavepoint()`
Release the savepoint that is held for the transaction.
`void`
`releaseSavepoint(Object savepoint)`
This implementation delegates to a SavepointManager for the underlying transaction, if possible.
`void`
`rollbackToHeldSavepoint()`
Roll back to the savepoint that is held for the transaction and release the savepoint right afterwards.
`void`
`rollbackToSavepoint(Object savepoint)`
This implementation delegates to a SavepointManager for the underlying transaction, if possible.
`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`

### Methods inherited from interface org.springframework.transaction.TransactionExecution

`getTransactionName, hasTransaction, isNested, isNewTransaction, isReadOnly`

### Methods inherited from interface org.springframework.transaction.TransactionStatus

`flush`

## Constructor Details

### AbstractTransactionStatus

public AbstractTransactionStatus()

## Method Details

### setRollbackOnly

public void setRollbackOnly()
Description copied from interface: `TransactionExecution`
Set the transaction rollback-only. This instructs the transaction manager that the only possible outcome of the transaction may be a rollback, as alternative to throwing an exception which would in turn trigger a rollback.

The default implementation throws an UnsupportedOperationException.

Specified by:
  `setRollbackOnly` in interface `TransactionExecution`
See Also:
  - `TransactionExecution.isRollbackOnly()`

### isRollbackOnly

public boolean isRollbackOnly()
Determine the rollback-only flag via checking both the local rollback-only flag of this TransactionStatus and the global rollback-only flag of the underlying transaction, if any.

Specified by:
  `isRollbackOnly` in interface `TransactionExecution`
See Also:
  - `isLocalRollbackOnly()`
  - `isGlobalRollbackOnly()`

### isLocalRollbackOnly

public boolean isLocalRollbackOnly()
Determine the rollback-only flag via checking this TransactionStatus.

Will only return "true" if the application called `setRollbackOnly` on this TransactionStatus object.

### isGlobalRollbackOnly

public boolean isGlobalRollbackOnly()
Template method for determining the global rollback-only flag of the underlying transaction, if any.

This implementation always returns `false`.

### setCompleted

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

### isCompleted

public boolean isCompleted()
Description copied from interface: `TransactionExecution`
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.

The default implementation returns `false`.

Specified by:
  `isCompleted` in interface `TransactionExecution`

### hasSavepoint

public boolean hasSavepoint()
Description copied from interface: `TransactionStatus`
Return whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint.

This method is mainly here for diagnostic purposes, alongside `TransactionExecution.isNewTransaction()`. For programmatic handling of custom savepoints, use the operations provided by `SavepointManager`.

The default implementation returns `false`.

Specified by:
  `hasSavepoint` in interface `TransactionStatus`
See Also:
  - `TransactionExecution.isNewTransaction()`
  - `SavepointManager.createSavepoint()`
  - `SavepointManager.rollbackToSavepoint(Object)`
  - `SavepointManager.releaseSavepoint(Object)`

### setSavepoint

protected void setSavepoint(@Nullable Object savepoint)
Set a savepoint for this transaction. Useful for PROPAGATION_NESTED.

See Also:
  - `TransactionDefinition.PROPAGATION_NESTED`

### getSavepoint

@Nullable protected Object getSavepoint()
Get the savepoint for this transaction, if any.

### 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`
See Also:
  - `SavepointManager.createSavepoint()`

### rollbackToHeldSavepoint

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

Throws:
  `TransactionException`
See Also:
  - `SavepointManager.rollbackToSavepoint(java.lang.Object)`
  - `SavepointManager.releaseSavepoint(java.lang.Object)`

### releaseHeldSavepoint

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

Throws:
  `TransactionException`
See Also:
  - `SavepointManager.releaseSavepoint(java.lang.Object)`

### createSavepoint

public Object createSavepoint() throws TransactionException
This implementation delegates to a SavepointManager for the underlying transaction, if possible.

Specified by:
  `createSavepoint` in interface `SavepointManager`
Returns:
  a savepoint object, to be passed into `SavepointManager.rollbackToSavepoint(java.lang.Object)` or `SavepointManager.releaseSavepoint(java.lang.Object)`
Throws:
  `NestedTransactionNotSupportedException` - if the underlying transaction does not support savepoints
  `TransactionException` - if the savepoint could not be created, for example because the transaction is not in an appropriate state
See Also:
  - `getSavepointManager()`
  - `SavepointManager.createSavepoint()`

### rollbackToSavepoint

public void rollbackToSavepoint(Object savepoint) throws TransactionException
This implementation delegates to a SavepointManager for the underlying transaction, if possible.

Specified by:
  `rollbackToSavepoint` in interface `SavepointManager`
Parameters:
  `savepoint` - the savepoint to roll back to
Throws:
  `NestedTransactionNotSupportedException` - if the underlying transaction does not support savepoints
  `TransactionException` - if the rollback failed
See Also:
  - `getSavepointManager()`
  - `SavepointManager.rollbackToSavepoint(Object)`

### releaseSavepoint

public void releaseSavepoint(Object savepoint) throws TransactionException
This implementation delegates to a SavepointManager for the underlying transaction, if possible.

Specified by:
  `releaseSavepoint` in interface `SavepointManager`
Parameters:
  `savepoint` - the savepoint to release
Throws:
  `NestedTransactionNotSupportedException` - if the underlying transaction does not support savepoints
  `TransactionException` - if the release failed
See Also:
  - `getSavepointManager()`
  - `SavepointManager.releaseSavepoint(Object)`

### getSavepointManager

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

Default implementation always throws a NestedTransactionNotSupportedException.

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