From 4e7c0f204b0c9c13c1197c11935733cfd82eb506 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Fri, 4 Aug 2023 20:34:34 +0200 Subject: [PATCH] better transaction handling --- hsarback/pom.xml | 6 ++--- qserv-deploy/pom.xml | 6 ++--- qserv/pom.xml | 4 +-- .../de/hsadmin/core/model/Transaction.java | 25 +++++++++++++------ util/pom.xml | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/hsarback/pom.xml b/hsarback/pom.xml index 446bd34..8c49ba5 100644 --- a/hsarback/pom.xml +++ b/hsarback/pom.xml @@ -5,7 +5,7 @@ de.hsadmin hsar war - 4.0.12 + 4.0.13 HSAdmin Stable Backend Webapp http://maven.apache.org @@ -36,12 +36,12 @@ de.hsadmin.core hsadmin-util - 4.0.12 + 4.0.13 de.hsadmin.core hsadmin-qserv - 4.0.12 + 4.0.13 commons-httpclient diff --git a/qserv-deploy/pom.xml b/qserv-deploy/pom.xml index 89f6afb..fb48ed6 100644 --- a/qserv-deploy/pom.xml +++ b/qserv-deploy/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin hsadmin-qserv - 4.0.12 + 4.0.13 jar HSAdmin-QServ @@ -20,7 +20,7 @@ de.hsadmin.core hsadmin-qserv - 4.0.12 + 4.0.13 org.apache.activemq @@ -84,7 +84,7 @@ file perm - /lib/systemd/system/ + /lib/systemd/system 644 diff --git a/qserv/pom.xml b/qserv/pom.xml index 853e7ad..9f790bf 100644 --- a/qserv/pom.xml +++ b/qserv/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-qserv - 4.0.12 + 4.0.13 UTF-8 11 @@ -13,7 +13,7 @@ de.hsadmin.core hsadmin-util - 4.0.12 + 4.0.13 commons-lang diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index fcd084a..cf5857f 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -12,6 +12,7 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; import javax.persistence.Query; import org.apache.openjpa.persistence.OpenJPAEntityManager; @@ -33,10 +34,10 @@ public class Transaction { private InitialContext ctx; public Transaction(String loginName) { - transactionActive = false; + this.transactionActive = false; this.entityManager = PersistenceManager.getEntityManager("hsadmin"); this.loginName = loginName; - taskStores = new HashMap(); + this.taskStores = new HashMap(); try { ctx = new InitialContext(); Context env = (Context) ctx.lookup("java:comp/env"); @@ -104,24 +105,34 @@ public class Transaction { public void beginTransaction() { transactionActive = true; - entityManager.getTransaction().begin(); + final EntityTransaction tx = entityManager.getTransaction(); + if (!tx.isActive()) { + tx.begin(); + } } public void commitTransaction() { try { - entityManager.getTransaction().commit(); + final EntityTransaction tx = entityManager.getTransaction(); + if (tx.isActive()) { + tx.commit(); + } + sendAll(); } catch (Exception e) { throw new TechnicalException(e); + } finally { + transactionActive = false; } - sendAll(); - transactionActive = false; } public void rollbackTransaction() { taskStores.clear(); transactionActive = false; try { - entityManager.getTransaction().rollback(); + final EntityTransaction tx = entityManager.getTransaction(); + if (tx.isActive()) { + tx.rollback(); + } } catch (IllegalStateException e) { throw new TechnicalException(e); } diff --git a/util/pom.xml b/util/pom.xml index a05482a..227c54e 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-util - 4.0.12 + 4.0.13 UTF-8 11