From 86802a2aab4733c3acbfe76b51f33f536eb8793f Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 19 Aug 2022 08:14:17 +0200 Subject: [PATCH] use Spring Transactional annotation instead of JavaX --- .../net/hostsharing/hsadminng/context/Context.java | 10 ++++++---- .../hsadminng/context/ContextIntegrationTests.java | 3 +-- .../hscustomer/CustomerRepositoryIntegrationTest.java | 2 +- .../hs/hspackage/PackageControllerAcceptanceTest.java | 2 +- .../hs/hspackage/PackageRepositoryIntegrationTest.java | 2 +- .../rbacuser/RbacUserControllerAcceptanceTest.java | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/context/Context.java b/src/main/java/net/hostsharing/hsadminng/context/Context.java index 82693667..20a40c2a 100644 --- a/src/main/java/net/hostsharing/hsadminng/context/Context.java +++ b/src/main/java/net/hostsharing/hsadminng/context/Context.java @@ -1,10 +1,12 @@ package net.hostsharing.hsadminng.context; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import javax.transaction.Transactional; + +import static org.springframework.transaction.annotation.Propagation.*; @Service public class Context { @@ -12,7 +14,7 @@ public class Context { @PersistenceContext private EntityManager em; - @Transactional(Transactional.TxType.MANDATORY) + @Transactional(propagation = MANDATORY) public void setCurrentUser(final String userName) { em.createNativeQuery( String.format( @@ -27,7 +29,7 @@ public class Context { return String.valueOf(em.createNativeQuery("select currentUser()").getSingleResult()); } - @Transactional(Transactional.TxType.MANDATORY) + @Transactional(propagation = MANDATORY) public void assumeRoles(final String roles) { em.createNativeQuery( String.format( @@ -37,7 +39,7 @@ public class Context { ).executeUpdate(); } - @Transactional(Transactional.TxType.MANDATORY) + @Transactional(propagation = MANDATORY) public void assumeNoSpecialRole() { em.createNativeQuery( "set local hsadminng.assumedRoles = '';" diff --git a/src/test/java/net/hostsharing/hsadminng/context/ContextIntegrationTests.java b/src/test/java/net/hostsharing/hsadminng/context/ContextIntegrationTests.java index 2e91ecf9..292fe9b5 100644 --- a/src/test/java/net/hostsharing/hsadminng/context/ContextIntegrationTests.java +++ b/src/test/java/net/hostsharing/hsadminng/context/ContextIntegrationTests.java @@ -5,8 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.annotation.DirtiesContext; - -import javax.transaction.Transactional; +import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java index ed532fec..6ac1d1bf 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java @@ -8,10 +8,10 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import javax.persistence.PersistenceException; -import javax.transaction.Transactional; import java.util.List; import java.util.UUID; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java index 5cc3cdd9..6fd8c15d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java @@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.transaction.annotation.Transactional; -import javax.transaction.Transactional; import java.util.UUID; import static java.lang.String.format; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java index b459dfba..b978fa86 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java @@ -9,9 +9,9 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; -import javax.transaction.Transactional; import java.util.List; import static net.hostsharing.test.JpaAttempt.attempt; diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/rbacuser/RbacUserControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/rbacuser/RbacUserControllerAcceptanceTest.java index c18302e5..f554f027 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/rbacuser/RbacUserControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/rbacuser/RbacUserControllerAcceptanceTest.java @@ -9,9 +9,9 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; -import javax.transaction.Transactional; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat;