better transaction handling
This commit is contained in:
parent
432904eef1
commit
4e7c0f204b
@ -5,7 +5,7 @@
|
|||||||
<groupId>de.hsadmin</groupId>
|
<groupId>de.hsadmin</groupId>
|
||||||
<artifactId>hsar</artifactId>
|
<artifactId>hsar</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
<name>HSAdmin Stable Backend Webapp</name>
|
<name>HSAdmin Stable Backend Webapp</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<properties>
|
<properties>
|
||||||
@ -36,12 +36,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-util</artifactId>
|
<artifactId>hsadmin-util</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-qserv</artifactId>
|
<artifactId>hsadmin-qserv</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-httpclient</groupId>
|
<groupId>commons-httpclient</groupId>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.hsadmin</groupId>
|
<groupId>de.hsadmin</groupId>
|
||||||
<artifactId>hsadmin-qserv</artifactId>
|
<artifactId>hsadmin-qserv</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HSAdmin-QServ</name>
|
<name>HSAdmin-QServ</name>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-qserv</artifactId>
|
<artifactId>hsadmin-qserv</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.activemq</groupId>
|
<groupId>org.apache.activemq</groupId>
|
||||||
@ -84,7 +84,7 @@
|
|||||||
<type>file</type>
|
<type>file</type>
|
||||||
<mapper>
|
<mapper>
|
||||||
<type>perm</type>
|
<type>perm</type>
|
||||||
<prefix>/lib/systemd/system/</prefix>
|
<prefix>/lib/systemd/system</prefix>
|
||||||
<filemode>644</filemode>
|
<filemode>644</filemode>
|
||||||
</mapper>
|
</mapper>
|
||||||
</data>
|
</data>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-qserv</artifactId>
|
<artifactId>hsadmin-qserv</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-util</artifactId>
|
<artifactId>hsadmin-util</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
|
@ -12,6 +12,7 @@ import javax.naming.Context;
|
|||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityTransaction;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||||
@ -33,10 +34,10 @@ public class Transaction {
|
|||||||
private InitialContext ctx;
|
private InitialContext ctx;
|
||||||
|
|
||||||
public Transaction(String loginName) {
|
public Transaction(String loginName) {
|
||||||
transactionActive = false;
|
this.transactionActive = false;
|
||||||
this.entityManager = PersistenceManager.getEntityManager("hsadmin");
|
this.entityManager = PersistenceManager.getEntityManager("hsadmin");
|
||||||
this.loginName = loginName;
|
this.loginName = loginName;
|
||||||
taskStores = new HashMap<String, QueueTaskStore>();
|
this.taskStores = new HashMap<String, QueueTaskStore>();
|
||||||
try {
|
try {
|
||||||
ctx = new InitialContext();
|
ctx = new InitialContext();
|
||||||
Context env = (Context) ctx.lookup("java:comp/env");
|
Context env = (Context) ctx.lookup("java:comp/env");
|
||||||
@ -104,24 +105,34 @@ public class Transaction {
|
|||||||
|
|
||||||
public void beginTransaction() {
|
public void beginTransaction() {
|
||||||
transactionActive = true;
|
transactionActive = true;
|
||||||
entityManager.getTransaction().begin();
|
final EntityTransaction tx = entityManager.getTransaction();
|
||||||
|
if (!tx.isActive()) {
|
||||||
|
tx.begin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commitTransaction() {
|
public void commitTransaction() {
|
||||||
try {
|
try {
|
||||||
entityManager.getTransaction().commit();
|
final EntityTransaction tx = entityManager.getTransaction();
|
||||||
} catch (Exception e) {
|
if (tx.isActive()) {
|
||||||
throw new TechnicalException(e);
|
tx.commit();
|
||||||
}
|
}
|
||||||
sendAll();
|
sendAll();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new TechnicalException(e);
|
||||||
|
} finally {
|
||||||
transactionActive = false;
|
transactionActive = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void rollbackTransaction() {
|
public void rollbackTransaction() {
|
||||||
taskStores.clear();
|
taskStores.clear();
|
||||||
transactionActive = false;
|
transactionActive = false;
|
||||||
try {
|
try {
|
||||||
entityManager.getTransaction().rollback();
|
final EntityTransaction tx = entityManager.getTransaction();
|
||||||
|
if (tx.isActive()) {
|
||||||
|
tx.rollback();
|
||||||
|
}
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
throw new TechnicalException(e);
|
throw new TechnicalException(e);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.hsadmin.core</groupId>
|
<groupId>de.hsadmin.core</groupId>
|
||||||
<artifactId>hsadmin-util</artifactId>
|
<artifactId>hsadmin-util</artifactId>
|
||||||
<version>4.0.12</version>
|
<version>4.0.13</version>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
|
Loading…
Reference in New Issue
Block a user