openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r713829 - in /openjpa/branches/1.1.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractj...
Date Thu, 13 Nov 2008 21:31:49 GMT
Author: awhite
Date: Thu Nov 13 13:31:48 2008
New Revision: 713829

URL: http://svn.apache.org/viewvc?rev=713829&view=rev
Log:
Merge 692307 from 0.9.7 to 1.1.x.


Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/RelationOwner.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SubID.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Subclass.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SuperID.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Superclass.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java?rev=713829&r1=713828&r2=713829&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
Thu Nov 13 13:31:48 2008
@@ -189,34 +189,27 @@
                     return null;
             }
         }
-        Object oid = ApplicationIds.fromPKValues(vals, cls);
-        
-        /**
-         * For polymorphic relations,
-         * the type field in the oid is initially set to base type.
-         * If the discriminator value is preset in the current result,
-         * then the type field needs reset based on the discriminator value.
-         * If the discriminator value is not present or invalid,
-         * ignore any exceptions being thrown.
-         */        
+
+        // the oid data is loaded by the base type, but if discriminator data
+        // is present, make sure to use it to construct the actual oid instance
+        // so that we get the correct app id class, etc
+        ClassMapping dcls = cls;
+        if (subs) {
+            res.startDataRequest(cls.getDiscriminator());
+            try {
+                Class dtype = cls.getDiscriminator().getClass(store, cls, res);
+                if (dtype != cls.getDescribedType())
+                  dcls = cls.getMappingRepository().getMapping(dtype, 
+                    store.getContext().getClassLoader(), true); 
+            } catch (Exception e) {
+                // intentionally ignored
+            }
+            res.endDataRequest();  
+        }
+        Object oid = ApplicationIds.fromPKValues(vals, dcls);
         if (oid instanceof OpenJPAId) {
-            Class type = cls.getDescribedType();
-            if (!subs)
-                // non-polymorphic relations
-                ((OpenJPAId) oid).setManagedInstanceType(type);
-            else if (cls.getDiscriminator() != null
-                && !StringUtils.equals("none",
-                    cls.getDiscriminator().getStrategy().getAlias())) {
-                // polymorphic relations
-                res.startDataRequest(cls.getDiscriminator());
-                try {
-                    type = cls.getDiscriminator().getClass(store, cls, res);
-                    ((OpenJPAId) oid).setManagedInstanceType(type, true);
-                } catch (Exception e) {
-                    // intentionally ignored
-                }
-                res.endDataRequest();  
-            } 
+            ((OpenJPAId) oid).setManagedInstanceType(dcls.getDescribedType(), 
+                subs);
         }
         return oid;
     }

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java?rev=713829&r1=713828&r2=713829&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
Thu Nov 13 13:31:48 2008
@@ -55,7 +55,7 @@
     }
 
     /**
-     * Return the persitent class which this id instance represents.
+     * Return the persistent class which this id instance represents.
      */
     public Class getType() {
         return type;
@@ -73,8 +73,7 @@
      * Set the exact type of the described instance once it is known.
      */
     public void setManagedInstanceType(Class type) {
-        this.type = type;
-        this.subs = false;
+        setManagedInstanceType(type, false);
     }
 
     /**

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/RelationOwner.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/RelationOwner.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/RelationOwner.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/RelationOwner.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,24 @@
+package org.apache.openjpa.persistence.inheritance.abstractjoinedappid;
+
+import java.util.*;
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;
+
+@Entity
+@Table(name="TEST")
+public class RelationOwner {
+	
+	private Integer id;
+	private Collection<Superclass> supers = new ArrayList<Superclass>();
+	
+	@Id
+	@Column(name="ID")
+	public Integer getId() { return id;	}
+	public void setId(Integer id) { this.id = id; }
+	
+	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
+	@ElementJoinColumn(name="TEST", referencedColumnName="ID")
+	public Collection<Superclass> getSupers() {	return supers; }
+	public void setSupers(Collection<Superclass> supers) { this.supers = supers; }
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SubID.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SubID.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SubID.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SubID.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,5 @@
+package org.apache.openjpa.persistence.inheritance.abstractjoinedappid;
+
+public class SubID extends SuperID {
+
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Subclass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Subclass.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Subclass.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Subclass.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,16 @@
+package org.apache.openjpa.persistence.inheritance.abstractjoinedappid;
+
+import javax.persistence.*;
+
+@Entity
+@IdClass(SubID.class)
+@Table(name="SUB")
+public class Subclass extends Superclass {
+	
+	private String attr2;
+	
+	@Column(name="ATTR2")
+	public String getAttr2() { return attr2; }
+	public void setAttr2(String attr2) { this.attr2 = attr2; }
+
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SuperID.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SuperID.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SuperID.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/SuperID.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,26 @@
+package org.apache.openjpa.persistence.inheritance.abstractjoinedappid;
+
+import java.io.Serializable;
+
+public abstract class SuperID implements Serializable {
+	
+	private Integer id;
+
+	public Integer getId() { return id; }
+	public void setId(Integer id) {	this.id = id; }
+	
+	public int hashCode() {
+		return id;
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) return true;
+		if (!(obj instanceof SuperID)) return false;
+		SuperID pk = (SuperID) obj;
+		if ( pk.getId().equals(id)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Superclass.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Superclass.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Superclass.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/Superclass.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,22 @@
+package org.apache.openjpa.persistence.inheritance.abstractjoinedappid;
+
+import javax.persistence.*;
+
+@Entity
+@IdClass(SuperID.class)
+@Table(name="SUPER")
+@Inheritance(strategy=InheritanceType.JOINED)
+public abstract class Superclass {
+	
+	private Integer id;
+	private String attr1;
+	
+	@Id
+	@Column(name="ID")
+	public Integer getId() { return id; }
+	public void setId(Integer id) {	this.id = id; }
+	
+	@Column(name="ATTR1")
+	public String getAttr1() { return attr1; }
+	public void setAttr1(String attr1) { this.attr1 = attr1; }
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java?rev=713829&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/abstractjoinedappid/TestAbstractJoinedAppId.java
Thu Nov 13 13:31:48 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.persistence.inheritance.abstractjoinedappid;
+
+import java.util.Arrays;
+import java.util.Collection;
+import javax.persistence.EntityManager;
+
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Test that you traverse an inverse key-baesd relation to an abstract
+ * class using joined inheritance.
+ */
+public class TestAbstractJoinedAppId
+    extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(Superclass.class, Subclass.class, RelationOwner.class);
+
+        Subclass s = new Subclass();
+        s.setId(99);
+        s.setAttr1("supattr");
+        s.setAttr2("subattr");
+    
+        RelationOwner ro = new RelationOwner();
+        ro.setId(1);
+        ro.setSupers(Arrays.asList(new Superclass[] { s }));
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(ro);
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void testTraverseRelation() {
+        EntityManager em = emf.createEntityManager();
+        RelationOwner ro = em.find(RelationOwner.class, 1);
+        assertNotNull(ro);
+
+        Collection supers = ro.getSupers();
+        assertEquals(1, supers.size());        
+        Superclass s = (Superclass) supers.iterator().next();
+        assertTrue(s instanceof Subclass);
+        assertEquals(new Integer(99), s.getId());
+        assertEquals("supattr", s.getAttr1());
+        assertEquals("subattr", ((Subclass) s).getAttr2());
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestAbstractJoinedAppId.class);
+    }
+}
+



Mime
View raw message