openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r518190 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/
Date Wed, 14 Mar 2007 15:44:56 GMT
Author: awhite
Date: Wed Mar 14 08:44:55 2007
New Revision: 518190

URL: http://svn.apache.org/viewvc?view=rev&rev=518190
Log:
Fix recently-introduced bug in handling of arrays in data cache.  Add test for
a shared id value among sibling classes deriving from the same mapped 
superclass.


Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java?view=diff&rev=518190&r1=518189&r2=518190
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
Wed Mar 14 08:44:55 2007
@@ -100,6 +100,9 @@
                 int length = Array.getLength(data);
                 Object a = Array.newInstance(fmd.getElement().getDeclaredType(),
                     length);
+                if (length == 0)
+                    return a;
+
                 if (isImmutableType(fmd.getElement())) {
                     System.arraycopy(data, 0, a, 0, length);
                 } else {
@@ -221,28 +224,32 @@
                 }
                 return m2;
             case JavaTypes.ARRAY:
-                Object a = val;
-                int length = Array.getLength(a);
+                int length = Array.getLength(val);
                 if (length == 0)
                     return EMPTY_ARRAY;
 
-                Object dataArray = Array.newInstance(
-                    fmd.getElement().getDeclaredType(), length);
+                Object a;
                 if (isImmutableType(fmd.getElement())) {
-                    System.arraycopy(a, 0, dataArray, 0, length);
+                    a = Array.newInstance(fmd.getElement().getDeclaredType(), 
+                        length);
+                    System.arraycopy(val, 0, a, 0, length);
                 } else {
+                    Object[] data = new Object[length];
                     for (int i = 0; i < length; i++) {
-                        val = toNestedData(fmd.getElement(), Array.get(a, i),
-                            ctx);
-                        Array.set(dataArray, i, val);
+                        data[i] = toNestedData(fmd.getElement(), 
+                            Array.get(val, i), ctx);
                     }
+                    a = data;
                 }
-                return dataArray;
+                return a;
             default:
                 return toNestedData(fmd, val, ctx);
         }
     }
 
+    /**
+     * Return whether the declared type of the given value is immutable.
+     */
     private boolean isImmutableType(ValueMetaData element) {
         switch (element.getDeclaredTypeCode()) {
             case JavaTypes.BOOLEAN:

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java?view=auto&rev=518190
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java
Wed Mar 14 08:44:55 2007
@@ -0,0 +1,34 @@
+/*
+ * 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 javax.persistence.Entity;
+
+@Entity 
+public class EntityL3Sibling 
+    extends MappedSuperclassL2 {
+
+    private int siblingl3data;
+
+    public int getSiblingL3Data() {
+        return siblingl3data;
+    }
+
+    public void setSiblingL3Data(int data) {
+        siblingl3data = data;
+    }
+}
+

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/EntityL3Sibling.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 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=diff&rev=518190&r1=518189&r2=518190
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/MappedSuperclassBase.java
Wed Mar 14 08:44:55 2007
@@ -30,5 +30,9 @@
     public long getId() {
         return id;
     }
+
+    public void setId(long id) {
+        this.id = id;
+    }
 }
 

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java?view=auto&rev=518190
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
Wed Mar 14 08:44:55 2007
@@ -0,0 +1,116 @@
+/*
+ * 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.Persistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ * Test that sibling classes with a shared id value declared in their 
+ * mapped superclass are distinguished correctly.
+ *
+ * @author Abe White
+ */
+public class TestSharedMappedSuperclassIdValue
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        String types = MappedSuperclassBase.class.getName() + ";"
+            + MappedSuperclassL2.class.getName() + ";"
+            + EntityL3.class.getName() + ";"
+            + EntityL3Sibling.class.getName();
+        Map props = new HashMap(System.getProperties());
+        props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+
+        EntityL3 ent = new EntityL3();
+        ent.setId(1);
+        ent.setL2Data(99); 
+        ent.setL3Data(100);
+        EntityL3Sibling sib = new EntityL3Sibling();
+        sib.setId(1);
+        sib.setL2Data(100); 
+        sib.setSiblingL3Data(101);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(ent);
+        em.persist(sib);
+        em.getTransaction().commit();
+        em.close();
+
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from EntityL3").executeUpdate();
+            em.createQuery("delete from EntityL3Sibling").executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testFind() {
+        EntityManager em = emf.createEntityManager();
+        EntityL3 ent = em.find(EntityL3.class, 1L);
+        assertNotNull(ent);
+        assertEquals(99, ent.getL2Data());
+        assertEquals(100, ent.getL3Data());
+
+        EntityL3Sibling sib = em.find(EntityL3Sibling.class, 1L);
+        assertNotNull(sib);
+        assertEquals(100, sib.getL2Data());
+        assertEquals(101, sib.getSiblingL3Data());
+
+        em.close();
+    }
+
+    public void testGetReference() {
+        EntityManager em = emf.createEntityManager();
+        EntityL3 ent = em.getReference(EntityL3.class, 1L);
+        assertNotNull(ent);
+
+        EntityL3Sibling sib = em.getReference(EntityL3Sibling.class, 1L);
+        assertNotNull(sib);
+
+        assertEquals(99, ent.getL2Data());
+        assertEquals(100, ent.getL3Data());
+        assertEquals(100, sib.getL2Data());
+        assertEquals(101, sib.getSiblingL3Data());
+
+        em.close();
+    }
+
+
+    public static void main(String[] args) {
+        TestRunner.run(TestSharedMappedSuperclassIdValue.class);
+    }
+}
+

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestSharedMappedSuperclassIdValue.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message