Author: rkanter
Date: Tue Nov 26 18:49:12 2013
New Revision: 1545778

URL: http://svn.apache.org/r1545778
Log:
OOZIE-1623 JPAService doesn't need to do reads in a transaction (rkanter)

Modified:
    oozie/trunk/core/src/main/java/org/apache/oozie/service/JPAService.java
    oozie/trunk/release-log.txt

Modified: 
oozie/trunk/core/src/main/java/org/apache/oozie/service/JPAService.java
URL: 
http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/service/JPAService.java?rev=1545778&r1=1545777&r2=1545778&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/service/JPAService.java 
(original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/service/JPAService.java Tue 
Nov 26 18:49:12 2013
@@ -295,7 +295,7 @@ public class JPAService implements Servi
             throw new JPAExecutorException(ErrorCode.E0603, e);
         }
         finally {
-            processFinally(em, cron, namedQueryName);
+            processFinally(em, cron, namedQueryName, true);
         }
     }
 
@@ -317,20 +317,22 @@ public class JPAService implements Servi
         }
     }
 
-    private void processFinally(EntityManager em, Instrumentation.Cron cron, 
String name){
+    private void processFinally(EntityManager em, Instrumentation.Cron cron, 
String name, boolean checkActive) {
         cron.stop();
         if (instr != null) {
             instr.addCron(INSTRUMENTATION_GROUP_JPA, name, cron);
         }
-        try {
-            if (em.getTransaction().isActive()) {
-                LOG.warn("[{0}] ended with an active transaction, rolling 
back", name);
-                em.getTransaction().rollback();
+        if (checkActive) {
+            try {
+                if (em.getTransaction().isActive()) {
+                    LOG.warn("[{0}] ended with an active transaction, rolling 
back", name);
+                    em.getTransaction().rollback();
+                }
+            }
+            catch (Exception ex) {
+                LOG.warn("Could not check/rollback transaction after [{0}], 
{1}", name,
+                        ex.getMessage(), ex);
             }
-        }
-        catch (Exception ex) {
-            LOG.warn("Could not check/rollback transaction after [{0}], {1}", 
name,
-                    ex.getMessage(), ex);
         }
         try {
             if (em.isOpen()) {
@@ -390,7 +392,7 @@ public class JPAService implements Servi
             throw new JPAExecutorException(ErrorCode.E0603, e);
         }
         finally {
-            processFinally(em, cron, "batchqueryexecutor");
+            processFinally(em, cron, "batchqueryexecutor", true);
         }
     }
 
@@ -400,9 +402,8 @@ public class JPAService implements Servi
      * @param query query instance to be executed
      * @param em Entity Manager
      * @return object that matches the query
-     * @throws JPAExecutorException
      */
-    public Object executeGet(String namedQueryName, Query query, EntityManager 
em) throws JPAExecutorException {
+    public Object executeGet(String namedQueryName, Query query, EntityManager 
em) {
         Instrumentation.Cron cron = new Instrumentation.Cron();
         try {
 
@@ -412,7 +413,6 @@ public class JPAService implements Servi
             }
 
             cron.start();
-            em.getTransaction().begin();
             Object obj = null;
             try {
                 obj = query.getSingleResult();
@@ -420,19 +420,10 @@ public class JPAService implements Servi
             catch (NoResultException e) {
                 // return null when no matched result
             }
-            if (em.getTransaction().isActive()) {
-                if 
(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection")) {
-                    throw new RuntimeException("Skipping Commit for Failover 
Testing");
-                }
-                em.getTransaction().commit();
-            }
             return obj;
         }
-        catch (PersistenceException e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
         finally {
-            processFinally(em, cron, namedQueryName);
+            processFinally(em, cron, namedQueryName, false);
         }
     }
 
@@ -442,9 +433,8 @@ public class JPAService implements Servi
      * @param query query instance to be executed
      * @param em Entity Manager
      * @return list containing results that match the query
-     * @throws JPAExecutorException
      */
-    public List<?> executeGetList(String namedQueryName, Query query, 
EntityManager em) throws JPAExecutorException {
+    public List<?> executeGetList(String namedQueryName, Query query, 
EntityManager em) {
         Instrumentation.Cron cron = new Instrumentation.Cron();
         try {
 
@@ -454,7 +444,6 @@ public class JPAService implements Servi
             }
 
             cron.start();
-            em.getTransaction().begin();
             List<?> resultList = null;
             try {
                 resultList = query.getResultList();
@@ -462,19 +451,10 @@ public class JPAService implements Servi
             catch (NoResultException e) {
                 // return null when no matched result
             }
-            if (em.getTransaction().isActive()) {
-                if 
(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection")) {
-                    throw new RuntimeException("Skipping Commit for Failover 
Testing");
-                }
-                em.getTransaction().commit();
-            }
             return resultList;
         }
-        catch (PersistenceException e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
         finally {
-            processFinally(em, cron, namedQueryName);
+            processFinally(em, cron, namedQueryName, false);
         }
     }
 

Modified: oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1545778&r1=1545777&r2=1545778&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Tue Nov 26 18:49:12 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1623 JPAService doesn't need to do reads in a transaction (rkanter)
 OOZIE-1612 When printing Dates to log messages, we should make sure they are 
in oozie.processing.timezone (gwenshap via rkanter)
 OOZIE-1519 Admin command to update the sharelib (puru via ryota)
 OOZIE-1604 <java-opts> and <java-opt> not added to Application Master property 
in uber mode (ryota)


Reply via email to