Replace signal materialization in TransactionalOperator with usingWhen

We now use Flux.usingWhen() instead materialize/dematerialize operators
to reuse Reactor's resource closure.

Until usingWhen() accepts a BiFunction to consume error signals,
we need to map error signals outside of usingWhen which requires
re-wrapping of the ReactiveTransaction object.
This commit is contained in:
Mark Paluch
2019-05-03 14:55:49 +02:00
committed by Juergen Hoeller
parent 9cff07ce35
commit 83046531da
2 changed files with 7 additions and 10 deletions

View File

@@ -78,14 +78,11 @@ final class TransactionalOperatorImpl implements TransactionalOperator {
return status.flatMapMany(it -> {
// This is an around advice: Invoke the next interceptor in the chain.
// This will normally result in a target object being invoked.
Flux<Object> retVal = Flux.from(action.doInTransaction(it));
return retVal.onErrorResume(ex -> rollbackOnException(it, ex).
then(Mono.error(ex))).materialize().flatMap(signal -> {
if (signal.isOnComplete()) {
return this.transactionManager.commit(it).materialize();
}
return Mono.just(signal);
}).<T>dematerialize();
// Need re-wrapping of ReactiveTransaction until we get hold of the exception
// through usingWhen.
return Flux.usingWhen(Mono.just(it), action::doInTransaction,
this.transactionManager::commit, s -> Mono.empty())
.onErrorResume(ex -> rollbackOnException(it, ex).then(Mono.error(ex)));
});
})
.subscriberContext(TransactionContextManager.getOrCreateContext())