Package org.springframework.transaction.reactive

# Class GenericReactiveTransaction

java.lang.Object
org.springframework.transaction.reactive.GenericReactiveTransaction

All Implemented Interfaces:
  `ReactiveTransaction`, `TransactionExecution`

public class GenericReactiveTransaction extends Object implements ReactiveTransaction
Default implementation of the `ReactiveTransaction` interface, used by `AbstractReactiveTransactionManager`. Based on the concept of an underlying "transaction object".

Holds all status information that `AbstractReactiveTransactionManager` needs internally, including a generic transaction object determined by the concrete transaction manager implementation.

NOTE: This is not intended for use with other ReactiveTransactionManager implementations, in particular not for mock transaction managers in testing environments.

Since:
  5.2
Author:
  Mark Paluch, Juergen Hoeller
See Also:
  - `AbstractReactiveTransactionManager`
  - `getTransaction()`

## Constructor Summary

Constructors
Constructor
Description
`GenericReactiveTransaction(Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, Object suspendedResources)`
Deprecated, for removal: This API element is subject to removal in a future version.
`GenericReactiveTransaction(String transactionName, Object transaction, boolean newTransaction, boolean newSynchronization, boolean nested, boolean readOnly, boolean debug, Object suspendedResources)`
Create a new `DefaultReactiveTransactionStatus` instance.

## Method Summary

Modifier and Type
Method
Description
`Object`
`getSuspendedResources()`
Return the holder for resources that have been suspended for this transaction, if any.
`Object`
`getTransaction()`
Return the underlying transaction object.
`String`
`getTransactionName()`
Return the defined name of the transaction (possibly an empty String).
`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.
`boolean`
`isCompleted()`
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.
`boolean`
`isDebug()`
Return whether the progress of this transaction is debugged.
`boolean`
`isNested()`
Return if this transaction executes in a nested fashion within another.
`boolean`
`isNewSynchronization()`
Return if a new transaction synchronization has been opened for this transaction.
`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.
`boolean`
`isReadOnly()`
Return if this transaction is defined as read-only transaction.
`boolean`
`isRollbackOnly()`
Determine the rollback-only flag via checking this ReactiveTransactionStatus.
`void`
`setCompleted()`
Mark this transaction as completed, that is, committed or rolled back.
`void`
`setRollbackOnly()`
Set the transaction rollback-only.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### GenericReactiveTransaction

public GenericReactiveTransaction(@Nullable String transactionName, @Nullable Object transaction, boolean newTransaction, boolean newSynchronization, boolean nested, boolean readOnly, boolean debug, @Nullable Object suspendedResources)
Create a new `DefaultReactiveTransactionStatus` instance.

Parameters:
  `transactionName` - the defined name of the transaction
  `transaction` - underlying transaction object that can hold state for the internal transaction implementation
  `newTransaction` - if the transaction is new, otherwise participating in an existing transaction
  `newSynchronization` - if a new transaction synchronization has been opened for the given transaction
  `readOnly` - whether the transaction is marked as read-only
  `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.
  `suspendedResources` - a holder for resources that have been suspended for this transaction, if any
Since:
  6.1

### GenericReactiveTransaction

@Deprecated(since="6.1", forRemoval=true) public GenericReactiveTransaction(@Nullable Object transaction, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, @Nullable Object suspendedResources)
Deprecated, for removal: This API element is subject to removal in a future version.

## Method Details

### getTransactionName

public String getTransactionName()
Description copied from interface: `TransactionExecution`
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.

Specified by:
  `getTransactionName` in interface `TransactionExecution`
See Also:
  - `TransactionDefinition.getName()`

### getTransaction

public Object getTransaction()
Return the underlying transaction object.

Throws:
  `IllegalStateException` - if no transaction is active

### hasTransaction

public boolean hasTransaction()
Description copied from interface: `TransactionExecution`
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`.

Specified by:
  `hasTransaction` in interface `TransactionExecution`
See Also:
  - `TransactionExecution.isNewTransaction()`
  - `TransactionExecution.isNested()`
  - `TransactionExecution.isReadOnly()`

### isNewTransaction

public boolean isNewTransaction()
Description copied from interface: `TransactionExecution`
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 `TransactionExecution.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 `TransactionExecution.isNested()`.

The default implementation returns `true`.

Specified by:
  `isNewTransaction` in interface `TransactionExecution`
See Also:
  - `TransactionExecution.hasTransaction()`
  - `TransactionExecution.isNested()`
  - `TransactionStatus.hasSavepoint()`

### isNewSynchronization

public boolean isNewSynchronization()
Return if a new transaction synchronization has been opened for this transaction.

### isNested

public boolean isNested()
Description copied from interface: `TransactionExecution`
Return if this transaction executes in a nested fashion within another.

The default implementation returns `false`.

Specified by:
  `isNested` in interface `TransactionExecution`
See Also:
  - `TransactionExecution.hasTransaction()`
  - `TransactionExecution.isNewTransaction()`
  - `TransactionDefinition.PROPAGATION_NESTED`

### isReadOnly

public boolean isReadOnly()
Description copied from interface: `TransactionExecution`
Return if this transaction is defined as read-only transaction.

The default implementation returns `false`.

Specified by:
  `isReadOnly` in interface `TransactionExecution`
See Also:
  - `TransactionDefinition.isReadOnly()`

### isDebug

public boolean isDebug()
Return whether the progress of this transaction is debugged. This is used by `AbstractReactiveTransactionManager` as an optimization, to prevent repeated calls to `logger.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.

### 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 this ReactiveTransactionStatus.

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

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

### 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`