openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r617073 - in /openjpa/branches/1.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/
Date Thu, 31 Jan 2008 08:56:58 GMT
Author: pcl
Date: Thu Jan 31 00:56:46 2008
New Revision: 617073

URL: http://svn.apache.org/viewvc?rev=617073&view=rev
Log:
OPENJPA-258. Actually really fixing the issue this time.

Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
Thu Jan 31 00:56:46 2008
@@ -30,11 +30,10 @@
 public class InheritanceComparator
     implements Comparator, Serializable {
 
-    private Class _base = Object.class;
+    private Class _base = null;
 
     /**
-     * Set the least-derived type possible; defaults to
-     * <code>Object.class</code>.
+     * Set the least-derived type possible; defaults to <code>null</code>.
      */
     public void setBase(Class base) {
         _base = base;
@@ -75,10 +74,9 @@
                 return 1;
             return c1.getName().compareTo(c2.getName());
         }
-        int diff = i1 - i2;
-        if (diff < 0)
+        if (i1 < i2)
             return -1;
-        else if (diff > 0)
+        else if (i1 > i2)
             return 1;
         else
             return 0;
@@ -90,6 +88,8 @@
     private int levels(Class to) {
         if (to.isInterface())
             return to.getInterfaces().length;
+        if (_base == null)
+            return 0;
         for (int i = 0; to != null; i++, to = to.getSuperclass())
             if (to == _base)
                 return i;

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java
Thu Jan 31 00:56:46 2008
@@ -19,8 +19,10 @@
 package org.apache.openjpa.meta;
 
 import javax.persistence.Entity;
+import javax.persistence.Table;
 
 @Entity
+@Table(name="meta_A")
 public class A extends AbstractThing {
 
 }

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java
Thu Jan 31 00:56:46 2008
@@ -35,7 +35,7 @@
         return id;
     }
 
-    void setId(final String id) {
+    protected void setId(final String id) {
         this.id = id;
     }
 }

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java
Thu Jan 31 00:56:46 2008
@@ -21,10 +21,12 @@
 import java.util.Set;
 import javax.persistence.Entity;
 import javax.persistence.OneToMany;
+import javax.persistence.Table;
 
 import org.apache.openjpa.meta.C;
 
 @Entity
+@Table(name="meta_B")
 public class B extends AbstractThing {
     private Set<C> cs;
     private Set<A> as;

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java
Thu Jan 31 00:56:46 2008
@@ -23,11 +23,13 @@
 import javax.persistence.ManyToOne;
 import javax.persistence.Column;
 import javax.persistence.Id;
+import javax.persistence.Table;
 
 import org.apache.openjpa.meta.C.Identity;
 
 @Entity
 @IdClass(Identity.class)
+@Table(name="meta_C")
 public class C {
     private A a;
     private B b;

Modified: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java?rev=617073&r1=617072&r2=617073&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java
Thu Jan 31 00:56:46 2008
@@ -20,16 +20,45 @@
 
 import javax.persistence.EntityManagerFactory;
 
-import junit.framework.TestCase;
 import org.apache.openjpa.persistence.test.PersistenceTestCase;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 import org.apache.openjpa.persistence.JPAFacadeHelper;
 
 public class TestMetaDataInheritanceComparator extends PersistenceTestCase {
 
-    public void testMetaDataInheritanceComparator() {
+    public void testInheritanceComparatorWithoutBase() {
+        inheritanceComparatorHelper(false);
+    }
+
+    public void testInheritanceComparatorWithBase() {
+        inheritanceComparatorHelper(true);
+    }
+
+    private void inheritanceComparatorHelper(boolean base) {
+        InheritanceComparator comp = new InheritanceComparator();
+        if (base)
+            comp.setBase(AbstractThing.class);
+
+        assertEquals(-1, comp.compare(A.class, B.class));
+        assertEquals(-1, comp.compare(B.class, C.class));
+        assertTrue(comp.compare(A.class, C.class) < 0);
+
+        assertEquals(-1, comp.compare(AbstractThing.class, A.class));
+        assertEquals(-1, comp.compare(AbstractThing.class, B.class));
+        assertTrue(comp.compare(AbstractThing.class, C.class) < 0);
+    }
+
+    public void testMetaDataInheritanceComparatorWithoutBase() {
+        metaDataInheritanceComparatorHelper(false);
+    }
+
+    public void testMetaDataInheritanceComparatorWithBase() {
+        metaDataInheritanceComparatorHelper(true);
+    }
+
+    private void metaDataInheritanceComparatorHelper(boolean base) {
         InheritanceComparator comp = new MetaDataInheritanceComparator();
-        comp.setBase(AbstractThing.class);
+        if (base)
+            comp.setBase(AbstractThing.class);
 
         EntityManagerFactory emf = createEMF(A.class, B.class, C.class,
             AbstractThing.class);
@@ -37,18 +66,29 @@
         ClassMetaData a = JPAFacadeHelper.getMetaData(emf, A.class);
         ClassMetaData b = JPAFacadeHelper.getMetaData(emf, B.class);
         ClassMetaData c = JPAFacadeHelper.getMetaData(emf, C.class);
+        ClassMetaData at = JPAFacadeHelper.getMetaData(emf,
+            AbstractThing.class);
+
+        emf.close();
 
         assertEquals(-1, comp.compare(a, b));
         assertEquals(-1, comp.compare(b, c));
-        assertEquals(-1, comp.compare(a, c));
-    }
+        assertTrue(comp.compare(a, c) < 0);
 
-    public void testInheritanceComparator() {
-        InheritanceComparator comp = new InheritanceComparator();
-        comp.setBase(AbstractThing.class);
+        assertEquals(1, comp.compare(b, a));
+        assertEquals(1, comp.compare(c, b));
+        assertTrue(comp.compare(c, a) > 0);
+
+        assertEquals(-1, comp.compare(at, a));
+        assertEquals(-1, comp.compare(at, b));
+        assertEquals(-1, comp.compare(at, c));
+    }
 
-        assertEquals(-1, comp.compare(A.class, B.class));
-        assertEquals(-1, comp.compare(B.class, C.class));
-        assertEquals(-1, comp.compare(A.class, C.class));
+    public void testEndToEnd() {
+        // make sure we can get things fully instantiated
+        EntityManagerFactory emf = createEMF(A.class, B.class, C.class,
+            AbstractThing.class);
+        emf.createEntityManager().close();
+        emf.close();
     }
 }



Mime
View raw message