Top Description Methods
org.springframework.transaction.reactive

public Interface TransactionalOperator

Known Direct Implementers
org.springframework.transaction.reactive.TransactionalOperatorImpl
Imports
reactor.core.publisher.Flux, .Mono, org.springframework.transaction.ReactiveTransactionManager, .TransactionDefinition, .TransactionException

Operator class that simplifies programmatic transaction demarcation and transaction exception handling.

The central method is transactional, 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.

Authors
Mark Paluch, Juergen Hoeller, Enric Sala
Since
5.2
See Also
execute, ReactiveTransactionManager

Method Summary

Modifier and TypeMethod and Description
public static TransactionalOperator

Returns:

the transactional operator
create
(ReactiveTransactionManager
the transaction management strategy to be used
transactionManager
)

Create a new TransactionalOperator using ReactiveTransactionManager, using a default transaction.

public static TransactionalOperator

Returns:

the transactional operator
create
(ReactiveTransactionManager
the transaction management strategy to be used
transactionManager
,
TransactionDefinition
the transaction definition to apply
transactionDefinition
)

Create a new TransactionalOperator using ReactiveTransactionManager and TransactionDefinition.

public <T> Flux<T>

Returns:

a result object returned by the callback
execute
(TransactionCallback<T>
the callback object that specifies the transactional action
action
)

Execute the action specified by the given callback object within a transaction.

public default <T> Flux<T>

Returns:

a result publisher returned by the callback, or null if none
transactional
(Flux<T>
the Flux that should be executed within the transaction
flux
)

Wrap the functional sequence specified by the given Flux within a transaction.

public default <T> Mono<T>

Returns:

a result publisher returned by the callback
transactional
(Mono<T>
the Mono that should be executed within the transaction
mono
)

Wrap the functional sequence specified by the given Mono within a transaction.

Method Detail

createback to summary
public static TransactionalOperator create(ReactiveTransactionManager transactionManager)

Create a new TransactionalOperator using ReactiveTransactionManager, using a default transaction.

Parameters
transactionManager:ReactiveTransactionManager

the transaction management strategy to be used

Returns:TransactionalOperator

the transactional operator

createback to summary
public static TransactionalOperator create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition)

Create a new TransactionalOperator using ReactiveTransactionManager and TransactionDefinition.

Parameters
transactionManager:ReactiveTransactionManager

the transaction management strategy to be used

transactionDefinition:TransactionDefinition

the transaction definition to apply

Returns:TransactionalOperator

the transactional operator

executeback to summary
public <T> 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:TransactionCallback<T>

the callback object that specifies the transactional action

Returns:Flux<T>

a result object returned by the callback

Exceptions
TransactionException:
in case of initialization, rollback, or system errors
RuntimeException:
if thrown by the TransactionCallback
transactionalback to summary
public default <T> Flux<T> transactional(Flux<T> flux)

Wrap the functional sequence specified by the given Flux within a transaction.

Parameters
flux:Flux<T>

the Flux that should be executed within the transaction

Returns:Flux<T>

a result publisher returned by the callback, or null if none

Exceptions
TransactionException:
in case of initialization, rollback, or system errors
RuntimeException:
if thrown by the TransactionCallback
transactionalback to summary
public default <T> Mono<T> transactional(Mono<T> mono)

Wrap the functional sequence specified by the given Mono within a transaction.

Parameters
mono:Mono<T>

the Mono that should be executed within the transaction

Returns:Mono<T>

a result publisher returned by the callback

Exceptions
TransactionException:
in case of initialization, rollback, or system errors
RuntimeException:
if thrown by the TransactionCallback