roller-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1708085&view=rev
Log:
Make database releasing procedure more safer

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAPersistenceStrategy.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=1708085&r1=1708084&r2=1708085&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:57:31 2015
@@ -142,15 +142,22 @@ public class JPAPersistenceStrategy {
      * Release database session, rolls back any uncommitted changes.
      */
     public void release() {
+        EntityManager em = null;
         try {
-            EntityManager em = getEntityManager(false);
+            em = getEntityManager(false);
             if (isTransactionActive(em)) {
                 em.getTransaction().rollback();
             }
-            em.close();
         } catch (Exception e) {
-            logger.debug("error during releasing database session", e);
+            logger.error("error during releasing database session", e);
         } finally {
+            if (em != null) {
+                try {
+                    em.close();
+                } catch (Exception e) {
+                    logger.debug("error during closing EntityManager", e);
+                }
+            }
             threadLocalEntityManager.remove();
         }
     }



Mime
View raw message