[jboss-cvs] JBossAS SVN: r68757 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src: main/org/jboss/ejb3/deployers and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 9 15:56:12 EST 2008


Author: bdecoste
Date: 2008-01-09 15:56:12 -0500 (Wed, 09 Jan 2008)
New Revision: 68757

Added:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/application.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/sharedEntityApplication.xml
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceBean.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceRemote.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/PersistenceUnitScopeTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/SharedEntityTestCase.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/JmxDeploymentUnit.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java
Log:
[JBPAPP-520] fixed persistence.xml scope at .ear level 

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -132,7 +132,14 @@
 
    public static boolean hasPersistenceXml(DeploymentInfo di)
    {
-      return hasFile(di, "META-INF/persistence.xml");
+      DeploymentInfo parent = di.parent;
+     
+      boolean hasLocalPersistenceXml = hasFile(di, "META-INF/persistence.xml");
+      if (!hasLocalPersistenceXml && parent != null)
+      {
+         return hasFile(parent, "META-INF/persistence.xml");
+      }
+      return hasLocalPersistenceXml;
    }
 
    public static boolean has30EjbJarXml(DeploymentInfo di)

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -49,6 +49,7 @@
 
 import org.hibernate.cfg.EJB3DTDEntityResolver;
 import org.hibernate.ejb.packaging.PersistenceMetadata;
+import org.jboss.deployment.DeploymentInfo;
 import org.jboss.ejb3.enc.EjbModuleEjbResolver;
 import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
