You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/06/06 13:36:18 UTC

svn commit: r1346832 - in /openejb/trunk/openejb/container/openejb-core/src: main/java/org/apache/openejb/ main/java/org/apache/openejb/config/ main/java/org/apache/openejb/junit/ test/java/org/apache/openejb/config/ test/java/org/apache/openejb/config...

Author: rmannibucau
Date: Wed Jun  6 11:36:17 2012
New Revision: 1346832

URL: http://svn.apache.org/viewvc?rev=1346832&view=rev
Log:
TOMEE-218 skipping resource local @PersistenceContext

Added:
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalCdiEmTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalEmInjectionTest.java
Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientNoInjectionTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/XmlOverridesTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceUnitUsageTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/DynamicDataSourceTest.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java Wed Jun  6 11:36:17 2012
@@ -507,12 +507,12 @@ public class OpenEjbContainer extends EJ
                     } else if (modules instanceof Persistence) {
 
                         final Persistence persistence = (Persistence) modules;
-                        appModule.getPersistenceModules().add(new PersistenceModule("", persistence));
+                        appModule.addPersistenceModule(new PersistenceModule("", persistence));
 
                     } else if (modules instanceof PersistenceUnit) {
 
                         final PersistenceUnit unit = (PersistenceUnit) modules;
-                        appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));
+                        appModule.addPersistenceModule(new PersistenceModule("", new Persistence(unit)));
 
                     } else if (modules instanceof Beans) {
 
@@ -527,7 +527,7 @@ public class OpenEjbContainer extends EJ
                 if (application != null) {
                     final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false);
                     newModule.getClientModules().addAll(appModule.getClientModules());
-                    newModule.getPersistenceModules().addAll(appModule.getPersistenceModules());
+                    newModule.addPersistenceModules(appModule.getPersistenceModules());
                     newModule.getEjbModules().addAll(appModule.getEjbModules());
                     newModule.getConnectorModules().addAll(appModule.getConnectorModules());
                     appModule = newModule;

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Wed Jun  6 11:36:17 2012
@@ -3560,6 +3560,7 @@ public class AnnotationDeployer implemen
                 // dynamic proxy implementation
                 if (clazz.get().isInterface()) {
                     Member member = new FilledMember("em", EntityManager.class, clazz.get());
+
                     buildPersistenceContext(consumer, pcFactory.create(persistenceContext, member), member);
                 }
             }
