Class TransactionContextManager
- java.lang.Object
- org.springframework.transaction.reactive.TransactionContextManager
public abstract class TransactionContextManager extends Object
Delegate to register and obtain transactional contexts.Typically used by components that intercept or orchestrate transactional flows such as AOP interceptors or transactional operators.
- Since:
- 5.2
- Author:
- Mark Paluch
- See Also:
TransactionSynchronization
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Function<reactor.util.context.Context,reactor.util.context.Context>
createTransactionContext()
Create aTransactionContext
and register it in the subscriberContext
.static reactor.core.publisher.Mono<TransactionContext>
currentContext()
Obtain the currentTransactionContext
from the subscriber context or the transactional context holder.static Function<reactor.util.context.Context,reactor.util.context.Context>
getOrCreateContext()
Return aFunction
to create or associate a newTransactionContext
.static Function<reactor.util.context.Context,reactor.util.context.Context>
getOrCreateContextHolder()
Return aFunction
to create or associate a newTransactionContextHolder
.
Method Detail
currentContext
public static reactor.core.publisher.Mono<TransactionContext> currentContext() throws NoTransactionException
Obtain the currentTransactionContext
from the subscriber context or the transactional context holder. Context retrieval fails with NoTransactionException if no context or context holder is registered.- Returns:
- the current
TransactionContext
- Throws:
NoTransactionException
- if no TransactionContext was found in the subscriber context or no context found in a holder
createTransactionContext
public static Function<reactor.util.context.Context,reactor.util.context.Context> createTransactionContext()
Create aTransactionContext
and register it in the subscriberContext
.- Returns:
- functional context registration.
- Throws:
IllegalStateException
- if a transaction context is already associated.- See Also:
Mono.subscriberContext(Function)
,Flux.subscriberContext(Function)
getOrCreateContext
public static Function<reactor.util.context.Context,reactor.util.context.Context> getOrCreateContext()
Return aFunction
to create or associate a newTransactionContext
. Interaction with transactional resources throughTransactionSynchronizationManager
requires a TransactionContext to be registered in the subscriber context.- Returns:
- functional context registration.
getOrCreateContextHolder
public static Function<reactor.util.context.Context,reactor.util.context.Context> getOrCreateContextHolder()
Return aFunction
to create or associate a newTransactionContextHolder
. Creation and release of transactions within a reactive flow requires a mutable holder that follows a top to down execution scheme. Reactor's subscriber context follows a down to top approach regarding mutation visibility.- Returns:
- functional context registration.