openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r772342 - in /incubator/openwebbeans/trunk/webbeans-jpa/src: main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java
Date Wed, 06 May 2009 16:08:13 GMT
Author: gerdogdu
Date: Wed May  6 16:08:13 2009
New Revision: 772342

URL: http://svn.apache.org/viewvc?rev=772342&view=rev
Log:
Updating to create entity manager. In M3 release we will fix the current solution. Currently,
we are creating an extended
manager only.

Modified:
    incubator/openwebbeans/trunk/webbeans-jpa/src/main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java
    incubator/openwebbeans/trunk/webbeans-jpa/src/test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java

Modified: incubator/openwebbeans/trunk/webbeans-jpa/src/main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jpa/src/main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java?rev=772342&r1=772341&r2=772342&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jpa/src/main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-jpa/src/main/java/org/apache/webbeans/jpa/spi/se/JPAServicePersistenceImpl.java
Wed May  6 16:08:13 2009
@@ -13,11 +13,13 @@
  */
 package org.apache.webbeans.jpa.spi.se;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 
-import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.jpa.spi.JPAService;
 import org.apache.webbeans.jpa.spi.se.EntityManagersManager;
 
@@ -28,6 +30,8 @@
 {
     
     public static final String SINGLETON_WEBBEANS_ENTITYMANAGERS_MAP = EntityManagersManager.class.getName();
+    
+    private Map<String, EntityManagerFactory> factoryCache = new ConcurrentHashMap<String,
EntityManagerFactory>();
 
     /**
      * {@inheritDoc}
@@ -35,8 +39,15 @@
      */
     public EntityManagerFactory getPersistenceUnit(String unitName)
     {
+        if(factoryCache.get(unitName) != null)
+        {
+            return factoryCache.get(unitName);
+        }
+        
         //X TODO this currently ignores JNDI
         EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName);
+        
+        factoryCache.put(unitName, emf);
             
         return emf;
     }
@@ -44,19 +55,13 @@
     /** 
      * {@inheritDoc}
      * TODO: currently this returns an extended EntityManager, so we have to wrap it
+     * We have to create a Proxy for injecting entity managers. So, whenever method is called
+     * on the entity managers, look at current Transaction, if exist call joinTransaction();
      */
     public EntityManager getPersistenceContext(String unitName, String name)
     {
-        EntityManagerFactory emf = getPersistenceUnit(unitName);
-        
-        EntityManagersManager entityManagersMgr = (EntityManagersManager) WebBeansFinder.getSingletonInstance(SINGLETON_WEBBEANS_ENTITYMANAGERS_MAP);
-        
-        EntityManager em = entityManagersMgr.get(unitName, name);
-        if (em == null)
-        {
-            em = emf.createEntityManager();
-            entityManagersMgr.set(unitName, name, em);
-        }
+        EntityManagerFactory emf = getPersistenceUnit(unitName);        
+        EntityManager em = emf.createEntityManager();
         
         return em;
     }

Modified: incubator/openwebbeans/trunk/webbeans-jpa/src/test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jpa/src/test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java?rev=772342&r1=772341&r2=772342&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jpa/src/test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-jpa/src/test/java/org/apache/webbeans/test/unittests/resource/ResourceInjectionTest.java
Wed May  6 16:08:13 2009
@@ -65,7 +65,7 @@
         EntityManager em2 = persBean.getFieldInjectedEntityManager2();
         Assert.assertNotNull(em2);
 
-        Assert.assertTrue(em != em2);
+        Assert.assertTrue(em == em2);
         
         // test method injection
         EntityManagerFactory emf2 = persBean.getMethodInjectedEntityManagerFactory();



Mime
View raw message