@@ -4137,6 +4138,31 @@ public class AnnotationDeployer implemen
          * @throws OpenEJBException
          */
         private void buildPersistenceContext(JndiConsumer consumer, PersistenceContextAnn persistenceContext, Member member) throws OpenEJBException {
+            AppModule module = null;
+            if (currentModule.get() instanceof AppModule) {
+                module = (AppModule) currentModule.get();
+            } else if (currentModule.get() instanceof Module) {
+                module = ((Module) currentModule.get()).getAppModule();
+            }
+            if (module != null
+                    && org.apache.openejb.jee.jpa.unit.TransactionType.RESOURCE_LOCAL.equals(module.getTransactionType(persistenceContext.unitName()))) {
+                // should it be in warn level?
+                // IMO no since with CDI it is tempting to do so
+                String name = persistenceContext.unitName();
+                if (name == null || name.isEmpty()) { // search for it
+                    try { // get the first one
+                        name = module.getPersistenceModules().iterator().next()
+                                .getPersistence()
+                                    .getPersistenceUnit().iterator().next().getName();
+                    } catch (Exception e) {
+                        name = "?";
+                    }
+                }
+                logger.info("PersistenceUnit '" + name + "' is a RESOURCE_LOCAL one, " +
+                                        "you'll have to manage @PersistenceContext yourself.");
+                return;
+            }
+
             String refName = persistenceContext.name();
 
             if (refName.length() ==0) {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java Wed Jun  6 11:36:17 2012
@@ -32,6 +32,9 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.jee.jpa.unit.TransactionType;
 
 /**
  * @version $Rev$ $Date$
@@ -47,6 +50,7 @@ public class AppModule implements Deploy
     private final List<ClientModule> clientModules = new ArrayList<ClientModule>();
     private final List<EjbModule> ejbModules = new ArrayList<EjbModule>();
     private final List<PersistenceModule> persistenceModules = new ArrayList<PersistenceModule>();
+    private final Map<String, TransactionType> txTypeByUnit = new HashMap<String, TransactionType>();
     // TODO We could turn this into the Resources JAXB object and support containers and other things as well
     private final Collection<Resource> resources = new HashSet<Resource>();
     private final ClassLoader classLoader;
@@ -83,7 +87,7 @@ public class AppModule implements Deploy
         } else if (type == WebModule.class) {
             getWebModules().add((WebModule) module);
         } else if (type == PersistenceModule.class) {
-            getPersistenceModules().add((PersistenceModule) module);
+            addPersistenceModule((PersistenceModule) module);
         } else {
             throw new IllegalArgumentException("Unknown module type: " + type.getName());
         }
@@ -291,4 +295,33 @@ public class AppModule implements Deploy
     public Collection<String> getJaxRsProviders() {
         return jaxRsProviders;
     }
+
+    public void addPersistenceModule(final PersistenceModule root) {
+        persistenceModules.add(root);
+
+        final Persistence persistence = root.getPersistence();
+        for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
+            txTypeByUnit.put(unit.getName(), unit.getTransactionType());
+        }
+    }
+
+    public void addPersistenceModules(final Collection<PersistenceModule> roots) {
+        for (PersistenceModule root : roots) {
+            addPersistenceModule(root);
+        }
+    }
+
+    public TransactionType getTransactionType(final String unit) {
+        if (unit == null || unit.isEmpty()) {
+            if (txTypeByUnit.size() == 1) {
+                return txTypeByUnit.values().iterator().next();
+            }
+        }
+
+        TransactionType type = txTypeByUnit.get(unit);
+        if (type == null) { // default, shouldn't occur
+            type = TransactionType.JTA;
+        }
+        return type;
+    }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java Wed Jun  6 11:36:17 2012
@@ -172,7 +172,7 @@ public class CmpJpaConversion implements
             persistence.getPersistenceUnit().add(persistenceUnit);
 
             PersistenceModule persistenceModule = new PersistenceModule(getPersistenceModuleId(appModule), persistence);
-            appModule.getPersistenceModules().add(persistenceModule);
+            appModule.addPersistenceModule(persistenceModule);
         }
         return persistenceUnit;
     }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Wed Jun  6 11:36:17 2012
@@ -723,7 +723,7 @@ public class ConfigurationFactory implem
                 collection.getAdditionalLibraries().addAll(module.getAdditionalLibraries());
                 collection.getClientModules().addAll(module.getClientModules());
                 collection.getEjbModules().addAll(module.getEjbModules());
-                collection.getPersistenceModules().addAll(module.getPersistenceModules());
+                collection.addPersistenceModules(module.getPersistenceModules());
                 collection.getConnectorModules().addAll(module.getConnectorModules());
                 collection.getWebModules().addAll(module.getWebModules());
                 collection.getWatchedResources().addAll(module.getWatchedResources());

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/PersistenceModule.java Wed Jun  6 11:36:17 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.openejb.config;
 
+import java.util.HashMap;
+import java.util.List;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 
 import java.io.File;
@@ -23,6 +25,7 @@ import java.net.URI;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.Map;
+import org.apache.openejb.jee.jpa.unit.TransactionType;
 
 public class PersistenceModule implements DeploymentModule {
     private String rootUrl;

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Wed Jun  6 11:36:17 2012
@@ -153,7 +153,7 @@ public class ReadDescriptors implements 
                     if (url && "file".equals(((URL) persistenceUrl).getProtocol())) {
                         persistenceModule.getWatchedResources().add(path);
                     }
-                    appModule.getPersistenceModules().add(persistenceModule);
+                    appModule.addPersistenceModule(persistenceModule);
                 } catch (Exception e1) {
                     DeploymentLoader.logger.error("Unable to load Persistence Unit from EAR: " + appModule.getJarLocation() + ", module: " + moduleName + ". Exception: " + e1.getMessage(), e1);
                 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java Wed Jun  6 11:36:17 2012
@@ -215,12 +215,12 @@ public class ApplicationComposer extends
                 } else if (obj instanceof Persistence) {
 
                     final Persistence persistence = (Persistence) obj;
-                    appModule.getPersistenceModules().add(new PersistenceModule("", persistence));
+                    appModule.addPersistenceModule(new PersistenceModule("", persistence));
 
                 } else if (obj instanceof PersistenceUnit) {
 
                     final PersistenceUnit unit = (PersistenceUnit) obj;
-                    appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));
+                    appModule.addPersistenceModule(new PersistenceModule("", new Persistence(unit)));
 
                 } else if (obj instanceof Beans) {
 
@@ -250,7 +250,7 @@ public class ApplicationComposer extends
             if (application != null) {
                 final AppModule newModule = new AppModule(appModule.getClassLoader(), appModule.getModuleId(), application, false);
                 newModule.getClientModules().addAll(appModule.getClientModules());
-                newModule.getPersistenceModules().addAll(appModule.getPersistenceModules());
+                newModule.addPersistenceModules(appModule.getPersistenceModules());
                 newModule.getEjbModules().addAll(appModule.getEjbModules());
                 newModule.getConnectorModules().addAll(appModule.getConnectorModules());
                 appModule = newModule;

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AutoConfigPersistenceUnitsTest.java Wed Jun  6 11:36:17 2012
@@ -141,7 +141,7 @@ public class AutoConfigPersistenceUnitsT
         unit2.setNonJtaDataSource("LimeUnmanaged");
 
         AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit1, unit2)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(unit1, unit2)));
 
         // Create app
 
@@ -265,7 +265,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, null, "orange-id"));
@@ -302,7 +302,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-id"));
@@ -343,7 +343,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-id"));
@@ -384,7 +384,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
@@ -421,7 +421,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
@@ -462,7 +462,7 @@ public class AutoConfigPersistenceUnitsT
 
         ClassLoader cl = this.getClass().getClassLoader();
         AppModule app = new AppModule(cl, "orange-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
         WebApp webApp = new WebApp();
         webApp.setMetadataComplete(true);
         app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
@@ -1395,7 +1395,7 @@ public class AutoConfigPersistenceUnitsT
         unit.setNonJtaDataSource(nonJtaDataSource);
 
         AppModule app = new AppModule(this.getClass().getClassLoader(), unitName + "-app");
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
 
         // Create app
 

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientNoInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientNoInjectionTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientNoInjectionTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientNoInjectionTest.java Wed Jun  6 11:36:17 2012
@@ -47,7 +47,7 @@ public class LocalClientNoInjectionTest 
         AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
 
         Persistence persistence = new Persistence(new org.apache.openejb.jee.jpa.unit.PersistenceUnit("foo-unit"));
-        app.getPersistenceModules().add(new PersistenceModule("root", persistence));
+        app.addPersistenceModule(new PersistenceModule("root", persistence));
 
         EjbJar ejbJar = new EjbJar();
         ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/LocalClientTest.java Wed Jun  6 11:36:17 2012
@@ -89,7 +89,7 @@ public class LocalClientTest extends Tes
         AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
 
         Persistence persistence = new Persistence(new org.apache.openejb.jee.jpa.unit.PersistenceUnit("foo-unit"));
-        app.getPersistenceModules().add(new PersistenceModule("root", persistence));
+        app.addPersistenceModule(new PersistenceModule("root", persistence));
 
         EjbJar ejbJar = new EjbJar();
         ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/XmlOverridesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/XmlOverridesTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/XmlOverridesTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/XmlOverridesTest.java Wed Jun  6 11:36:17 2012
@@ -98,7 +98,7 @@ public class XmlOverridesTest extends Te
 
         AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
         app.getEjbModules().add(new EjbModule(ejbJar));
-        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(persistenceUnit)));
+        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
 
         AppInfo appInfo = config.configureApplication(app);
 

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceContextUsageTest.java Wed Jun  6 11:36:17 2012
@@ -53,7 +53,7 @@ public class CheckPersistenceContextUsag
         PersistenceUnit pu2 = new PersistenceUnit("fooUnit");
         org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu, pu1, pu2);
         PersistenceModule pm = new PersistenceModule("foo", p);
-        appModule.getPersistenceModules().add(pm);
+        appModule.addPersistenceModule(pm);
         return appModule;
     }
 
@@ -71,7 +71,7 @@ public class CheckPersistenceContextUsag
         PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
         org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
         PersistenceModule pm1 = new PersistenceModule("foo1", p1);
-        appModule.getPersistenceModules().add(pm1);
+        appModule.addPersistenceModule(pm1);
         return appModule;
     }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceUnitUsageTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceUnitUsageTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceUnitUsageTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckPersistenceUnitUsageTest.java Wed Jun  6 11:36:17 2012
@@ -50,7 +50,7 @@ public class CheckPersistenceUnitUsageTe
         PersistenceUnit pu2 = new PersistenceUnit("fooUnit");
         org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu, pu1, pu2);
         PersistenceModule pm = new PersistenceModule("foo", p);
-        appModule.getPersistenceModules().add(pm);
+        appModule.addPersistenceModule(pm);
         return appModule;
     }
 
@@ -68,7 +68,7 @@ public class CheckPersistenceUnitUsageTe
         PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
         org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
         PersistenceModule pm1 = new PersistenceModule("foo1", p1);
-        appModule.getPersistenceModules().add(pm1);
+        appModule.addPersistenceModule(pm1);
         return appModule;
     }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java Wed Jun  6 11:36:17 2012
@@ -350,7 +350,7 @@ public class EntityManagerPropogationTes
         unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
 
         // Add the persistence.xml to the "ear"
-        appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));
+        appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
 
         // Configure and assemble the ear -- aka. deploy it
         AppInfo info = config.configureApplication(appModule);

Added: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalCdiEmTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalCdiEmTest.java?rev=1346832&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalCdiEmTest.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalCdiEmTest.java Wed Jun  6 11:36:17 2012
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.persistence;
+
+import java.util.Properties;
+import javax.ejb.EJB;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import org.apache.openejb.jee.Empty;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.jee.jpa.unit.TransactionType;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(ApplicationComposer.class)
+public class ResourceLocalCdiEmTest {
+    @Inject
+    private PersistManager persistManager;
+
+    @Test
+    public void injection2Validator() {
+        assertNotNull(persistManager);
+        assertTrue(!persistManager.isEmNull());
+    }
+
+    @Configuration
+    public Properties config() {
+        final Properties p = new Properties();
+        p.put("ResourceLocalCdiEmTest", "new://Resource?type=DataSource");
+        p.put("ResourceLocalCdiEmTest.JdbcDriver", "org.hsqldb.jdbcDriver");
+        p.put("ResourceLocalCdiEmTest.JdbcUrl", "jdbc:hsqldb:mem:ResourceLocalCdiEmTest");
+        return p;
+    }
+
+    @Module
+    public Class<?>[] app() throws Exception {
+        return new Class<?>[] { EMFProducer.class, PersistManager.class };
+    }
+
+    @Module
+    public Persistence persistence() {
+        final PersistenceUnit unit = new PersistenceUnit("rl-unit");
+        unit.setTransactionType(TransactionType.RESOURCE_LOCAL);
+        unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+        unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
+        unit.setExcludeUnlistedClasses(true);
+
+        final Persistence persistence = new Persistence(unit);
+        persistence.setVersion("2.0");
+        return persistence;
+    }
+
+    public static class PersistManager {
+        @Inject
+        private EntityManager em;
+
+        public boolean isEmNull() {
+            return em == null;
+        }
+    }
+
+    public static class EMFProducer {
+        @Produces
+        @javax.persistence.PersistenceUnit
+        private EntityManagerFactory emf;
+
+        @Produces
+        private EntityManager em() {
+            return emf.createEntityManager();
+        }
+
+        private void close(@Disposes final EntityManager em) {
+            em.close();
+        }
+    }
+}

Added: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalEmInjectionTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalEmInjectionTest.java?rev=1346832&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalEmInjectionTest.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/persistence/ResourceLocalEmInjectionTest.java Wed Jun  6 11:36:17 2012
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.persistence;
+
+import java.util.Properties;
+import javax.ejb.EJB;
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.apache.openejb.jee.Empty;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.jee.jpa.unit.TransactionType;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(ApplicationComposer.class)
+public class ResourceLocalEmInjectionTest {
+    @EJB
+    private PersistManager persistManager;
+
+    @Test
+    public void injection2Validator() {
+        assertNotNull(persistManager);
+        assertTrue(persistManager.isEmNull());
+    }
+
+    @Configuration
+    public Properties config() {
+        final Properties p = new Properties();
+        p.put("ResourceLocalEmInjectionTest", "new://Resource?type=DataSource");
+        p.put("ResourceLocalEmInjectionTest.JdbcDriver", "org.hsqldb.jdbcDriver");
+        p.put("ResourceLocalEmInjectionTest.JdbcUrl", "jdbc:hsqldb:mem:ResourceLocalEmInjectionTest");
+        return p;
+    }
+
+    @Module
+    public StatelessBean app() throws Exception {
+        final StatelessBean bean = new StatelessBean(PersistManager.class);
+        bean.setLocalBean(new Empty());
+        return bean;
+    }
+
+    @Module
+    public Persistence persistence() {
+        final PersistenceUnit unit = new PersistenceUnit("rl-unit");
+        unit.setTransactionType(TransactionType.RESOURCE_LOCAL);
+        unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+        unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
+        unit.setExcludeUnlistedClasses(true);
+
+        final Persistence persistence = new Persistence(unit);
+        persistence.setVersion("2.0");
+        return persistence;
+    }
+
+    @LocalBean
+    @Stateless
+    public static class PersistManager {
+        @PersistenceContext
+        private EntityManager em;
+
+        public boolean isEmNull() {
+            return em == null;
+        }
+    }
+}

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/DynamicDataSourceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/DynamicDataSourceTest.java?rev=1346832&r1=1346831&r2=1346832&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/DynamicDataSourceTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/DynamicDataSourceTest.java Wed Jun  6 11:36:17 2012
@@ -114,14 +114,14 @@ public class DynamicDataSourceTest {
         unit.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
         unit.setTransactionType(TransactionType.JTA);
         unit.setJtaDataSource("Routed Datasource");
-        appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));
+        appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
         for (int i = 1; i <= 3; i++) {
             PersistenceUnit u = new PersistenceUnit("db" + i);
             u.addClass(Person.class);
             u.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
             u.setTransactionType(TransactionType.JTA);
             u.setJtaDataSource("database" + i);
-            appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(u)));
+            appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(u)));
         }
 
         assembler.createApplication(config.configureApplication(appModule));