openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r441702 - in /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test: java/org/apache/openjpa/persistence/inheritance/ java/org/apache/openjpa/persistence/simple/ resources/META-INF/
Date Sat, 09 Sep 2006 00:39:30 GMT
Author: awhite
Date: Fri Sep  8 17:39:29 2006
New Revision: 441702

URL: http://svn.apache.org/viewvc?view=rev&rev=441702
Log:
Added test for deep mapped superclass inheritance hierarchy, which is what
my last metadata changes fixed.


Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
Modified:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java?view=auto&rev=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3.java
Fri Sep  8 17:39:29 2006
@@ -0,0 +1,19 @@
+package org.apache.openjpa.persistence.inheritance;
+
+import javax.persistence.Entity;
+
+@Entity 
+public class EntityL3 
+    extends MappedSuperclassL2 {
+
+    private int l3data;
+
+    public int getL3Data() {
+        return l3data;
+    }
+
+    public void setL3Data(int data) {
+        l3data = data;
+    }
+}
+

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java?view=auto&rev=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
Fri Sep  8 17:39:29 2006
@@ -0,0 +1,19 @@
+package org.apache.openjpa.persistence.inheritance;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+@MappedSuperclass
+public class MappedSuperclassBase {
+
+    @Id
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    private long id;
+
+    public long getId() {
+        return id;
+    }
+}
+

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java?view=auto&rev=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassL2.java
Fri Sep  8 17:39:29 2006
@@ -0,0 +1,19 @@
+package org.apache.openjpa.persistence.inheritance;
+
+import javax.persistence.MappedSuperclass;
+
+@MappedSuperclass 
+public class MappedSuperclassL2 
+    extends MappedSuperclassBase {
+
+    private int l2data;
+
+    public int getL2Data() {
+        return l2data;
+    }
+
+    public void setL2Data(int data) {
+        l2data = data;
+    }
+}
+

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java?view=auto&rev=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestMultipleMappedSuperclassHierarchy.java
Fri Sep  8 17:39:29 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.openjpa.persistence.inheritance;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Perform basic operations on an inheritance hierarchy involving multiple
+ * @MappedSuperclasses.
+ *
+ * @author Abe White
+ */
+public class TestMultipleMappedSuperclassHierarchy
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        String types = MappedSuperclassBase.class.getName() + ";"
+            + MappedSuperclassL2.class.getName() + ";"
+            + EntityL3.class.getName();
+        Map props = new HashMap();
+        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from EntityL3").executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testPersist() {
+        EntityL3 ent = new EntityL3();
+        ent.setL2Data(99); 
+        ent.setL3Data(100);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(ent);
+        em.getTransaction().commit();
+        long id = ent.getId();
+        assertTrue(id != 0);
+        em.close();
+
+        em = emf.createEntityManager();
+        ent = em.find(EntityL3.class, id);
+        assertNotNull(ent);
+        assertEquals(99, ent.getL2Data());
+        assertEquals(100, ent.getL3Data());
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestMultipleMappedSuperclassHierarchy.class);
+    }
+}
+

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java?view=diff&rev=441702&r1=441701&r2=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestPersistence.java
Fri Sep  8 17:39:29 2006
@@ -15,6 +15,8 @@
  */
 package org.apache.openjpa.persistence.simple;
 
+import java.util.HashMap;
+import java.util.Map;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
@@ -34,23 +36,18 @@
 
     private EntityManagerFactory emf;
 
-    protected EntityManager getEM() {
-        if (emf == null)
-            emf = Persistence.createEntityManagerFactory("simple-emf-test");
-        assertNotNull(emf);
-
-        EntityManager em = emf.createEntityManager();
-        assertNotNull(em);
-
-        return em;
+    public void setUp() {
+        Map props = new HashMap();
+        props.put("openjpa.MetaDataFactory", 
+            "jpa(Types=" + AllFieldTypes.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
     }
 
-    public void tearDown()
-        throws Exception {
-        super.tearDown();
-
+    public void tearDown() {
+        if (emf == null)
+            return;
         try {
-            EntityManager em = getEM();
+            EntityManager em = emf.createEntityManager();
             em.getTransaction().begin();
             em.createQuery("delete from AllFieldTypes").executeUpdate();
             em.getTransaction().commit();
@@ -61,11 +58,10 @@
     }
 
     public void testCreateEntityManager() {
-        EntityManager em = getEM();
+        EntityManager em = emf.createEntityManager();
 
         EntityTransaction t = em.getTransaction();
         assertNotNull(t);
-
         t.begin();
         t.setRollbackOnly();
         t.rollback();
@@ -75,14 +71,11 @@
         OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
         ojem.getFetchPlan().setMaxFetchDepth(-1);
         assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth());
-
         em.close();
     }
 
     public void testPersist() {
-        EntityManager em;
-
-        em = getEM();
+        EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         em.persist(new AllFieldTypes());
         em.getTransaction().commit();
@@ -90,9 +83,7 @@
     }
 
     public void testQuery() {
-        EntityManager em;
-
-        em = getEM();
+        EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         AllFieldTypes aft = new AllFieldTypes();
         aft.setStringField("foo");
@@ -101,7 +92,7 @@
         em.getTransaction().commit();
         em.close();
 
-        em = getEM();
+        em = emf.createEntityManager();
         em.getTransaction().begin();
         assertEquals(1, em.createQuery
             ("select x from AllFieldTypes x where x.stringField = 'foo'").

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?view=diff&rev=441702&r1=441701&r2=441702
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
Fri Sep  8 17:39:29 2006
@@ -1,24 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <persistence xmlns="http://java.sun.com/xml/ns/persistence"
-             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-             version="1.0">
-
-    <persistence-unit name="simple-emf-test">
-
-        <!-- This is not needed if OpenJPA is the only persistence provider
-             in the classpath.
-          <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
-          -->
-
-        <class>org.apache.openjpa.persistence.simple.AllFieldTypes</class>
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    version="1.0">
 
+    <persistence-unit name="test">
+        <!-- 
+        <provider>
+            org.apache.openjpa.persistence.PersistenceProviderImpl
+        </provider>
+        -->
         <properties>
             <property name="openjpa.ConnectionDriverName"
-                      value="org.apache.commons.dbcp.BasicDataSource"/>
+                value="org.apache.commons.dbcp.BasicDataSource"/>
             <property name="openjpa.ConnectionProperties"
-                      value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
+                value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
             <property name="openjpa.jdbc.SynchronizeMappings"
-                      value="buildSchema(ForeignKeys=true)"/>
+                value="buildSchema(ForeignKeys=true)"/>
         </properties>
     </persistence-unit>
 </persistence>



Mime
View raw message