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-2499: Race condition in EntityManagerSource#getEntityManagerFactory
Date Mon, 14 Mar 2016 22:08:16 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 2869383aa -> 940bd2a51


FIXED - TAP5-2499: Race condition in
EntityManagerSource#getEntityManagerFactory 

- if EntityManagerFactory is not found, synchronize on the service
itself, double check the existence of the emf and create and put a new
emf in the map


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

Branch: refs/heads/master
Commit: 940bd2a51df3a96c14da7d1a861f387820b65efe
Parents: 2869383
Author: kaosko <kaosko@apache.org>
Authored: Mon Mar 14 15:08:18 2016 -0700
Committer: kaosko <kaosko@apache.org>
Committed: Mon Mar 14 15:08:18 2016 -0700

----------------------------------------------------------------------
 .../internal/jpa/EntityManagerSourceImpl.java   | 48 ++++++++++++--------
 1 file changed, 30 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/940bd2a5/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
index f7aa979..74f1112 100644
--- a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
+++ b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
@@ -14,6 +14,20 @@
 
 package org.apache.tapestry5.internal.jpa;
 
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceProviderResolver;
+import javax.persistence.spi.PersistenceProviderResolverHolder;
+import javax.persistence.spi.PersistenceUnitInfo;
+
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Mapper;
 import org.apache.tapestry5.func.Predicate;
@@ -24,22 +38,13 @@ import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
-import org.apache.tapestry5.jpa.*;
+import org.apache.tapestry5.jpa.EntityManagerSource;
+import org.apache.tapestry5.jpa.JpaConstants;
+import org.apache.tapestry5.jpa.JpaSymbols;
+import org.apache.tapestry5.jpa.PersistenceUnitConfigurer;
+import org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo;
 import org.slf4j.Logger;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceProviderResolver;
-import javax.persistence.spi.PersistenceProviderResolverHolder;
-import javax.persistence.spi.PersistenceUnitInfo;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
 public class EntityManagerSourceImpl implements EntityManagerSource
 {
     private final Map<String, EntityManagerFactory> entityManagerFactories = CollectionFactory
@@ -185,11 +190,18 @@ public class EntityManagerSourceImpl implements EntityManagerSource
         EntityManagerFactory emf = entityManagerFactories.get(persistenceUnitName);
 
         if (emf == null)
-        {
-            emf = createEntityManagerFactory(persistenceUnitName);
+            synchronized (this)
+            {
+                emf = entityManagerFactories.get(persistenceUnitName);
 
-            entityManagerFactories.put(persistenceUnitName, emf);
-        }
+                if (emf == null)
+                {
+
+                    emf = createEntityManagerFactory(persistenceUnitName);
+
+                    entityManagerFactories.put(persistenceUnitName, emf);
+                }
+            }
 
         return emf;
     }


Mime
View raw message