airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: making entity manager thread safe
Date Thu, 10 Nov 2016 17:49:09 GMT
Repository: airavata
Updated Branches:
  refs/heads/develop 3fa3c3f63 -> 6a73db2fd


making entity manager thread safe


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/6a73db2f
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/6a73db2f
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/6a73db2f

Branch: refs/heads/develop
Commit: 6a73db2fd29595e62354cb394b755de3cc79ca4b
Parents: 3fa3c3f
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Thu Nov 10 12:49:04 2016 -0500
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Thu Nov 10 12:49:04 2016 -0500

----------------------------------------------------------------------
 .../airavata/sharing/registry/db/utils/JPAUtils.java    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/6a73db2f/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
index f879c15..ee0cce4 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
@@ -58,6 +58,11 @@ public class JPAUtils {
     private static String jdbcUser;
     private static String jdbcPassword;
 
+    private static final ThreadLocal<EntityManager> threadLocal;
+    static {
+        threadLocal = new ThreadLocal<EntityManager>();
+    }
+
 
     @PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME)
     protected static EntityManagerFactory factory;
@@ -96,7 +101,12 @@ public class JPAUtils {
             properties.put("openjpa.RuntimeUnenhancedClasses", "warn");
             factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
         }
-        entityManager = factory.createEntityManager();
+
+        entityManager = threadLocal.get();
+        if(entityManager == null){
+            entityManager = factory.createEntityManager();
+            threadLocal.set(entityManager);
+        }
         return entityManager;
     }
 


Mime
View raw message