@Singleton @Requires(beans=SynchronousTransactionManager.class) public class TransactionalInterceptor extends java.lang.Object implements io.micronaut.aop.MethodInterceptor<java.lang.Object,java.lang.Object>
TransactionalAdvice
. Forked from the reflection based code in Spring.Modifier and Type | Class and Description |
---|---|
protected class |
TransactionalInterceptor.TransactionInfo
Opaque object used to hold transaction information.
|
Constructor and Description |
---|
TransactionalInterceptor(io.micronaut.context.BeanLocator beanLocator)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cleanupTransactionInfo(TransactionalInterceptor.TransactionInfo txInfo)
Reset the TransactionInfo ThreadLocal.
|
protected void |
commitTransactionAfterReturning(TransactionalInterceptor.TransactionInfo txInfo)
Execute after successful completion of call, but not after an exception was handled.
|
protected void |
completeTransactionAfterThrowing(TransactionalInterceptor.TransactionInfo txInfo,
java.lang.Throwable ex)
Handle a throwable, completing the transaction.
|
protected TransactionalInterceptor.TransactionInfo |
createTransactionIfNecessary(SynchronousTransactionManager tm,
TransactionAttribute txAttr,
java.lang.String joinpointIdentification)
Create a transaction if necessary based on the given TransactionAttribute.
|
static TransactionStatus |
currentTransactionStatus()
Return the transaction status of the current method invocation.
|
int |
getOrder() |
java.lang.Object |
intercept(io.micronaut.aop.MethodInvocationContext<java.lang.Object,java.lang.Object> context) |
protected TransactionalInterceptor.TransactionInfo |
prepareTransactionInfo(SynchronousTransactionManager tm,
TransactionAttribute txAttr,
java.lang.String joinpointIdentification,
TransactionStatus status)
Prepare a TransactionInfo for the given attribute and status object.
|
protected TransactionAttribute |
resolveTransactionDefinition(io.micronaut.inject.ExecutableMethod<java.lang.Object,java.lang.Object> executableMethod) |
public TransactionalInterceptor(@NonNull io.micronaut.context.BeanLocator beanLocator)
beanLocator
- The bean locator.public int getOrder()
getOrder
in interface io.micronaut.core.order.Ordered
public java.lang.Object intercept(io.micronaut.aop.MethodInvocationContext<java.lang.Object,java.lang.Object> context)
intercept
in interface io.micronaut.aop.MethodInterceptor<java.lang.Object,java.lang.Object>
public static TransactionStatus currentTransactionStatus() throws NoTransactionException
NoTransactionException
- if the transaction info cannot be found,
because the method was invoked outside an AOP invocation contextprotected TransactionalInterceptor.TransactionInfo createTransactionIfNecessary(@NonNull SynchronousTransactionManager tm, @NonNull TransactionAttribute txAttr, java.lang.String joinpointIdentification)
Allows callers to perform custom TransactionAttribute lookups through the TransactionAttributeSource.
tm
- The transaction managertxAttr
- the TransactionAttribute (may be null
)joinpointIdentification
- the fully qualified method name
(used for monitoring and logging purposes)hasTransaction()
method on TransactionInfo can be used to
tell if there was a transaction created.protected TransactionalInterceptor.TransactionInfo prepareTransactionInfo(@NonNull SynchronousTransactionManager tm, @NonNull TransactionAttribute txAttr, java.lang.String joinpointIdentification, @NonNull TransactionStatus status)
tm
- The transaction managertxAttr
- the TransactionAttribute (may be null
)joinpointIdentification
- the fully qualified method name
(used for monitoring and logging purposes)status
- the TransactionStatus for the current transactionprotected void commitTransactionAfterReturning(@NonNull TransactionalInterceptor.TransactionInfo txInfo)
txInfo
- information about the current transactionprotected void completeTransactionAfterThrowing(@NonNull TransactionalInterceptor.TransactionInfo txInfo, java.lang.Throwable ex)
txInfo
- information about the current transactionex
- throwable encounteredprotected void cleanupTransactionInfo(@Nullable TransactionalInterceptor.TransactionInfo txInfo)
Call this in all cases: exception or normal return!
txInfo
- information about the current transaction (may be null
)protected TransactionAttribute resolveTransactionDefinition(io.micronaut.inject.ExecutableMethod<java.lang.Object,java.lang.Object> executableMethod)
executableMethod
- The methodTransactionAttribute