Class DmxTransactionalAspect

java.lang.Object
dmx.fun.spring.DmxTransactionalAspect

@Component @NullMarked public class DmxTransactionalAspect extends Object
Spring AOP aspect that backs the TransactionalResult, TransactionalTry, and TransactionalValidated annotations.

Intercepts annotated methods and delegates to TxExecutor with a TransactionDefinition built from the annotation attributes. The transaction commits on a success value and rolls back on a failure value or an unchecked exception.

Register this bean and enable AspectJ auto-proxying in your Spring context:

@Configuration
@EnableAspectJAutoProxy
public class AppConfig {
    @Bean
    public DmxTransactionalAspect dmxTransactionalAspect(
            PlatformTransactionManager txManager, BeanFactory beanFactory) {
        return new DmxTransactionalAspect(txManager, beanFactory);
    }
}
See Also:
  • Constructor Details

    • DmxTransactionalAspect

      public DmxTransactionalAspect(org.springframework.transaction.PlatformTransactionManager txManager, org.springframework.beans.factory.BeanFactory beanFactory)
      Creates the aspect backed by the given transaction manager and bean factory.
      Parameters:
      txManager - the default transaction manager used when no bean name is specified in the annotation; must not be null
      beanFactory - the factory used to look up named transaction managers; must not be null
  • Method Details

    • aroundResult

      public Object aroundResult(org.aspectj.lang.ProceedingJoinPoint pjp, TransactionalResult ann)
      Runs the annotated method inside a transaction and rolls back if the returned Result is an error.
      Parameters:
      pjp - the proceeding join point supplied by AspectJ
      ann - the annotation instance carrying the transaction attributes
      Returns:
      the Result returned by the target method
    • aroundTry

      public Object aroundTry(org.aspectj.lang.ProceedingJoinPoint pjp, TransactionalTry ann)
      Runs the annotated method inside a transaction and rolls back if the returned Try is a failure.
      Parameters:
      pjp - the proceeding join point supplied by AspectJ
      ann - the annotation instance carrying the transaction attributes
      Returns:
      the Try returned by the target method
    • aroundValidated

      public Object aroundValidated(org.aspectj.lang.ProceedingJoinPoint pjp, TransactionalValidated ann)
      Runs the annotated method inside a transaction and rolls back if the returned Validated is invalid.
      Parameters:
      pjp - the proceeding join point supplied by AspectJ
      ann - the annotation instance carrying the transaction attributes
      Returns:
      the Validated returned by the target method