I need to mark the transaction somehow. We need some kind of method like: TransactionAspectSupport.setData (someObject); Then, until the transaction is alive, I would like to be able to read this data.
I need him to check in the Aspect class that some operation on the current transaction has already been completed.
EDIT: To illustrate what I mean. Let have two classes.
Class of service:
class Service {
@Transactional
public void serviceA(){
serviceB();
}
@Transactional
public void serviceB(){
}
}
Aspect Class:
@Aspect
class ServiceAspect {
@Pointcut("execution(public * service*)")
private void checkTransaction(){};
@Around("checkTransaction()")
public Object _checkTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
if (!isTransactionFlagged())
doTheCheckingJob()
transactionInfo.setData(Boolean.True);
}
private boolean isTransactionFlagged() {
if (transactionInfo.getData != null)
return true;
return false;
}
}
As you can see, I need to commit the transaction in some way, so the aspect does not work several times in the same transaction. But still need an aspect for every service method. Just do not fire on an internal call to a service method.
source
share