Package org.springframework.transaction

# Interface TransactionExecution

All Known Subinterfaces:
  `ReactiveTransaction`, `TransactionStatus`

All Known Implementing Classes:
  `AbstractTransactionStatus`, `DefaultTransactionStatus`, `GenericReactiveTransaction`, `SimpleTransactionStatus`

public interface TransactionExecution
Common representation of the current state of a transaction. Serves as base interface for `TransactionStatus` as well as `ReactiveTransaction`, and as of 6.1 also as transaction representation for `TransactionExecutionListener`.

Since:
  5.2
Author:
  Juergen Hoeller

## Method Summary

Modifier and Type
Method
Description
`default String`
`getTransactionName()`
Return the defined name of the transaction (possibly an empty String).
`default boolean`
`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.
`default boolean`
`isCompleted()`
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.
`default boolean`
`isNested()`
Return if this transaction executes in a nested fashion within another.
`default boolean`
`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.
`default boolean`
`isReadOnly()`
Return if this transaction is defined as read-only transaction.
`default boolean`
`isRollbackOnly()`
Return whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).
`default void`
`setRollbackOnly()`
Set the transaction rollback-only.

## Method Details

### getTransactionName

default String 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.

Since:
  6.1
See Also:
  - `TransactionDefinition.getName()`

### hasTransaction

default boolean 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`.

Since:
  6.1
See Also:
  - `isNewTransaction()`
  - `isNested()`
  - `isReadOnly()`

### isNewTransaction

default boolean 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, for example, 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`.

See Also:
  - `hasTransaction()`
  - `isNested()`
  - `TransactionStatus.hasSavepoint()`

### isNested

default boolean isNested()
Return if this transaction executes in a nested fashion within another.

The default implementation returns `false`.

Since:
  6.1
See Also:
  - `hasTransaction()`
  - `isNewTransaction()`
  - `TransactionDefinition.PROPAGATION_NESTED`

### isReadOnly

default boolean isReadOnly()
Return if this transaction is defined as read-only transaction.

The default implementation returns `false`.

Since:
  6.1
See Also:
  - `TransactionDefinition.isReadOnly()`

### setRollbackOnly

default void setRollbackOnly()
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.

See Also:
  - `isRollbackOnly()`

### isRollbackOnly

default boolean isRollbackOnly()
Return whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).

The default implementation returns `false`.

See Also:
  - `setRollbackOnly()`

### isCompleted

default boolean isCompleted()
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.

The default implementation returns `false`.