Based on Anthony Accioly’s answer I’ve come up with a solution.
Annotation:
@Retention(RetentionPolicy.RUNTIME)
public @interface NoTransactional {
}
Declaration class of pointcuts:
@Aspect
public class AspectTransactionConfig {
@Pointcut("execution(* br.com.infraestrutura.domain.BaseBusiness+.*(..))")
public void baseBusinessPointcut() {}
@Pointcut("@annotation(br.com.webfarma.sis.application.NoTransactional)")
public void nonTransactionalMethod() {}
@Pointcut("@within(br.com.webfarma.sis.application.NoTransactional)")
public void nonTransactionalClass() {}
@Pointcut("execution(* br.com.infraestrutura.domain.BaseDao+.*(..))")
public void baseDaoPointcut() {}
@Pointcut("baseBusinessPointcut() && !(nonTransactionalMethod() || nonTransactionalClass())")
public void trasactionalBaseBusinessMethod() {}
}
XML of configuration:
<aop:config>
<aop:advisor advice-ref="permissaoMetodoAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.baseDaoPointcut()" order="1" />
<aop:advisor advice-ref="notificacaoEntidadeAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.baseDaoPointcut()" order="2" />
<aop:advisor advice-ref="transactionDaoAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.baseDaoPointcut()" order="3" />
<aop:advisor advice-ref="queryFilterManagerAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.baseDaoPointcut()" order="4" />
<aop:advisor advice-ref="permissaoMetodoAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.baseBusinessPointcut()" order="1" />
<aop:advisor advice-ref="transactionBusinessAdvice" pointcut="br.com.webfarma.sis.application.AspectTransactionConfig.trasactionalBaseBusinessMethod()" order="2" />
</aop:config>
I’m trying this solution because the system has an old architecture where it defines that all classes that implement Basedao or Basebusiness are transactional, however there are some exceptions emerging where I would note the class as Notransactional is transactional methods with Transactional.
– Henrique Luiz