You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2008/01/31 09:04:05 UTC

svn commit: r617039 - 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/

Author: pcl
Date: Thu Jan 31 00:04:03 2008
New Revision: 617039

URL: http://svn.apache.org/viewvc?rev=617039&view=rev
Log:
OPENJPA-258

Added:
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/
    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

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=617039&r1=617038&r2=617039&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:04:03 2008
@@ -75,7 +75,13 @@
                 return 1;
             return c1.getName().compareTo(c2.getName());
         }
-        return i1 - i2;
+        int diff = i1 - i2;
+        if (diff < 0)
+            return -1;
+        else if (diff > 0)
+            return 1;
+        else
+            return 0;
     }
 
     /**

Added: 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=617039&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java (added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/A.java Thu Jan 31 00:04:03 2008
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.meta;
+
+import javax.persistence.Entity;
+
+@Entity
+public class A extends AbstractThing {
+
+}

Added: 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=617039&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java (added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/AbstractThing.java Thu Jan 31 00:04:03 2008
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.meta;
+
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+
+@MappedSuperclass
+public class AbstractThing {
+
+    private String id;
+
+    @Id
+    @GeneratedValue(generator = "uuid-hex")
+    @Column(columnDefinition = "char(32)")
+    public String getId() {
+        return id;
+    }
+
+    void setId(final String id) {
+        this.id = id;
+    }
+}

Added: 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=617039&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java (added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/B.java Thu Jan 31 00:04:03 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.meta;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+
+import org.apache.openjpa.meta.C;
+
+@Entity
+public class B extends AbstractThing {
+    private Set<C> cs;
+    private Set<A> as;
+
+    @OneToMany
+    public Set<C> getCs() {
+        return cs;
+    }
+
+    public void setCs(Set<C> cs) {
+        this.cs = cs;
+    }
+
+    @OneToMany
+    public Set<A> getAs() {
+        return as;
+    }
+
+    public void setAs(Set<A> as) {
+        this.as = as;
+    }
+}

Added: 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=617039&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java (added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/C.java Thu Jan 31 00:04:03 2008
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.meta;
+
+import javax.persistence.Entity;
+import javax.persistence.IdClass;
+import javax.persistence.ManyToOne;
+import javax.persistence.Column;
+import javax.persistence.Id;
+
+import org.apache.openjpa.meta.C.Identity;
+
+@Entity
+@IdClass(Identity.class)
+public class C {
+    private A a;
+    private B b;
+    private long num;
+
+    @ManyToOne(optional = false)
+    @Column(nullable = false)
+    public A getA() {
+        return a;
+    }
+
+    public void setA(A a) {
+        this.a = a;
+    }
+
+    @Id
+    @ManyToOne(optional = false)
+    @Column(nullable = false)
+    public B getB() {
+        return b;
+    }
+
+    public void setB(B b) {
+        this.b = b;
+    }
+
+    @Id
+    public long getNum() {
+        return num;
+    }
+
+    public void setNum(long num) {
+        this.num = num;
+    }
+
+    public static class Identity {
+        private String b;
+        private long num;
+
+        @Override
+        public int hashCode() {
+            return b.hashCode() * 17 + (int) num;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            return obj != null && (obj instanceof Identity)
+                && b.equals(((Identity) obj).b) && num == ((Identity) obj).num;
+        }
+
+        public String getB() {
+            return b;
+        }
+
+        public void setB(B b) {
+            this.b = b.getId();
+        }
+
+        public void setB(String b) {
+            this.b = b;
+        }
+
+        public long getNum() {
+            return num;
+        }
+
+        public void setNum(long num) {
+            this.num = num;
+        }
+    }
+}

Added: 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=617039&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java (added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/meta/TestMetaDataInheritanceComparator.java Thu Jan 31 00:04:03 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.meta;
+
+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() {
+        InheritanceComparator comp = new MetaDataInheritanceComparator();
+        comp.setBase(AbstractThing.class);
+
+        EntityManagerFactory emf = createEMF(A.class, B.class, C.class,
+            AbstractThing.class);
+
+        ClassMetaData a = JPAFacadeHelper.getMetaData(emf, A.class);
+        ClassMetaData b = JPAFacadeHelper.getMetaData(emf, B.class);
+        ClassMetaData c = JPAFacadeHelper.getMetaData(emf, C.class);
+
+        assertEquals(-1, comp.compare(a, b));
+        assertEquals(-1, comp.compare(b, c));
+        assertEquals(-1, comp.compare(a, c));
+    }
+
+    public void testInheritanceComparator() {
+        InheritanceComparator comp = new InheritanceComparator();
+        comp.setBase(AbstractThing.class);
+
+        assertEquals(-1, comp.compare(A.class, B.class));
+        assertEquals(-1, comp.compare(B.class, C.class));
+        assertEquals(-1, comp.compare(A.class, C.class));
+    }
+}