Skip to content

Commit

Permalink
Merge pull request #7 from murdos/feature/handle-jakarta-transactional
Browse files Browse the repository at this point in the history
Support Jakarta JTA @transactional annotation
  • Loading branch information
DirkMahler authored Mar 11, 2024
2 parents 4cb72f6 + 9e3ea99 commit b92f590
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 19 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<org.springframework.ws_version>4.0.10</org.springframework.ws_version>
<org.springframework.data_version>3.2.2</org.springframework.data_version>
<javax.transaction.transaction-api_version>1.3</javax.transaction.transaction-api_version>
<jakarta.transaction-api.version>2.0.1</jakarta.transaction-api.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -166,6 +167,12 @@
<version>${javax.transaction.transaction-api_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>${jakarta.transaction-api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<concept id="spring-transaction:TransactionalMethod">
<requiresConcept refId="spring-transaction:TransactionalClass"/>
<description>
Label all methods which are annotated with "@org.springframework.transaction.annotation.Transactional" with "Spring" and "Transactional".
Label all methods which are annotated with "@org.springframework.transaction.annotation.Transactional", "jakarta.transaction.Transactional",
or "javax.transaction.Transactional", with "Spring" and "Transactional".
</description>
<cypher><![CDATA[
MATCH
Expand All @@ -39,6 +40,7 @@
WHERE
annotationType.fqn in [
"org.springframework.transaction.annotation.Transactional",
"jakarta.transaction.Transactional",
"javax.transaction.Transactional"
]
or type:Spring:Transactional
Expand All @@ -51,15 +53,16 @@

<concept id="spring-transaction:TransactionalClass">
<description>
Label all classes annotated with "@org.springframework.transaction.annotation.Transactional"and their declared methods with "Spring" and
"Transactional".
Label all classes annotated with "@org.springframework.transaction.annotation.Transactional", "jakarta.transaction.Transactional",
or "javax.transaction.Transactional", and their declared methods with "Spring" and "Transactional".
</description>
<cypher><![CDATA[
MATCH
(transactionalClass:Class)-[:EXTENDS*0..]->(:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(annotationType:Type)
WHERE
annotationType.fqn in [
"org.springframework.transaction.annotation.Transactional",
"jakarta.transaction.Transactional",
"javax.transaction.Transactional"
]
SET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,35 @@ class TransactionalMethodIT extends AbstractSpringIT {

@Test
void transactionalMethod() throws Exception {
scanClasses(TransactionalMethod.class, JtaTransactionalMethod.class);
scanClasses(SpringTransactionalMethod.class, JtaTransactionalMethod.class, JtaJakartaTransactionalMethod.class);
assertThat(applyConcept("spring-transaction:TransactionalMethod").getStatus(), equalTo(SUCCESS));
store.beginTransaction();
List<Object> methods = query("MATCH (m:Spring:Method:Transactional) RETURN m").getColumn("m");
assertThat(methods.size(), equalTo(2));
assertThat(methods, hasItem(methodDescriptor(TransactionalMethod.class, "transactionalMethod")));
assertThat(methods, not(hasItem(methodDescriptor(TransactionalMethod.class, "nonTransactionalMethod"))));
assertThat(methods.size(), equalTo(3));
assertThat(methods, hasItem(methodDescriptor(SpringTransactionalMethod.class, "transactionalMethod")));
assertThat(methods, not(hasItem(methodDescriptor(SpringTransactionalMethod.class, "nonTransactionalMethod"))));
assertThat(methods, hasItem(methodDescriptor(JtaTransactionalMethod.class, "transactionalMethod")));
assertThat(methods, hasItem(methodDescriptor(JtaJakartaTransactionalMethod.class, "transactionalMethod")));
store.commitTransaction();
}

@Test
void transactionalClass() throws Exception {
scanClasses(TransactionalClass.class, TransactionalSubClass.class, JtaTransactionalClass.class);
scanClasses(SpringTransactionalClass.class, SpringTransactionalSubClass.class, JtaTransactionalClass.class, JtaJakartaTransactionalClass.class);
assertThat(applyConcept("spring-transaction:TransactionalClass").getStatus(), equalTo(SUCCESS));
store.beginTransaction();
List<Object> classes = query("MATCH (c:Spring:Class:Transactional) RETURN c").getColumn("c");
assertThat(classes.size(), equalTo(3));
assertThat(classes, hasItem(typeDescriptor(TransactionalClass.class)));
assertThat(classes, hasItem(typeDescriptor(TransactionalSubClass.class)));
assertThat(classes.size(), equalTo(4));
assertThat(classes, hasItem(typeDescriptor(SpringTransactionalClass.class)));
assertThat(classes, hasItem(typeDescriptor(SpringTransactionalSubClass.class)));
assertThat(classes, hasItem(typeDescriptor(JtaTransactionalClass.class)));
assertThat(classes, hasItem(typeDescriptor(JtaJakartaTransactionalClass.class)));
List<Object> methods = query("MATCH (m:Spring:Method:Transactional) RETURN m").getColumn("m");
assertThat(methods.size(), equalTo(3));
assertThat(methods, hasItem(methodDescriptor(TransactionalClass.class, "transactionalMethod")));
assertThat(methods, hasItem(methodDescriptor(TransactionalSubClass.class, "transactionalSubClassMethod")));
assertThat(methods.size(), equalTo(4));
assertThat(methods, hasItem(methodDescriptor(SpringTransactionalClass.class, "transactionalMethod")));
assertThat(methods, hasItem(methodDescriptor(SpringTransactionalSubClass.class, "transactionalSubClassMethod")));
assertThat(methods, hasItem(methodDescriptor(JtaTransactionalClass.class, "transactionalMethod")));
assertThat(methods, hasItem(methodDescriptor(JtaJakartaTransactionalClass.class, "transactionalMethod")));
store.commitTransaction();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.buschmais.jqassistant.core.rule.api.model.Constraint;
import com.buschmais.jqassistant.plugin.java.test.AbstractJavaPluginIT;

import org.jqassistant.plugin.spring.test.set.transaction.TransactionalMethod;
import org.jqassistant.plugin.spring.test.set.transaction.SpringTransactionalMethod;
import org.junit.jupiter.api.Test;

import static com.buschmais.jqassistant.core.report.api.model.Result.Status.FAILURE;
Expand All @@ -21,7 +21,7 @@ class TransactionalMethodMustNotBeInvokedFromSameClassIT extends AbstractJavaPlu

@Test
void transactionMethodsMustNotBeCalledDirectly() throws Exception {
scanClasses(TransactionalMethod.class);
scanClasses(SpringTransactionalMethod.class);
assertThat(validateConstraint("spring-transaction:TransactionalMethodMustNotBeInvokedFromSameClass").getStatus(), equalTo(FAILURE));
store.beginTransaction();
List<Result<Constraint>> constraintViolations = new ArrayList<>(reportPlugin.getConstraintResults().values());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jqassistant.plugin.spring.test.set.transaction;

import jakarta.transaction.Transactional;

@Transactional
public class JtaJakartaTransactionalClass {

public void transactionalMethod(){
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.jqassistant.plugin.spring.test.set.transaction;

import jakarta.transaction.Transactional;

public class JtaJakartaTransactionalMethod {

@Transactional
public void transactionalMethod() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class TransactionalClass {
public class SpringTransactionalClass {

public void transactionalMethod(){
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.transaction.annotation.Transactional;

public class TransactionalMethod {
public class SpringTransactionalMethod {

@Transactional
public void transactionalMethod(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jqassistant.plugin.spring.test.set.transaction;

public class TransactionalSubClass extends TransactionalClass {
public class SpringTransactionalSubClass extends SpringTransactionalClass {

public void transactionalSubClassMethod() {
}
Expand Down

0 comments on commit b92f590

Please sign in to comment.