@@ -514,7 +515,7 @@
    {
       URL persistenceXmlUrl = null;
       persistenceXmlUrl = unit.getPersistenceXml();
- 
+       
       hasEntities = persistenceXmlUrl != null;
 
       if (!hasEntities) return;

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/JmxDeploymentUnit.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/JmxDeploymentUnit.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/JmxDeploymentUnit.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -148,7 +148,14 @@
 
    public URL getPersistenceXml()
    {
-      return extractDescriptorUrl("META-INF/persistence.xml");
+      URL url = extractDescriptorUrl("META-INF/persistence.xml");
+        
+      if (url == null && this.deploymentInfo.parent != null)
+      {
+         url = this.deploymentInfo.parent.localCl.findResource("META-INF/persistence.xml");
+      }
+    
+      return url;
    }
 
    public URL getEjbJarXml()

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/deployers/JBoss5DeploymentUnit.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -30,7 +30,9 @@
 import java.util.Map;
 
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.ejb3.EJB3Deployer;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.logging.Logger;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.VisitorAttributes;
@@ -46,6 +48,8 @@
  */
 public class JBoss5DeploymentUnit implements org.jboss.ejb3.DeploymentUnit
 {
+   private final static Logger log = Logger.getLogger(JBoss5DeploymentUnit.class);
+   
    private DeploymentUnit unit;
    private InterceptorInfoRepository interceptorInfoRepository = new InterceptorInfoRepository();
    private Map defaultPersistenceProperties;

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/application.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/application.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/application.xml	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
+
+<application>
+  <display-name>EAR test</display-name>
+  
+  <module>
+    <ejb>lib/persistenceunitscope.jar</ejb>
+  </module>
+</application>
+
+

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/sharedEntityApplication.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/sharedEntityApplication.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/sharedEntityApplication.xml	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
+
+<application>
+  <display-name>EAR test</display-name>
+  
+  <module>
+    <ejb>lib/persistenceunitsharedentity1.jar</ejb>
+  </module>
+  
+  <module>
+    <ejb>lib/persistenceunitsharedentity2.jar</ejb>
+  </module>
+</application>
+
+

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -22,6 +22,8 @@
 package org.jboss.ejb3.test.persistenceunits;
 
 import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -32,8 +34,13 @@
  */
 @Entity
 @Table(name = "ENTITY1")
+ at NamedQueries({
+ @NamedQuery(name = "findAll", query = "from Entity1") 
+ })
 public class Entity1 implements java.io.Serializable
 {
+   public static final String FIND_ALL = "findAll";
+
    private Long id;
    private String data;
 

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -31,4 +31,6 @@
    Entity1 loadEntity1(Long id);
    Long persistEntity2(Entity2 entity2);
    Entity2 loadEntity2(Long id);
+   
+   void testSharedEntity();
 }

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java	2008-01-09 20:51:37 UTC (rev 68756)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.test.persistenceunits;
 
+import java.util.List;
+
 import org.jboss.logging.Logger;
 
 import javax.ejb.Remote;
@@ -61,4 +63,21 @@
    {
       return manager2.find(Entity2.class, id);
    }
+   
+   public void testSharedEntity()
+   {
+      Entity1 entity = new Entity1();
+      entity.setData("TestShared1");
+      manager1.persist(entity);
+      
+      entity = new Entity1();
+      entity.setData("TestShared2");
+      manager1.persist(entity);
+
+      List<Entity1> result = manager1.createNamedQuery(Entity1.FIND_ALL).getResultList();
+      for (Entity1 e : result)
+      {
+          log.info("*** testSharedEntity result=" + e.getData());
+      }
+   }
 }

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceBean.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.persistenceunits;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.annotation.ejb.Service;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Service
+ at Remote(ServiceRemote.class)
+public class ServiceBean implements ServiceRemote
+{
+   private static final Logger log = Logger.getLogger(ServiceBean.class);
+   
+   @PersistenceContext(unitName = "Entity1")
+   private EntityManager manager;
+   
+   public void testSharedEntity()
+   {
+      Entity1 entity = new Entity1();
+      entity.setData("TestShared3");
+      manager.persist(entity);
+      
+      entity = new Entity1();
+      entity.setData("TestShared4");
+      manager.persist(entity);
+
+      List<Entity1> result = manager.createNamedQuery(Entity1.FIND_ALL).getResultList();
+      for (Entity1 e : result)
+      {
+         log.info("*** testSharedEntity result=" + e.getData());
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceRemote.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/ServiceRemote.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.persistenceunits;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface ServiceRemote
+{
+   void testSharedEntity();
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/PersistenceUnitScopeTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/PersistenceUnitScopeTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/PersistenceUnitScopeTestCase.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.persistenceunits.unit;
+
+import org.jboss.ejb3.test.persistenceunits.Entity1;
+import org.jboss.ejb3.test.persistenceunits.Entity2;
+import org.jboss.ejb3.test.persistenceunits.EntityTest;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class PersistenceUnitScopeTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(EntityUnitTestCase.class);
+
+   public PersistenceUnitScopeTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testScope() throws Exception
+   {
+      EntityTest test = (EntityTest) getInitialContext().lookup("persistenceunitscope-test/EntityTestBean/remote");
+      
+      Entity1 entity1 = new Entity1();
+      entity1.setData("ONE");
+      Long id1 = test.persistEntity1(entity1);
+      
+      Entity2 entity2 = new Entity2();
+      entity2.setData("TWO");
+      Long id2 = test.persistEntity2(entity2);
+      
+      entity1 = test.loadEntity1(id1);
+      assertEquals("ONE", entity1.getData());
+      
+      entity2 = test.loadEntity2(id2);
+      assertEquals("TWO", entity2.getData());
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(PersistenceUnitScopeTestCase.class, "persistenceunitscope-test.ear");
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/SharedEntityTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/SharedEntityTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/SharedEntityTestCase.java	2008-01-09 20:56:12 UTC (rev 68757)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.persistenceunits.unit;
+
+import org.jboss.ejb3.test.persistenceunits.EntityTest;
+import org.jboss.ejb3.test.persistenceunits.ServiceRemote;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class SharedEntityTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(SharedEntityTestCase.class);
+
+   public SharedEntityTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSharedEntity() throws Exception
+   {
+      EntityTest test = (EntityTest) getInitialContext().lookup("persistenceunitsharedentity-test/EntityTestBean/remote");
+      test.testSharedEntity();
+      
+      ServiceRemote service = (ServiceRemote) getInitialContext().lookup("persistenceunitsharedentity-test/ServiceBean/remote");
+      service.testSharedEntity();
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(SharedEntityTestCase.class, "persistenceunitsharedentity-test.ear");
+   }
+
+}




More information about the jboss-cvs-commits mailing list