Package com.ultikits.ultitools.aop
Class TransactionInterceptor
java.lang.Object
com.ultikits.ultitools.aop.TransactionInterceptor
- All Implemented Interfaces:
MethodInterceptor
AOP interceptor that implements declarative transaction management.
This interceptor processes @Transactional annotations and manages transaction boundaries accordingly.
- Since:
- 6.2.0
- Author:
- wisdomme
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTransactionInterceptor(TransactionManager transactionManager) Creates a new transaction interceptor. -
Method Summary
Modifier and TypeMethodDescriptionprivate ObjectexecuteInNewTransaction(MethodInvocation invocation, Transactional tx) Executes the invocation in a new transaction.private ObjectexecuteWithTransaction(MethodInvocation invocation, Transactional tx) Executes the method invocation within a transaction context.invoke(MethodInvocation invocation) Intercept the given method invocation.private booleanshouldRollback(Throwable e, Transactional tx) Determines if the transaction should be rolled back for the given exception.
-
Field Details
-
LOGGER
-
transactionManager
-
-
Constructor Details
-
TransactionInterceptor
Creates a new transaction interceptor.- Parameters:
transactionManager- the transaction manager to use
-
-
Method Details
-
invoke
Description copied from interface:MethodInterceptorIntercept the given method invocation.Implementations should call
MethodInvocation.proceed()to continue the interceptor chain or invoke the target method.- Specified by:
invokein interfaceMethodInterceptor- Parameters:
invocation- the method invocation context- Returns:
- the result of the method invocation
- Throws:
Throwable- if the interceptor or target method throws an exception
-
executeWithTransaction
private Object executeWithTransaction(MethodInvocation invocation, Transactional tx) throws Throwable Executes the method invocation within a transaction context.- Throws:
Throwable
-
executeInNewTransaction
private Object executeInNewTransaction(MethodInvocation invocation, Transactional tx) throws Throwable Executes the invocation in a new transaction.- Throws:
Throwable
-
shouldRollback
Determines if the transaction should be rolled back for the given exception.
-