roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject svn commit: r1708083 - in /roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa: JPAPersistenceStrategy.java JPAWebloggerImpl.java
Date Mon, 12 Oct 2015 10:49:40 GMT
Author: kohei
Date: Mon Oct 12 10:49:40 2015
New Revision: 1708083

URL: http://svn.apache.org/viewvc?rev=1708083&view=rev
Log:
Improve database release/shutdown procedures to reduce occasional Exceptions such as "IllegalStateException:
Illegal access:..."

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java?rev=1708083&r1=1708082&r2=1708083&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.java
Mon Oct 12 10:49:40 2015
@@ -142,12 +142,17 @@ public class JPAPersistenceStrategy {
      * Release database session, rolls back any uncommitted changes.
      */
     public void release() {
-        EntityManager em = getEntityManager(false);
-        if (isTransactionActive(em)) {
-            em.getTransaction().rollback();
+        try {
+            EntityManager em = getEntityManager(false);
+            if (isTransactionActive(em)) {
+                em.getTransaction().rollback();
+            }
+            em.close();
+        } catch (Exception e) {
+            logger.debug("error during releasing database session", e);
+        } finally {
+            threadLocalEntityManager.remove();
         }
-        em.close();
-        setThreadLocalEntityManager(null);
     }
     
     /**
@@ -249,13 +254,6 @@ public class JPAPersistenceStrategy {
     }
     
     /**
-     * Set the current ThreadLocal EntityManager
-     */
-    private void setThreadLocalEntityManager(EntityManager em) {
-        threadLocalEntityManager.set(em);
-    }
-    
-    /**
      * Get named query that won't commit changes to DB first (FlushModeType.COMMIT)
      * @param queryName the name of the query
      * @throws org.apache.roller.weblogger.WebloggerException on any error
@@ -345,4 +343,9 @@ public class JPAPersistenceStrategy {
         return em.createNamedQuery(queryName);
     }
 
+    public void shutdown() {
+        if (emf != null) {
+            emf.close();
+        }
+    }
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java?rev=1708083&r1=1708082&r2=1708083&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl.java
Mon Oct 12 10:49:40 2015
@@ -119,6 +119,8 @@ public class JPAWebloggerImpl extends We
 
         // then let parent do its thing
         super.shutdown();
+
+        this.strategy.shutdown();
     }
 
 }



Mime
View raw message