[jboss-cvs] JBossAS SVN: r96883 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/main/org/jboss/ejb3 and 14 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 24 13:34:36 EST 2009
Author: jaikiran
Date: 2009-11-24 13:34:35 -0500 (Tue, 24 Nov 2009)
New Revision: 96883
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/META-INF/persistence.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/application.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/persistence.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/application.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/persistence.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Dummy.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Entity1.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SLSBRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SimpleSLSB.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/unit/NestedJarInPersistenceUnitTestCase.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Book.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManager.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManagerBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/User.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManager.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManagerBean.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
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/Ejb3Module.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/MultipleEarTestCase.java
Log:
JBPAPP-3121 Fix added to allow persistence.xml to be deployed from .ear/META-INF. Also fixes the issue with nested jars in a persistence unit jar as reported in JBPAPP-1307
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-11-24 18:25:32 UTC (rev 96882)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -2681,6 +2681,60 @@
<include name="persistenceunitsharedentity2.jar"/>
</zipfileset>
</ear>
+
+ <!-- Build the book manager application ear -->
+ <!-- first the entity jar file -->
+ <jar jarfile="${build.lib}/bookmanager-entities.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/persistenceunits/Book.class"/>
+ </fileset>
+ </jar>
+ <!-- the ejbs -->
+ <jar jarfile="${build.lib}/bookmanager-beans.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/persistenceunits/BookManager.class"/>
+ <include name="org/jboss/ejb3/test/persistenceunits/BookManagerBean.class"/>
+ </fileset>
+ </jar>
+ <!-- finally collect them in a ear -->
+ <ear earfile="${build.lib}/bookmanager.ear" appxml="${resources}/test/persistenceunits/bookmanager/META-INF/application.xml">
+ <zipfileset dir="${build.lib}" prefix="lib">
+ <include name="bookmanager-entities.jar"/>
+ </zipfileset>
+ <zipfileset dir="${build.lib}">
+ <include name="bookmanager-beans.jar"/>
+ </zipfileset>
+ <zipfileset dir="${resources}/test/persistenceunits/bookmanager/META-INF" prefix="META-INF">
+ <include name="persistence.xml"/>
+ </zipfileset>
+ </ear>
+
+ <!-- Build the user manager application ear -->
+ <!-- first the entity jar file -->
+ <jar jarfile="${build.lib}/usermanager-entities.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/persistenceunits/User.class"/>
+ </fileset>
+ </jar>
+ <!-- the ejbs -->
+ <jar jarfile="${build.lib}/usermanager-beans.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/persistenceunits/UserManager.class"/>
+ <include name="org/jboss/ejb3/test/persistenceunits/UserManagerBean.class"/>
+ </fileset>
+ </jar>
+ <!-- finally collect them in a ear -->
+ <ear earfile="${build.lib}/usermanager.ear" appxml="${resources}/test/persistenceunits/usermanager/META-INF/application.xml">
+ <zipfileset dir="${build.lib}" prefix="lib">
+ <include name="usermanager-entities.jar"/>
+ </zipfileset>
+ <zipfileset dir="${build.lib}">
+ <include name="usermanager-beans.jar"/>
+ </zipfileset>
+ <zipfileset dir="${resources}/test/persistenceunits/usermanager/META-INF" prefix="META-INF">
+ <include name="persistence.xml"/>
+ </zipfileset>
+ </ear>
</target>
<target name="externalpersistenceunit"
@@ -2701,7 +2755,35 @@
</fileset>
</jar>
</target>
+
+ <target name="jbpapp1307"
+ description="Builds jar files required for testing JBPAPP-1307."
+ depends="compile-classes">
+ <mkdir dir="${build.lib}"/>
+
+ <!-- Build a dummy jar file to be used as a nested jar in a persistence
+ unit jar -->
+ <jar jarfile="${build.lib}/jbpapp-1307-dummy.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/jbpapp1307/Dummy.class"/>
+ </fileset>
+ </jar>
+
+ <jar jarfile="${build.lib}/jbpapp1307.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/jbpapp1307/*.class"/>
+ </fileset>
+ <fileset dir="${resources}/test/jbpapp1307">
+ <include name="META-INF/persistence.xml"/>
+ </fileset>
+ <fileset dir="${build.lib}">
+ <include name="jbpapp-1307-dummy.jar"/>
+ </fileset>
+
+ </jar>
+ </target>
+
<target name="mdbtransactions"
description="Builds all jar files."
depends="compile-classes">
@@ -3929,7 +4011,7 @@
entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob, cache, initial,
timer, benchmark, entity, joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression,
composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc,
- localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor"/>
+ localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor, jbpapp1307"/>
<target name="test" depends="init" if="test"
description="Execute all tests in the given test directory.">
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 2009-11-24 18:25:32 UTC (rev 96882)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -97,7 +97,8 @@
*/
public EJB3Deployer()
{
- setSuffixes(new String[]{".jar", ".ejb3", ".par"});
+ // we look for .ear too, for META-INF/persistence.xml
+ setSuffixes(new String[]{".jar", ".ejb3", ".par", ".ear"});
setRelativeOrder(400); // before old EJB 2.1 deployer
}
@@ -136,10 +137,10 @@
DeploymentInfo parent = di.parent;
boolean hasLocalPersistenceXml = hasFile(di, "META-INF/persistence.xml");
- if (!hasLocalPersistenceXml && parent != null)
- {
- return hasFile(parent, "META-INF/persistence.xml");
- }
+// if (!hasLocalPersistenceXml && parent != null)
+// {
+// return hasFile(parent, "META-INF/persistence.xml");
+// }
return hasLocalPersistenceXml;
}
@@ -258,6 +259,16 @@
{
return true;
}
+ // we also accept (only those) .ear which have META-INF/persistence.xml
+ if (urlStr.endsWith(".ear") || urlStr.endsWith(".ear/"))
+ {
+ if (hasPersistenceXml(di))
+ {
+ return true;
+ }
+ return false;
+ }
+
// To be accepted the deployment's root name must end in jar
if (!urlStr.endsWith(".jar") && !urlStr.endsWith(".jar/"))
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java 2009-11-24 18:25:32 UTC (rev 96882)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -59,6 +59,22 @@
}
}
}
+ // if this is the top level .ear file
+ else
+ {
+ if (di.shortName.endsWith(".ear") || di.shortName.endsWith(".ear/"))
+ {
+ synchronized(di.context)
+ {
+ deploymentScope = (DeploymentScope)di.context.get("EJB3_EAR_METADATA");
+ if (deploymentScope == null)
+ {
+ deploymentScope = new JmxDeploymentScopeImpl(di.shortName);
+ di.context.put("EJB3_EAR_METADATA", deploymentScope);
+ }
+ }
+ }
+ }
deployment = new Ejb3JmxDeployment(di, deploymentScope);
if (deploymentScope != null)
{
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java 2009-11-24 18:25:32 UTC (rev 96882)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -21,16 +21,19 @@
*/
package org.jboss.ejb3.enc;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-import org.jboss.ejb3.DeploymentScope;
-import org.jboss.ejb3.Ejb3Deployment;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Set;
import org.jboss.logging.Logger;
import javax.naming.NameNotFoundException;
-import java.util.List;
-import java.util.LinkedHashMap;
+import org.jboss.ejb3.DeploymentScope;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.PersistenceUnitRegistry;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+
/**
* Resolves persistence units for @PersistenceContext and @PersistenceUnit
*
@@ -106,15 +109,49 @@
if (rtn != null)
return rtn;
+ Set<PersistenceUnitDeployment> possibleMatches = new HashSet<PersistenceUnitDeployment>();
for (PersistenceUnitDeployment deployment : PersistenceUnitRegistry.getPersistenceUnits())
{
if (deployment.isScoped()) continue;
if (deployment.getEntityManagerName().equals(unitName))
{
- if (deploymentScope == null || deployment.getKernelName().contains(deploymentScope.getBaseName())) return deployment;
+ possibleMatches.add(deployment);
}
}
- return rtn;
+ if (possibleMatches.isEmpty())
+ {
+ log.debug("No matching persistence unit with name " + unitName + " found");
+ return null;
+ }
+ // if only one persistence unit was found then just return it
+ if (possibleMatches.size() == 1)
+ {
+ return possibleMatches.iterator().next();
+ }
+ log.debug("Multiple persistence units with name " + unitName + " found. Will narrow down based on scope");
+ // if multiple persistence units were found, then identify the right one
+ // based on scope (JBPAPP-604)
+ for (PersistenceUnitDeployment deployment : possibleMatches)
+ {
+ // 1) get the ear to which the persistence unit belongs to
+ DeploymentScope persistenceDeploymentScope = deployment.getDeployment().getEar();
+ if (deploymentScope == null)
+ {
+ log.debug("Persistence unit deployment " + deployment.getKernelName() + " identified as the best match");
+ return deployment;
+ }
+ // check if the persistence unit deployment scope matches the scope of
+ // this resolver
+ else if (persistenceDeploymentScope != null
+ && persistenceDeploymentScope.getBaseName().equals(deploymentScope.getBaseName()))
+ {
+ log.debug("Persistence unit deployment " + deployment.getKernelName() + " identified as the best match");
+ return deployment;
+ }
+
+ }
+
+ return null;
}
public PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/META-INF/persistence.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/META-INF/persistence.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/jbpapp1307/META-INF/persistence.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+ <persistence-unit name="jbpapp1307-PU">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ </properties>
+ <class>org.jboss.ejb3.test.jbpapp1307.Entity1</class>
+ </persistence-unit>
+
+</persistence>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/application.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/application.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/application.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,13 @@
+<?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>Book Manager</display-name>
+
+ <module>
+ <ejb>bookmanager-beans.jar</ejb>
+ </module>
+
+</application>
+
+
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/persistence.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/persistence.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/bookmanager/META-INF/persistence.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+ <persistence-unit name="same-name-pu">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ </properties>
+ <class>org.jboss.ejb3.test.persistenceunits.Book</class>
+ </persistence-unit>
+</persistence>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/application.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/application.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/application.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,13 @@
+<?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>User Manager</display-name>
+
+ <module>
+ <ejb>usermanager-beans.jar</ejb>
+ </module>
+
+</application>
+
+
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/persistence.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/persistence.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/persistenceunits/usermanager/META-INF/persistence.xml 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+ <persistence-unit name="same-name-pu">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ </properties>
+ <class>org.jboss.ejb3.test.persistenceunits.User</class>
+ </persistence-unit>
+</persistence>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Dummy.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Dummy.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Dummy.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,33 @@
+/*
+ * 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.jbpapp1307;
+
+/**
+ * Dummy
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class Dummy
+{
+ //does nothing
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Entity1.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Entity1.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/Entity1.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,71 @@
+/*
+ * 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.jbpapp1307;
+
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Entity1
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Entity
+ at 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;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+ public void setData(String data)
+ {
+ this.data = data;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SLSBRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SLSBRemote.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SLSBRemote.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,43 @@
+/*
+ * 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.jbpapp1307;
+
+import java.util.List;
+
+
+
+/**
+ * SLSBRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface SLSBRemote
+{
+
+ public static final String JNDI_NAME = "jbpapp1307-SimpleSLSB";
+
+ public List<Entity1> getAllEntities();
+
+ public Entity1 createNewEntity(String data);
+
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SimpleSLSB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SimpleSLSB.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/SimpleSLSB.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,61 @@
+/*
+ * 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.jbpapp1307;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.annotation.ejb.RemoteBinding;
+
+
+/**
+ * SimpleSLSB
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote (SLSBRemote.class)
+ at RemoteBinding(jndiBinding = SLSBRemote.JNDI_NAME)
+public class SimpleSLSB implements SLSBRemote
+{
+
+ @PersistenceContext (unitName="jbpapp1307-PU")
+ private EntityManager emOne;
+
+ public List<Entity1> getAllEntities()
+ {
+ List<Entity1> result = this.emOne.createNamedQuery(Entity1.FIND_ALL).getResultList();
+ return result;
+ }
+
+ public Entity1 createNewEntity(String data)
+ {
+ Entity1 e1 = new Entity1();
+ e1.setData(data);
+ this.emOne.persist(e1);
+ return e1;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/unit/NestedJarInPersistenceUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/unit/NestedJarInPersistenceUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1307/unit/NestedJarInPersistenceUnitTestCase.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,83 @@
+/*
+ * 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.jbpapp1307.unit;
+
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.jbpapp1224.DefaultedServiceRemote;
+import org.jboss.ejb3.test.jbpapp1224.unit.DefaultedMBeanUnitTestCase;
+import org.jboss.ejb3.test.jbpapp1307.Entity1;
+import org.jboss.ejb3.test.jbpapp1307.SLSBRemote;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * NestedJarInPersistenceUnitTestCase
+ *
+ * Tests that if a persistence unit jar contains a nested jar, then the
+ * deployment works successfully and the persistence unit is usable.
+ * This is related to https://jira.jboss.org/jira/browse/JBPAPP-1307
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NestedJarInPersistenceUnitTestCase extends JBossTestCase
+{
+
+ /**
+ * Constructor
+ * @param name
+ */
+ public NestedJarInPersistenceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test that the deployment of a persistence unit jar with a nested
+ * jar works successfully and operations on the persistence unit
+ * work as expected
+ *
+ * @throws Exception
+ */
+ public void testPersistenceUnitDeployment() throws Exception
+ {
+ SLSBRemote bean = (SLSBRemote) getInitialContext().lookup(SLSBRemote.JNDI_NAME);
+ String data = "testOne";
+ bean.createNewEntity("testOne");
+ List<Entity1> entities = bean.getAllEntities();
+ assertNotNull("Entities list was null", entities);
+ assertEquals("Unexpected number of entities returned", 1, entities.size());
+ Entity1 entity = entities.get(0);
+ assertEquals("Unexpected entity returned", data, entity.getData());
+
+ }
+
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(NestedJarInPersistenceUnitTestCase.class, "jbpapp1307.jar");
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Book.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Book.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Book.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,72 @@
+/*
+ * 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.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Book
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Entity
+ at Table(name = "book")
+ at NamedQueries(
+{@NamedQuery(name = "findAll", query = "from Book")})
+public class Book implements Serializable
+{
+ public static final String FIND_ALL = "findAll";
+
+ private Long id;
+ private String name;
+
+ @Id
+ @GeneratedValue(strategy= GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManager.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManager.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManager.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * BookManager
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface BookManager
+{
+ public static final String JNDI_NAME = "BookManagerBean";
+
+ Book addBook(String name);
+
+ List<Book> getBooks();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManagerBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManagerBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/BookManagerBean.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -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.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+
+
+/**
+ * BookManagerBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote (BookManager.class)
+ at RemoteBinding(jndiBinding = BookManager.JNDI_NAME)
+public class BookManagerBean implements BookManager
+{
+
+ @PersistenceContext (unitName="same-name-pu")
+ private EntityManager em;
+
+ public Book addBook(String name)
+ {
+ Book book = new Book();
+ book.setName(name);
+ this.em.persist(book);
+ return book;
+ }
+
+ public List<Book> getBooks()
+ {
+ return this.em.createNamedQuery(Book.FIND_ALL).getResultList();
+ }
+
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/User.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/User.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/User.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,72 @@
+/*
+ * 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.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+/**
+ * User
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Entity
+ at Table(name = "USER_PROFILE")
+ at NamedQueries(
+{@NamedQuery(name = "findAll", query = "from User")})
+public class User implements Serializable
+{
+ public static final String FIND_ALL = "findAll";
+
+ private Long id;
+ private String name;
+
+ @Id
+ @GeneratedValue(strategy= GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManager.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManager.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManager.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * UserManager
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface UserManager
+{
+
+ public static final String JNDI_NAME = "UserManagerBean";
+
+ User addUser(String name);
+
+ List<User> getUsers();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManagerBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManagerBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/UserManagerBean.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -0,0 +1,60 @@
+/*
+ * 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.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.jboss.annotation.ejb.RemoteBinding;
+
+/**
+ * UserManagerBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote (UserManager.class)
+ at RemoteBinding(jndiBinding = UserManager.JNDI_NAME)
+public class UserManagerBean implements UserManager
+{
+
+ @PersistenceContext (unitName="same-name-pu")
+ private EntityManager em;
+
+ public User addUser(String name)
+ {
+ User user = new User();
+ user.setName(name);
+ this.em.persist(user);
+ return user;
+ }
+
+ public List<User> getUsers()
+ {
+ return this.em.createNamedQuery(User.FIND_ALL).getResultList();
+ }
+
+}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/MultipleEarTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/MultipleEarTestCase.java 2009-11-24 18:25:32 UTC (rev 96882)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/MultipleEarTestCase.java 2009-11-24 18:34:35 UTC (rev 96883)
@@ -21,12 +21,19 @@
*/
package org.jboss.ejb3.test.persistenceunits.unit;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.persistenceunits.Book;
+import org.jboss.ejb3.test.persistenceunits.BookManager;
import org.jboss.ejb3.test.persistenceunits.Entity1;
import org.jboss.ejb3.test.persistenceunits.Entity2;
import org.jboss.ejb3.test.persistenceunits.EntityTest;
+import org.jboss.ejb3.test.persistenceunits.User;
+import org.jboss.ejb3.test.persistenceunits.UserManager;
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>
@@ -60,21 +67,71 @@
assertEquals("TWO", entity2.getData());
}
- public void testBadEar() throws Exception
+ /**
+ * Tests that if an ear doesn't package a persistence unit, and tries to inject a persistence
+ * unit deployed outside the ear, then the persistence unit is accessible and usable.
+ * This is a jboss specific feature.
+ * See https://jira.jboss.org/jira/browse/JBPAPP-3064
+ * @throws Exception
+ */
+ public void testPersistenceUnitAccessibleFromDifferentEar() throws Exception
{
- try
- {
+ // persistenceunitscope-test2.ear does *not* package a persistence unit,
+ // so the PU will be picked up from persistenceunitscope-test1.ear (which pacakges
+ // the PU). This is a jboss specific feature https://jira.jboss.org/jira/browse/JBPAPP-3064
EntityTest test = (EntityTest) getInitialContext().lookup("persistenceunitscope-test2/EntityTestBean/remote");
- fail("Should not have deployed - got PU from persistenceunitscope-test1");
- } catch (javax.naming.NameNotFoundException e)
- {
- }
+ Entity1 entity1 = new Entity1();
+ entity1.setData("hello");
+ Long id1 = test.persistEntity1(entity1);
+ entity1 = test.loadEntity1(id1);
+ assertEquals("hello", entity1.getData());
+
}
+
+ /**
+ * Test that if multiple EARs deploy a persistence unit with the same unit name, then
+ * the deployments within the ears pick up the correct persistence unit.
+ *
+ * @throws Exception
+ */
+ public void testMultipleEarWithSamePUName() throws Exception
+ {
+ // Both bookmanager.ear and usermanager.ear package a persistence unit
+ // with the same name. However, each persistence unit maps different
+ // set of (exclusive) entities. The test ensures that the correct
+ // PU is picked up by the deployments for entitymanager operations.
+
+ // first do some book manager operations. If an incorrect PU was picked
+ // up then the org.jboss.ejb3.test.persistenceunits.Book entity will *not* be mapped to this PU
+ // and the test will fail
+ BookManager bookManager = (BookManager) getInitialContext().lookup(BookManager.JNDI_NAME);
+ String bookName = "new book";
+ bookManager.addBook(bookName);
+ List<Book> books = bookManager.getBooks();
+ assertNotNull("Books list was null", books);
+ assertEquals("Unexpected number of books returned", 1, books.size());
+ Book book = books.get(0);
+ assertEquals("Unexpected book returned", bookName, book.getName());
+
+ // now do some usermanager operations. If an incorrect PU was picked
+ // up then the org.jboss.ejb3.test.persistenceunits.User entity will *not* be mapped to this PU
+ // and the test will fail
+ UserManager userManager = (UserManager) getInitialContext().lookup(UserManager.JNDI_NAME);
+ String userName = "new book";
+ userManager.addUser(userName);
+ List<User> users = userManager.getUsers();
+ assertNotNull("Users list was null", users);
+ assertEquals("Unexpected number of books returned", 1, users.size());
+ User user = users.get(0);
+ assertEquals("Unexpected user returned", userName, user.getName());
+
+ }
public static Test suite() throws Exception
{
- return getDeploySetup(MultipleEarTestCase.class, "persistenceunitscope-test1.ear, persistenceunitscope-test2.ear");
+ return getDeploySetup(MultipleEarTestCase.class,
+ "persistenceunitscope-test1.ear, persistenceunitscope-test2.ear, bookmanager.ear, usermanager.ear");
}
}
More information about the jboss-cvs-commits
mailing list