[jboss-cvs] JBossAS SVN: r61756 - in branches/Branch_4_2/ejb3/src: resources/test/persistenceunits and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 27 15:20:48 EDT 2007


Author: bdecoste
Date: 2007-03-27 15:20:48 -0400 (Tue, 27 Mar 2007)
New Revision: 61756

Added:
   branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/
   branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/META-INF/
   branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/META-INF/persistence.xml
   branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/entity2-ds.xml
   branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/mysql-connector-java-5.0.5-bin.jar
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity2.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/EntityUnitTestCase.java
Log:
test for multiple persistence units in one persistence.xml

Added: branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/META-INF/persistence.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/META-INF/persistence.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/META-INF/persistence.xml	2007-03-27 19:20:48 UTC (rev 61756)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+   <persistence-unit name="Entity1">
+      <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.Entity1</class>
+   </persistence-unit>
+   <persistence-unit name="Entity2">
+      <jta-data-source>java:/Entity2DS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create"/>
+          <!--property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/-->
+          <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+      </properties>
+      <class>org.jboss.ejb3.test.persistenceunits.Entity2</class>
+   </persistence-unit>
+</persistence>

Added: branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/entity2-ds.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/entity2-ds.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/entity2-ds.xml	2007-03-27 19:20:48 UTC (rev 61756)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<datasources>
+   <local-tx-datasource>
+      <jndi-name>Entity2DS</jndi-name>
+
+      <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic2${/}Entity2DS</connection-url>
+
+      <driver-class>org.hsqldb.jdbcDriver</driver-class>
+
+      <user-name>sa</user-name>
+      <password></password>
+
+      <min-pool-size>5</min-pool-size>
+
+      <max-pool-size>20</max-pool-size>
+
+      <idle-timeout-minutes>0</idle-timeout-minutes>
+
+      <metadata>
+         <type-mapping>Hypersonic SQL</type-mapping>
+      </metadata>
+      
+      <depends>jboss:service=Hypersonic,database=Entity2DS</depends>
+   </local-tx-datasource>
+
+   <mbean code="org.jboss.jdbc.HypersonicDatabase" 
+     name="jboss:service=Hypersonic,database=Entity2DS">
+     <attribute name="Database">Entity2DS</attribute>
+     <attribute name="InProcessMode">true</attribute>
+   </mbean>
+   
+   <!--local-tx-datasource> 
+ 
+	<jndi-name>Entity2DS</jndi-name> 
+ 
+    <connection-url>jdbc:mysql://localhost:3306/jboss</connection-url> 
+    <driver-class>com.mysql.jdbc.Driver</driver-class> 
+ 
+    <user-name>jboss</user-name> 
+    <password>jboss</password> 
+ 
+    <connection-property name="autoReconnect">true</connection-property>
+ 
+    <metadata> 
+      <type-mapping>mySQL</type-mapping> 
+    </metadata> 
+ 
+  </local-tx-datasource-->
+</datasources>

Added: branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/mysql-connector-java-5.0.5-bin.jar
===================================================================
(Binary files differ)


Property changes on: branches/Branch_4_2/ejb3/src/resources/test/persistenceunits/mysql-connector-java-5.0.5-bin.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity1.java	2007-03-27 19:20:48 UTC (rev 61756)
@@ -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.persistenceunits;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Entity
+ at Table(name = "ENTITY1")
+public class Entity1 implements java.io.Serializable
+{
+   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/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity2.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity2.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/Entity2.java	2007-03-27 19:20:48 UTC (rev 61756)
@@ -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.persistenceunits;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Table;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Entity
+ at Table(name = "ENTITY2")
+public class Entity2 implements java.io.Serializable
+{
+   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/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTest.java	2007-03-27 19:20:48 UTC (rev 61756)
@@ -0,0 +1,34 @@
+/*
+ * 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 EntityTest
+{
+   Long persistEntity1(Entity1 entity1);
+   Entity1 loadEntity1(Long id);
+   Long persistEntity2(Entity2 entity2);
+   Entity2 loadEntity2(Long id);
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/EntityTestBean.java	2007-03-27 19:20:48 UTC (rev 61756)
@@ -0,0 +1,64 @@
+/*
+ * 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 org.jboss.logging.Logger;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(EntityTest.class)
+public class EntityTestBean implements EntityTest
+{
+   private static final Logger log = Logger.getLogger(EntityTestBean.class);
+   
+   private @PersistenceContext(unitName="Entity1") EntityManager manager1;
+   private @PersistenceContext(unitName="Entity2") EntityManager manager2;
+
+   public Long persistEntity1(Entity1 entity1)
+   {
+      manager1.persist(entity1);
+      return entity1.getId();
+   }
+
+   public Entity1 loadEntity1(Long id)
+   {
+      return manager1.find(Entity1.class, id);
+   }
+
+   public Long persistEntity2(Entity2 entity2)
+   {
+      manager2.persist(entity2);
+      return entity2.getId();
+   }
+
+   public Entity2 loadEntity2(Long id)
+   {
+      return manager2.find(Entity2.class, id);
+   }
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/EntityUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/EntityUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/persistenceunits/unit/EntityUnitTestCase.java	2007-03-27 19:20:48 UTC (rev 61756)
@@ -0,0 +1,70 @@
+/*
+ * 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 java.util.Set;
+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 EntityUnitTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(EntityUnitTestCase.class);
+
+   public EntityUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testPersistenceUnits() throws Exception
+   {
+      EntityTest test = (EntityTest) getInitialContext().lookup("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(EntityUnitTestCase.class, "persistenceunits-test.jar");
+   }
+
+}




More information about the jboss-cvs-commits mailing list