接口 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.
- 从以下版本开始:
- 5.2
- 作者:
- Mark Paluch, Juergen Hoeller
- 另请参阅:
execute(org.springframework.transaction.reactive.TransactionCallback<T>)
,ReactiveTransactionManager
方法概要
所有方法 静态方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 static TransactionalOperator
create(ReactiveTransactionManager transactionManager)
Create a newTransactionalOperator
usingReactiveTransactionManager
, using a default transaction.static TransactionalOperator
create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition)
<T> reactor.core.publisher.Flux<T>
execute(TransactionCallback<T> action)
Execute the action specified by the given callback object within a transaction.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.<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.
方法详细资料
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.- 参数:
flux
- the Flux that should be executed within the transaction- 返回:
- a result publisher returned by the callback, or
null
if none - 抛出:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- 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.- 参数:
mono
- the Mono that should be executed within the transaction- 返回:
- a result publisher returned by the callback
- 抛出:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- 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.
- 参数:
action
- the callback object that specifies the transactional action- 返回:
- a result object returned by the callback
- 抛出:
TransactionException
- in case of initialization, rollback, or system errorsRuntimeException
- if thrown by the TransactionCallback
create
static TransactionalOperator create(ReactiveTransactionManager transactionManager)
Create a newTransactionalOperator
usingReactiveTransactionManager
, using a default transaction.- 参数:
transactionManager
- the transaction management strategy to be used- 返回:
- the transactional operator
create
static TransactionalOperator create(ReactiveTransactionManager transactionManager, TransactionDefinition transactionDefinition)
- 参数:
transactionManager
- the transaction management strategy to be usedtransactionDefinition
- the transaction definition to apply- 返回:
- the transactional operator