You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/05/26 01:58:36 UTC

svn commit: r409512 - /incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java

Author: aadamchik
Date: Thu May 25 16:58:35 2006
New Revision: 409512

URL: http://svn.apache.org/viewvc?rev=409512&view=rev
Log:
changing the algorithm, removing an kludge that was supposed to support early versions of nested DC, and doesn't seem to be needed now.

Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java?rev=409512&r1=409511&r2=409512&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowUtils.java Thu May 25 16:58:35 2006
@@ -62,7 +62,6 @@
 import org.objectstyle.cayenne.DataObject;
 import org.objectstyle.cayenne.DataRow;
 import org.objectstyle.cayenne.Fault;
-import org.objectstyle.cayenne.ObjectContext;
 import org.objectstyle.cayenne.ObjectId;
 import org.objectstyle.cayenne.PersistenceState;
 import org.objectstyle.cayenne.ValueHolder;
@@ -96,10 +95,7 @@
         if (entity.isReadOnly() || state == PersistenceState.HOLLOW) {
             refreshObjectWithSnapshot(entity, object, snapshot, true);
         }
-        // if nested DataContext is involved, we'll have to go through merge to keep
-        // uncommitted parent modifications
-        else if (state != PersistenceState.COMMITTED
-                || object.getDataContext().getChannel() instanceof ObjectContext) {
+        else if (state != PersistenceState.COMMITTED) {
             forceMergeWithSnapshot(entity, object, snapshot);
         }
         else {
@@ -119,56 +115,62 @@
             DataRow snapshot,
             boolean invalidateToManyRelationships) {
 
-        Map attrMap = objEntity.getAttributeMap();
-        Iterator it = attrMap.entrySet().iterator();
         boolean isPartialSnapshot = false;
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
-            String attrName = (String) entry.getKey();
-            ObjAttribute attr = (ObjAttribute) entry.getValue();
-            String dbAttrPath = attr.getDbAttributePath();
-            object.writePropertyDirectly(attrName, snapshot.get(dbAttrPath));
-
-            // note that a check "snaphsot.get(..) == null" would be incorrect in this
-            // case, as NULL value is entirely valid.
-            if (!snapshot.containsKey(dbAttrPath)) {
-                isPartialSnapshot = true;
-            }
-        }
 
-        Iterator rit = objEntity.getRelationships().iterator();
-        while (rit.hasNext()) {
-            ObjRelationship rel = (ObjRelationship) rit.next();
-            if (rel.isToMany()) {
-
-                // "to many" relationships have no information to collect from
-                // snapshot
-                // initialize a new empty list if requested, but otherwise
-                // ignore snapshot data
+        Map attrMap = objEntity.getAttributeMap();
+        if (!attrMap.isEmpty()) {
+            Iterator it = attrMap.entrySet().iterator();
 
-                Object toManyList = object.readPropertyDirectly(rel.getName());
+            while (it.hasNext()) {
+                Map.Entry entry = (Map.Entry) it.next();
+                String attrName = (String) entry.getKey();
+                ObjAttribute attr = (ObjAttribute) entry.getValue();
+                String dbAttrPath = attr.getDbAttributePath();
+                object.writePropertyDirectly(attrName, snapshot.get(dbAttrPath));
+
+                // note that a check "snaphsot.get(..) == null" would be incorrect in this
+                // case, as NULL value is entirely valid.
+                if (!snapshot.containsKey(dbAttrPath)) {
+                    isPartialSnapshot = true;
+                }
+            }
+        }
 
-                if (toManyList == null) {
-                    object.writePropertyDirectly(rel.getName(), Fault.getToManyFault());
+        Map rMap = objEntity.getRelationshipMap();
+        if (!rMap.isEmpty()) {
+            Iterator it = rMap.entrySet().iterator();
+            while (it.hasNext()) {
+
+                Map.Entry e = (Map.Entry) it.next();
+                ObjRelationship rel = (ObjRelationship) e.getValue();
+                
+                if (rel.isToMany()) {
+
+                    // "to many" relationships have no information to collect from
+                    // snapshot initialize a new empty list if requested, but otherwise
+                    // ignore snapshot data
+
+                    Object toManyList = object.readPropertyDirectly(rel.getName());
+
+                    if (toManyList == null) {
+                        object.writePropertyDirectly(rel.getName(), Fault
+                                .getToManyFault());
+                    }
+                    else if (invalidateToManyRelationships
+                            && toManyList instanceof ValueHolder) {
+                        ((ValueHolder) toManyList).invalidate();
+                    }
                 }
-                else if (invalidateToManyRelationships
-                        && toManyList instanceof ValueHolder) {
-                    ((ValueHolder) toManyList).invalidate();
+                else {
+                    // set a shared fault to indicate any kind of unresolved to-one
+                    object.writePropertyDirectly(rel.getName(), Fault.getToOneFault());
                 }
-
-                continue;
             }
-
-            // set a shared fault to indicate any kind of unresolved to-one
-            object.writePropertyDirectly(rel.getName(), Fault.getToOneFault());
         }
 
-        if (isPartialSnapshot) {
-            object.setPersistenceState(PersistenceState.HOLLOW);
-        }
-        else {
-            object.setPersistenceState(PersistenceState.COMMITTED);
-        }
+        object.setPersistenceState(isPartialSnapshot
+                ? PersistenceState.HOLLOW
+                : PersistenceState.COMMITTED);
     }
 
     static void forceMergeWithSnapshot(