openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ss...@apache.org
Subject svn commit: r692299 - in /openjpa/branches/0.9.7-r547073: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
Date Thu, 04 Sep 2008 23:12:27 GMT
Author: ssegu
Date: Thu Sep  4 16:12:27 2008
New Revision: 692299

URL: http://svn.apache.org/viewvc?rev=692299&view=rev
Log:
OPENJPA-313.2.patch 

Modified:
    openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
    openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java

Modified: openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
URL: http://svn.apache.org/viewvc/openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java?rev=692299&r1=692298&r2=692299&view=diff
==============================================================================
--- openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
(original)
+++ openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
Thu Sep  4 16:12:27 2008
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
@@ -189,8 +190,34 @@
             }
         }
         Object oid = ApplicationIds.fromPKValues(vals, cls);
-        if (!subs && oid instanceof OpenJPAId)
-            ((OpenJPAId) oid).setManagedInstanceType(cls.getDescribedType());
+        
+        /**
+         * 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.
+         */        
+        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();  
+            } 
+        }
         return oid;
     }
 

Modified: openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
URL: http://svn.apache.org/viewvc/openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java?rev=692299&r1=692298&r2=692299&view=diff
==============================================================================
--- openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
(original)
+++ openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
Thu Sep  4 16:12:27 2008
@@ -78,6 +78,14 @@
     }
 
     /**
+     * Set the exact type of the described instance once it is known.
+     */
+    public void setManagedInstanceType(Class type, boolean subs) {
+        this.type = type;
+        this.subs = subs;
+    }
+
+    /**
      * Return the identity value as an object.
      */
     public abstract Object getIdObject();



Mime
View raw message