tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1207802 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence: JtaEntityManager.java JtaQuery.java JtaTypedQuery.java
Date Tue, 29 Nov 2011 09:24:04 GMT
Author: rmannibucau
Date: Tue Nov 29 09:24:03 2011
New Revision: 1207802

URL: http://svn.apache.org/viewvc?rev=1207802&view=rev
Log:
OPENEJB-1443 we should be able to call jpa method which doesn't need a transaction twice in
 a method

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaQuery.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaTypedQuery.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java?rev=1207802&r1=1207801&r2=1207802&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
Tue Nov 29 09:24:03 2011
@@ -73,11 +73,11 @@ public class JtaEntityManager implements
         logger = (unitName == null) ? baseLogger : baseLogger.getChildLogger(unitName);
     }
 
-    private EntityManager getEntityManager() {
+    EntityManager getEntityManager() {
         return registry.getEntityManager(entityManagerFactory, properties, extended, unitName);
     }
 
-    private boolean isTransactionActive() {
+    boolean isTransactionActive() {
         return registry.isTransactionActive();
     }
 
@@ -98,7 +98,7 @@ public class JtaEntityManager implements
      * for the operation and then closed.
      * @param entityManager the entity manager to close if non-extended and a transaction
is not active
      */
-    private void closeIfNoTx(EntityManager entityManager) {
+    void closeIfNoTx(EntityManager entityManager) {
         if (!extended && !isTransactionActive()) {
             entityManager.close();
             logger.debug("Closed EntityManager(unit=" + unitName + ", hashCode=" + entityManager.hashCode()
+ ")");
@@ -310,14 +310,14 @@ public class JtaEntityManager implements
 
     private Query proxyIfNoTx(EntityManager entityManager, Query query) {
         if (!extended && !isTransactionActive()) {
-            return new JtaQuery(entityManager, query);
+            return new JtaQuery(entityManager, this, query);
         }
         return query;
     }
     
     private <T> TypedQuery<T> proxyIfNoTx(EntityManager entityManager, TypedQuery<T>
query) {
         if (!extended && !isTransactionActive()) {
-            return new JtaTypedQuery<T>(entityManager, query);
+            return new JtaTypedQuery<T>(entityManager, this, query);
         }
         return query;
     }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaQuery.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaQuery.java?rev=1207802&r1=1207801&r2=1207802&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaQuery.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaQuery.java
Tue Nov 29 09:24:03 2011
@@ -34,34 +34,47 @@ import java.util.Set;
  */
 public class JtaQuery implements Query {
     private final EntityManager entityManager;
+    private final JtaEntityManager jtaEntityManager;
     private final Query query;
 
-    public JtaQuery(EntityManager entityManager, Query query) {
+    public JtaQuery(EntityManager entityManager, JtaEntityManager jtaEntityManager, Query
query) {
         this.entityManager = entityManager;
+        this.jtaEntityManager = jtaEntityManager;
         this.query = query;
     }
 
+    private EntityManager getEntityManager() {
+        EntityManager em = entityManager;
+        if (!jtaEntityManager.isTransactionActive()) {
+            em = jtaEntityManager.getEntityManager();
+        }
+        return em;
+    }
+
     public List getResultList() {
+        final EntityManager em = getEntityManager();
         try {
             return query.getResultList();
         } finally {
-            entityManager.close();
+            jtaEntityManager.closeIfNoTx(em);
         }
     }
 
     public Object getSingleResult() {
+        final EntityManager em = getEntityManager();
         try {
             return query.getSingleResult();
         } finally {
-            entityManager.close();
+            jtaEntityManager.closeIfNoTx(em);
         }
     }
 
     public int executeUpdate() {
+        final EntityManager em = getEntityManager();
         try {
             return query.executeUpdate();
         } finally {
-            entityManager.close();
+            jtaEntityManager.closeIfNoTx(em);
         }
     }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaTypedQuery.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaTypedQuery.java?rev=1207802&r1=1207801&r2=1207802&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaTypedQuery.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaTypedQuery.java
Tue Nov 29 09:24:03 2011
@@ -34,8 +34,8 @@ import java.util.List;
  */
 public class JtaTypedQuery<X> extends JtaQuery implements TypedQuery<X> {
 
-    public JtaTypedQuery(EntityManager entityManager, Query query) {
-        super(entityManager, query);
+    public JtaTypedQuery(EntityManager entityManager, JtaEntityManager jtaEm, Query query)
{
+        super(entityManager, jtaEm, query);
     }
 
     @SuppressWarnings("unchecked")



Mime
View raw message