openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r952972 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: meta/strats/RelationStrategies.java meta/strats/StoreCollectionFieldStrategy.java sql/SelectImpl.java
Date Wed, 09 Jun 2010 12:03:15 GMT
Author: ppoddar
Date: Wed Jun  9 12:03:15 2010
New Revision: 952972

URL: http://svn.apache.org/viewvc?rev=952972&view=rev
Log:
OPENJPA-1686: Refactor in RelationStrategies.isRelationId()

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationStrategies.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationStrategies.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationStrategies.java?rev=952972&r1=952971&r2=952972&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationStrategies.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationStrategies.java
Wed Jun  9 12:03:15 2010
@@ -26,9 +26,11 @@ import org.apache.openjpa.jdbc.meta.Clas
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.FieldStrategy;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.meta.RelationId;
 import org.apache.openjpa.jdbc.meta.ValueMapping;
 import org.apache.openjpa.jdbc.meta.ValueMappingInfo;
 import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.kernel.DetachedValueStateManager;
 import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.kernel.StoreContext;
@@ -225,4 +227,25 @@ public class RelationStrategies {
             return new DetachedValueStateManager(obj, ctx);
         return sm;
     }
+    
+    /**
+     * Affirms if all of the given columns represent a {@linkplain RelationId relationship
identifier}. 
+     */
+    public static boolean isRelationId(Column[] cols) {
+        if (cols == null || cols.length == 0)
+            return false;
+        for (int i = 0; i < cols.length; i++) {
+            if (!cols[i].isRelationId())
+                return false;
+        }
+        return true;
+    }
+    
+    /**
+     * Affirms if all of the foreign key columns represent a {@linkplain RelationId relationship
identifier}.
+     */
+    public static boolean isRelationId(ForeignKey fk) {
+        return fk != null && isRelationId(fk.getColumns());
+    }
+
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=952972&r1=952971&r2=952972&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Wed Jun  9 12:03:15 2010
@@ -611,10 +611,8 @@ public abstract class StoreCollectionFie
      */
     Object getObjectIdForJoin(ForeignKey fk, OpenJPAStateManager sm) {
         Object oid = sm.getObjectId();
-        for (Column col : fk.getColumns()) {
-            if (!col.isRelationId()) {
-                return oid;
-            }
+        if (!RelationStrategies.isRelationId(fk)) {
+            return oid;
         }
         
         FieldMapping owningField = field.getMappedByMapping();

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=952972&r1=952971&r2=952972&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Wed
Jun  9 12:03:15 2010
@@ -50,6 +50,7 @@ import org.apache.openjpa.jdbc.meta.Clas
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.Joinable;
 import org.apache.openjpa.jdbc.meta.ValueMapping;
+import org.apache.openjpa.jdbc.meta.strats.RelationStrategies;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Table;
@@ -1343,7 +1344,6 @@ public class SelectImpl
     private void where(Object oid, ClassMapping mapping, Column[] toCols,
         Column[] fromCols, Object[] vals, Column[] constCols, PathJoins pj,
         JDBCStore store) {
-        boolean relationId = fromCols[0].isRelationId(); 
         ValueMapping embed = mapping.getEmbeddingMapping();
         if (embed != null) {
             where(oid, embed.getFieldMapping().getDefiningMapping(),
@@ -1353,6 +1353,7 @@ public class SelectImpl
 
         // only bother to pack pk values into array if app id
         Object[] pks = null;
+        boolean relationId = RelationStrategies.isRelationId(fromCols); 
         if (!relationId && mapping.getIdentityType() == ClassMapping.ID_APPLICATION)
             pks = ApplicationIds.toPKValues(oid, mapping);
 



Mime
View raw message