use Spring Transactional annotation instead of JavaX

This commit is contained in:
Michael Hoennig 2022-08-19 08:14:17 +02:00
parent eebe2d40a6
commit 86802a2aab
6 changed files with 11 additions and 10 deletions

View File

@ -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 = '';"

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;