openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r683916 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta: ClassMapping.java strats/RelationFieldStrategy.java
Date Fri, 08 Aug 2008 08:59:12 GMT
Author: ppoddar
Date: Fri Aug  8 01:59:12 2008
New Revision: 683916

URL: http://svn.apache.org/viewvc?rev=683916&view=rev
Log:
OPENJPA-677: Make a judgement whether reading discrimnator value from the result makes sense
in a context

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java?rev=683916&r1=683915&r2=683916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
Fri Aug  8 01:59:12 2008
@@ -175,6 +175,7 @@
         FieldMapping fm;
         Joinable join;
         int pkIdx;
+        boolean canReadDiscriminator = true;
         for (int i = 0; i < pks.length; i++) {
             // we know that all pk column join mappings use primary key fields,
             // cause this mapping uses the oid as its primary key (we recursed
@@ -182,7 +183,7 @@
             join = assertJoinable(pks[i]);
             fm = getFieldMapping(join.getFieldIndex());
             pkIdx = fm.getPrimaryKeyIndex();
-
+            canReadDiscriminator &= isSelfReference(fk, join.getColumns()); 
             // could have already set value with previous multi-column joinable
             if (vals[pkIdx] == null) {
                 res.startDataRequest(fm);
@@ -197,8 +198,13 @@
         // 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
+        
+        // Discriminator refers to the row but the vals[] may hold data that
+        // refer to another row. Then there is little point reading the disc
+        // value
+
         ClassMapping dcls = cls;
-        if (subs) {
+        if (subs && canReadDiscriminator) {
             res.startDataRequest(cls.getDiscriminator());
             try {
                 Class dtype = cls.getDiscriminator().getClass(store, cls, res);
@@ -217,6 +223,15 @@
         }
         return oid;
     }
+    
+    boolean isSelfReference(ForeignKey fk, Column[] cols) {
+    	if (fk == null)
+    		return true;
+    	for (Column col : cols)
+    		if (fk.getColumn(col) != col)
+    			return false;
+    	return true;
+    }
 
     /**
      * Return the given column value(s) for the given object. The given

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=683916&r1=683915&r2=683916&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Fri Aug  8 01:59:12 2008
@@ -556,10 +556,8 @@
         ClassMapping relMapping = field.getTypeMapping();
         Object oid = null;
         if (relMapping.isMapped()) {
-        	boolean subs = field.getPolymorphic() != ValueMapping.POLY_FALSE 
-        		&& relMapping.getPCSubclasses().length > 0;
             oid = relMapping.getObjectId(store, res, field.getForeignKey(),
-                subs, null);
+            		field.getPolymorphic() != ValueMapping.POLY_FALSE, null);
         } else {
             Column[] cols = field.getColumns();
             if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {



Mime
View raw message