tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kao...@apache.org
Subject tapestry-5 git commit: FIXED - TAP5-2027: EntityManagerObjectProvider always provides the initial EntityManger proxy created
Date Tue, 15 Mar 2016 05:59:21 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 940bd2a51 -> 0acf94ae0


FIXED - TAP5-2027: EntityManagerObjectProvider always provides the
initial EntityManger proxy created

- change the proxy member from a single instance EntityManager to a map
- refactor getOrCreateProxy: unsynchronize access to the map and only
make modifying the map synchronized
- candidate for merging to T5.3, issue was originally opened against
that version


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/0acf94ae
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/0acf94ae
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/0acf94ae

Branch: refs/heads/master
Commit: 0acf94ae073b321ec8579092c0324745ff235c05
Parents: 940bd2a
Author: kaosko <kaosko@apache.org>
Authored: Mon Mar 14 22:59:21 2016 -0700
Committer: kaosko <kaosko@apache.org>
Committed: Mon Mar 14 22:59:21 2016 -0700

----------------------------------------------------------------------
 .../jpa/EntityManagerObjectProvider.java        | 52 +++++++++++---------
 1 file changed, 29 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/0acf94ae/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java
b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java
index bb2f9ae..ae91fea 100644
--- a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java
+++ b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerObjectProvider.java
@@ -14,6 +14,12 @@
 
 package org.apache.tapestry5.internal.jpa;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
 import org.apache.tapestry5.ioc.AnnotationProvider;
 import org.apache.tapestry5.ioc.ObjectCreator;
 import org.apache.tapestry5.ioc.ObjectLocator;
@@ -21,13 +27,9 @@ import org.apache.tapestry5.ioc.ObjectProvider;
 import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
 import org.apache.tapestry5.jpa.EntityManagerManager;
 
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
 public class EntityManagerObjectProvider implements ObjectProvider
 {
-
-    private EntityManager proxy;
+    private Map<String, EntityManager> emProxyByName = new HashMap<String, EntityManager>();
 
     @Override
     public <T> T provide(final Class<T> objectType, final AnnotationProvider
annotationProvider,
@@ -39,29 +41,33 @@ public class EntityManagerObjectProvider implements ObjectProvider
         return null;
     }
 
-    private synchronized EntityManager getOrCreateProxy(
-            final AnnotationProvider annotationProvider, final ObjectLocator objectLocator)
+    @SuppressWarnings(
+    { "unchecked", "rawtypes" })
+    private EntityManager getOrCreateProxy(final AnnotationProvider annotationProvider,
+            final ObjectLocator objectLocator)
     {
+        final PersistenceContext annotation = annotationProvider
+                .getAnnotation(PersistenceContext.class);
+        EntityManager proxy = emProxyByName.get(annotation.unitName());
         if (proxy == null)
-        {
-            final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory",
-                    PlasticProxyFactory.class);
-
-            final PersistenceContext annotation = annotationProvider
-                    .getAnnotation(PersistenceContext.class);
-
-            proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator()
+            synchronized (this)
             {
-                @Override
-                public Object createObject()
+                final PlasticProxyFactory proxyFactory = objectLocator.getService(
+                        "PlasticProxyFactory", PlasticProxyFactory.class);
+
+                proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator()
                 {
-                    final EntityManagerManager entityManagerManager = objectLocator
-                            .getService(EntityManagerManager.class);
+                    @Override
+                    public Object createObject()
+                    {
+                        final EntityManagerManager entityManagerManager = objectLocator
+                                .getService(EntityManagerManager.class);
 
-                    return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
-                }
-            }, "<EntityManagerProxy>");
-        }
+                        return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
+                    }
+                }, "<EntityManagerProxy>");
+                emProxyByName.put(annotation.unitName(), proxy);
+            }
 
         return proxy;
     }


Mime
View raw message