cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454229 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne: CayenneDataObject.java access/DataContext.java access/DataContextDeleteAction.java access/DataContextGraphAction.java access/ObjectStore.java
Date Sun, 08 Oct 2006 22:55:27 GMT
Author: aadamchik
Date: Sun Oct  8 15:55:26 2006
New Revision: 454229

URL: http://svn.apache.org/viewvc?view=rev&rev=454229
Log:
CAY-680 - switching relationship handling in CayenneDataObject to a generic GraphManager API

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java?view=diff&rev=454229&r1=454228&r2=454229
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/CayenneDataObject.java
Sun Oct  8 15:55:26 2006
@@ -234,17 +234,11 @@
         // flattened or not)
         List relList = (List) readProperty(relName);
 
-        // call 'recordArcDeleted' AFTER readProperty as readProperty ensures that this
+        // call 'propertyChanged' AFTER readProperty as readProperty ensures that this
         // object fault is resolved
-        getDataContext().getObjectStore().recordArcDeleted(
-                this,
-                value != null ? value.getObjectId() : null,
-                relName);
+        getObjectContext().propertyChanged(this, relName, value, null);
 
         relList.remove(value);
-        if (persistenceState == PersistenceState.COMMITTED) {
-            persistenceState = PersistenceState.MODIFIED;
-        }
 
         if (value != null && setReverse) {
             unsetReverseRelationship(relName, value);
@@ -262,13 +256,9 @@
         // flattened or not)
         List list = (List) readProperty(relName);
 
-        // call 'recordArcCreated' AFTER readProperty as readProperty ensures that this
+        // call 'propertyChanged' AFTER readProperty as readProperty ensures that this
         // object fault is resolved
-        // getObjectContext().getGraphManager().
-        getDataContext().getObjectStore().recordArcCreated(
-                this,
-                value.getObjectId(),
-                relName);
+        getObjectContext().propertyChanged(this, relName, null, value);
 
         list.add(value);
 
@@ -289,10 +279,7 @@
             return;
         }
 
