fix Transactional handing

This commit is contained in:
2024-08-09 13:44:48 -04:00
parent 4e64539de2
commit f636b22c76
3 changed files with 38 additions and 8 deletions

21
pom.xml
View File

@@ -72,9 +72,26 @@
<dependency>
<groupId>com.inteligr8.alfresco</groupId>
<artifactId>aspectj-platform-module</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<type>amp</type>
<scope>provided</scope>
</dependency>
<!-- AMP resources are included in the WAR, not the extension directory; this makes aspectjweaver available to javaagent -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
<scope>test</scope>
</dependency>
<!-- Removes startup warning regarding annotations that aren't annotations -->
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
</dependencies>

View File

@@ -19,9 +19,18 @@ public class TransactionalWrapper {
this.jtxl = txl;
}
public TransactionalWrapper(Method method) {
this.stxl = method.getAnnotation(Transactional.class);
this.jtxl = method.getAnnotation(javax.transaction.Transactional.class);
public static TransactionalWrapper wrap(Method method) {
Transactional stxl = method.getAnnotation(Transactional.class);
javax.transaction.Transactional jtxl = method.getAnnotation(javax.transaction.Transactional.class);
if (stxl == null && jtxl == null) {
return null;
} else if (stxl != null) {
return new TransactionalWrapper(stxl);
} else if (jtxl != null) {
return new TransactionalWrapper(jtxl);
} else {
throw new IllegalStateException("This should never happen");
}
}
public boolean isReadOnly() {

View File

@@ -46,20 +46,24 @@ public class RetryingTransactionAspect {
@Autowired
private TransactionService txService;
@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional || javax.transaction.Transactional) && execution(* *(..))")
@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional) && execution(* *(..))")
public void isTransactionalAnnotated() {
}
@Pointcut("@annotation(javax.transaction.Transactional) && execution(* *(..))")
public void isJtaTransactionalAnnotated() {
}
@Pointcut("@annotation(com.inteligr8.alfresco.annotations.TransactionalRetryable) && execution(* *(..))")
public void isTransactionalRetryableAnnotated() {
}
@Around("isTransactionalAnnotated() || isTransactionalRetryableAnnotated()")
@Around("isTransactionalAnnotated() || isJtaTransactionalAnnotated() || isTransactionalRetryableAnnotated()")
public Object retryingTransactional(ProceedingJoinPoint joinPoint) throws Throwable {
this.logger.trace("retryingTransactional({})", joinPoint);
Method method = this.getMethod(joinPoint);
TransactionalWrapper txl = new TransactionalWrapper(method);
TransactionalWrapper txl = TransactionalWrapper.wrap(method);
TransactionalRetryable txtry = method.getAnnotation(TransactionalRetryable.class);
if (this.doCreateNewTxContext(txl) || this.isReadStateChange(txl)) {