Interface TransactionalOperator


public interface TransactionalOperator
Operator class that simplifies programmatic transaction demarcation and transaction exception handling.

The central method is transactional(reactor.core.publisher.Flux<T>), supporting transactional wrapping of functional sequences code that. This operator handles the transaction lifecycle and possible exceptions such that neither the ReactiveTransactionCallback implementation nor the calling code needs to explicitly handle transactions.

Typical usage: Allows for writing low-level data access objects that use resources such as database connections but are not transaction-aware themselves. Instead, they can implicitly participate in transactions handled by higher-level application services utilizing this class, making calls to the low-level services via an inner-class callback object.

Note: Transactional Publishers should avoid Subscription cancellation. See the Cancel Signals section of the Spring Framework reference for more details.

Since:
5.2
Author:
Mark Paluch, Juergen Hoeller
See Also:
  • Method Details

    • transactional

      default <T> reactor.core.publisher.Flux<T> transactional(reactor.core.publisher.Flux<T> flux)
      Wrap the functional sequence specified by the given Flux within a transaction.
      Parameters:
      flux - the Flux that should be executed within the transaction
      Returns:
      a result publisher returned by the callback, or null if none
      Throws:
      TransactionException - in case of initialization, rollback, or system errors
      RuntimeException - if thrown by the TransactionCallback
    • transactional

      <T> reactor.core.publisher.Mono<T> transactional(reactor.core.publisher.Mono<T> mono)
      Wrap the functional sequence specified by the given Mono within a transaction.
      Parameters:
      mono - the Mono that should be executed within the transaction
      Returns:
      a result publisher returned by the callback
      Throws:
      TransactionException - in case of initialization, rollback, or system errors
      RuntimeException - if thrown by the TransactionCallback
    • execute

      <T> reactor.core.publisher.Flux<T> execute(TransactionCallback<T> action) throws TransactionException
      Execute the action specified by the given callback object within a transaction.

      Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.

      Parameters:
      action - the callback object that specifies the transactional action
      Returns:
      a result object returned by the callback
      Throws:
      TransactionException - in case of initialization, rollback, or system errors
      RuntimeException - if thrown by the TransactionCallback
    • create

      static TransactionalOperator create(ReactiveTransactionManager transactionManager)
      Create a new TransactionalOperator using ReactiveTransactionManager, using a default transaction.
      Parameters:
      transactionManager - the transaction management strategy to be used
      Returns:
      the transactional operator
    • create

      static TransactionalOperator create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition)
      Parameters:
      transactionManager - the transaction management strategy to be used
      transactionDefinition - the transaction definition to apply
      Returns:
      the transactional operator