-        getDataContext().getObjectStore().recordArcCreated(
-                this,
-                value != null ? value.getObjectId() : null,
-                relationshipName);
+        getObjectContext().propertyChanged(this, relationshipName, oldTarget, value);
 
         if (setReverse) {
             // unset old reverse relationship

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java?view=diff&rev=454229&r1=454228&r2=454229
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
Sun Oct  8 15:55:26 2006
@@ -728,7 +728,7 @@
         descriptor.injectValueHolders(dataObject);
 
         ObjectId id = new ObjectId(objEntityName);
-        
+
         // note that the order of initialization of persistence artifacts below is
         // important - do not change it lightly
         dataObject.setObjectId(id);
@@ -850,8 +850,8 @@
 
                             // make sure it is registered
                             registerNewObject(targetDO);
-                            getObjectStore().recordArcCreated(
-                                    object,
+                            getObjectStore().arcCreated(
+                                    object.getObjectId(),
                                     targetDO.getObjectId(),
                                     property.getName());
                         }
@@ -869,8 +869,8 @@
 
                     // make sure it is registered
                     registerNewObject(targetDO);
-                    getObjectStore().recordArcCreated(
-                            object,
+                    getObjectStore().arcCreated(
+                            object.getObjectId(),
                             targetDO.getObjectId(),
                             property.getName());
                 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java?view=diff&rev=454229&r1=454228&r2=454229
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
Sun Oct  8 15:55:26 2006
@@ -177,8 +177,8 @@
                 Iterator iterator = relatedObjects.iterator();
                 while (iterator.hasNext()) {
                     DataObject relatedObject = (DataObject) iterator.next();
-                    objectStore.recordArcDeleted(
-                            object,
+                    objectStore.arcDeleted(
+                            object.getObjectId(),
                             relatedObject.getObjectId(),
                             relationship.getName());
                 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java?view=diff&rev=454229&r1=454228&r2=454229
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContextGraphAction.java
Sun Oct  8 15:55:26 2006
@@ -18,16 +18,15 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.DataRow;
 import org.apache.cayenne.Persistent;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.property.ArcProperty;
 import org.apache.cayenne.util.ObjectContextGraphAction;
 
 /**
  * An action object that processes graph change calls from Persistent objects. It handles
- * GraphManager notifications and bi-directional graph consistency.
+ * GraphManager notifications and bi-directional graph consistency. The main difference
+ * with CayenneContextGraph action is that reverse relationships are handled by the
+ * objects themselves.
  * 
  * @since 3.0
  * @author Andrus Adamchik
@@ -61,42 +60,22 @@
             Object oldValue,
             Object newValue) {
 
-    }
-
-    protected boolean markAsDirty(Persistent object) {
-        if (super.markAsDirty(object)) {
-
-            // TODO: andrus 3/23/2006 DataObject kink: snapshot versions are obsolete, but
-            // there is no replacement yet, so we still need to handle them...
-
-            if (object instanceof DataObject) {
+        if (oldValue != newValue) {
+            markAsDirty(object);
 
-                DataContext dataContext = (DataContext) context;
-                DataObject dataObject = (DataObject) object;
-                DataRow snapshot = dataContext.getObjectStore().getCachedSnapshot(
-                        object.getObjectId());
-
-                if (snapshot != null
-                        && snapshot.getVersion() != dataObject.getSnapshotVersion())
{
-                    DataContextDelegate delegate = dataContext.nonNullDelegate();
-                    if (delegate.shouldMergeChanges(dataObject, snapshot)) {
-                        ObjEntity entity = context.getEntityResolver().lookupObjEntity(
-                                object);
-                        DataRowUtils.forceMergeWithSnapshot(
-                                dataContext,
-                                entity,
-                                dataObject,
-                                snapshot);
-                        dataObject.setSnapshotVersion(snapshot.getVersion());
-                        delegate.finishedMergeChanges(dataObject);
-                    }
-                }
+            if (oldValue instanceof Persistent) {
+                context.getGraphManager().arcDeleted(
+                        object.getObjectId(),
+                        ((Persistent) oldValue).getObjectId(),
+                        property.getName());
             }
 
-            return true;
+            if (newValue instanceof Persistent) {
+                context.getGraphManager().arcCreated(
+                        object.getObjectId(),
+                        ((Persistent) newValue).getObjectId(),
+                        property.getName());
+            }
         }
-
-        return false;
     }
-
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java?view=diff&rev=454229&r1=454228&r2=454229
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java
Sun Oct  8 15:55:26 2006
@@ -104,43 +104,6 @@
     }
 
     /**
-     * Performs tracking of object relationship changes.
-     * 
-     * @since 1.2
-     */
-    // TODO: Andrus, 3/14/2006 - this method should be made non-public once we remove
-    // direct ObjectStore access from CayenneDataObject.
-    public void recordArcCreated(
-            Persistent object,
-            ObjectId targetId,
-            String relationshipName) {
-
-        registerDiff(object, new ArcOperation(
-                object.getObjectId(),
-                targetId,
-                relationshipName,
-                false));
-    }
-
-    /**
-     * Performs tracking of object relationship changes.
-     * 
-     * @since 1.2
-     */
-    // TODO: Andrus, 3/14/2006 - this method should be made non-public once we remove
-    // direct ObjectStore access from CayenneDataObject.
-    public void recordArcDeleted(
-            Persistent object,
-            ObjectId targetId,
-            String relationshipName) {
-        registerDiff(object, new ArcOperation(
-                object.getObjectId(),
-                targetId,
-                relationshipName,
-                true));
-    }
-
-    /**
      * Registers object change.
      * 
      * @since 1.2
@@ -1037,27 +1000,33 @@
             String property,
             Object oldValue,
             Object newValue) {
-        
+
         Persistent object = (Persistent) getNode(nodeId);
         registerDiff(object, null);
     }
 
     /**
-     * Does nothing.
-     * 
      * @since 1.2
      */
     public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
-        throw new UnsupportedOperationException("arcCreated");
+        Persistent object = (Persistent) getNode(nodeId);
+        registerDiff(object, new ArcOperation(
+                object.getObjectId(),
+                targetNodeId,
+                arcId.toString(),
+                false));
     }
 
     /**
-     * Does nothing.
-     * 
      * @since 1.2
      */
     public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
-        throw new UnsupportedOperationException("arcDeleted");
+        Persistent object = (Persistent) getNode(nodeId);
+        registerDiff(object, new ArcOperation(
+                object.getObjectId(),
+                targetNodeId,
+                arcId.toString(),
+                true));
     }
 
     // an ObjectIdQuery optimized for retrieval of multiple snapshots - it can be reset



Mime
View raw message