Example usage for org.springframework.transaction.reactive TransactionContextManager getOrCreateContextHolder

List of usage examples for org.springframework.transaction.reactive TransactionContextManager getOrCreateContextHolder

Introduction

In this page you can find the example usage for org.springframework.transaction.reactive TransactionContextManager getOrCreateContextHolder.

Prototype

public static Function<Context, Context> getOrCreateContextHolder() 

Source Link

Document

Return a Function to create or associate a new TransactionContextHolder .

Usage

From source file:org.springframework.transaction.reactive.TransactionalOperatorImpl.java

@Override
public <T> Flux<T> execute(TransactionCallback<T> action) throws TransactionException {
    return TransactionContextManager.currentContext().flatMapMany(context -> {
        Mono<ReactiveTransaction> status = this.transactionManager
                .getReactiveTransaction(this.transactionDefinition);
        // This is an around advice: Invoke the next interceptor in the chain.
        // This will normally result in a target object being invoked.
        // Need re-wrapping of ReactiveTransaction until we get hold of the exception
        // through usingWhen.
        return status.flatMapMany(it -> 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())
            .subscriberContext(TransactionContextManager.getOrCreateContextHolder());
}