cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454230 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/access/
Date Sun, 08 Oct 2006 23:03:30 GMT
Author: aadamchik
Date: Sun Oct  8 16:03:30 2006
New Revision: 454230

URL: http://svn.apache.org/viewvc?view=rev&rev=454230
Log:
CAY-680 - final refactoring of the objectstore diff handling API

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/ObjectStore.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataRowUtilsTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/FlattenedRelationshipInContextTst.java

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=454230&r1=454229&r2=454230
==============================================================================
--- 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 16:03:30 2006
@@ -108,48 +108,49 @@
      * 
      * @since 1.2
      */
-    synchronized ObjectDiff registerDiff(Persistent object, NodeDiff diff) {
+    synchronized ObjectDiff registerDiff(Object nodeId, NodeDiff diff) {
 
-        ObjectId id = object.getObjectId();
+        if (diff != null) {
+            diff.setDiffId(++currentDiffId);
+        }
 
-        if (object.getPersistenceState() == PersistenceState.COMMITTED) {
-            object.setPersistenceState(PersistenceState.MODIFIED);
+        ObjectDiff objectDiff = (ObjectDiff) changes.get(nodeId);
 
-            // TODO: andrus 3/23/2006 snapshot versions are obsolete, but there is no
-            // replacement yet, so we still need to handle them...
-            if (object instanceof DataObject) {
+        if (objectDiff == null) {
 
-                DataObject dataObject = (DataObject) object;
-                DataRow snapshot = getCachedSnapshot(id);
+            Persistent object = (Persistent) objectMap.get(nodeId);
+            if (object.getPersistenceState() == PersistenceState.COMMITTED) {
+                object.setPersistenceState(PersistenceState.MODIFIED);
+
+                // TODO: andrus 3/23/2006 snapshot versions are obsolete, but there is no
+                // replacement yet, so we still need to handle them...
+                if (object instanceof DataObject) {
 
-                if (snapshot != null
-                        && snapshot.getVersion() != dataObject.getSnapshotVersion())
{
-                    DataContextDelegate delegate = context.nonNullDelegate();
-                    if (delegate.shouldMergeChanges(dataObject, snapshot)) {
-                        ObjEntity entity = context.getEntityResolver().lookupObjEntity(
-                                object);
-                        DataRowUtils.forceMergeWithSnapshot(
-                                context,
-                                entity,
-                                dataObject,
-                                snapshot);
-                        dataObject.setSnapshotVersion(snapshot.getVersion());
-                        delegate.finishedMergeChanges(dataObject);
+                    DataObject dataObject = (DataObject) object;
+                    DataRow snapshot = getCachedSnapshot((ObjectId) nodeId);
+
+                    if (snapshot != null
+                            && snapshot.getVersion() != dataObject.getSnapshotVersion())
{
+                        DataContextDelegate delegate = context.nonNullDelegate();
+                        if (delegate.shouldMergeChanges(dataObject, snapshot)) {
+                            ObjEntity entity = context
+                                    .getEntityResolver()
+                                    .lookupObjEntity(object);
+                            DataRowUtils.forceMergeWithSnapshot(
+                                    context,
+                                    entity,
+                                    dataObject,
+                                    snapshot);
+                            dataObject.setSnapshotVersion(snapshot.getVersion());
+                            delegate.finishedMergeChanges(dataObject);
+                        }
                     }
                 }
             }
-        }
 
-        if (diff != null) {
-            diff.setDiffId(++currentDiffId);
-        }
-
-        ObjectDiff objectDiff = (ObjectDiff) changes.get(id);
-
-        if (objectDiff == null) {
             objectDiff = new ObjectDiff(this, object);
             objectDiff.setDiffId(++currentDiffId);
-            changes.put(id, objectDiff);
+            changes.put(nodeId, objectDiff);
         }
 
         if (diff != null) {
@@ -978,16 +979,14 @@
      * @since 1.2
      */
     public void nodeCreated(Object nodeId) {
-        Persistent object = (Persistent) getNode(nodeId);
-        registerDiff(object, new NodeCreateOperation(object.getObjectId()));
+        registerDiff(nodeId, new NodeCreateOperation(nodeId));
     }
 
     /**
      * @since 1.2
      */
     public void nodeRemoved(Object nodeId) {
-        Persistent object = (Persistent) getNode(nodeId);
-        registerDiff(object, new NodeDeleteOperation(nodeId));
+        registerDiff(nodeId, new NodeDeleteOperation(nodeId));
     }
 
     /**
@@ -1001,17 +1000,15 @@
             Object oldValue,
             Object newValue) {
 
-        Persistent object = (Persistent) getNode(nodeId);
-        registerDiff(object, null);
+        registerDiff(nodeId, null);
     }
 
     /**
      * @since 1.2
      */
     public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
-        Persistent object = (Persistent) getNode(nodeId);
-        registerDiff(object, new ArcOperation(
-                object.getObjectId(),
+        registerDiff(nodeId, new ArcOperation(
+                nodeId,
                 targetNodeId,
                 arcId.toString(),
                 false));
@@ -1021,9 +1018,8 @@
      * @since 1.2
      */
     public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
-        Persistent object = (Persistent) getNode(nodeId);
-        registerDiff(object, new ArcOperation(
-                object.getObjectId(),
+        registerDiff(nodeId, new ArcOperation(
+                nodeId,
                 targetNodeId,
                 arcId.toString(),
                 true));

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataRowUtilsTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataRowUtilsTst.java?view=diff&rev=454230&r1=454229&r2=454230
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataRowUtilsTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataRowUtilsTst.java
Sun Oct  8 16:03:30 2006
@@ -91,7 +91,7 @@
         Artist artist = (Artist) context.performQuery(artistQ).get(0);
         assertNotSame(artist, painting.getToArtist());
 
-        ObjectDiff diff = context.getObjectStore().registerDiff(painting, null);
+        ObjectDiff diff = context.getObjectStore().registerDiff(painting.getObjectId(), null);
 
         assertFalse(DataRowUtils.isToOneTargetModified(toArtist, painting, diff));
 
@@ -112,7 +112,7 @@
         ObjRelationship toGallery = (ObjRelationship) paintingEntity
                 .getRelationship("toGallery");
 
-        ObjectDiff diff = context.getObjectStore().registerDiff(p1, null);
+        ObjectDiff diff = context.getObjectStore().registerDiff(p1.getObjectId(), null);
         assertFalse(DataRowUtils.isToOneTargetModified(toGallery, p1, diff));
 
         Gallery g1 = (Gallery) context.createAndRegisterNewObject("Gallery");

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/FlattenedRelationshipInContextTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/FlattenedRelationshipInContextTst.java?view=diff&rev=454230&r1=454229&r2=454230
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/FlattenedRelationshipInContextTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/FlattenedRelationshipInContextTst.java
Sun Oct  8 16:03:30 2006
@@ -52,7 +52,7 @@
         ObjEntity entity = context.getEntityResolver().lookupObjEntity(
                 FlattenedTest3.class);
         ObjRelationship flattenedRel = (ObjRelationship) entity.getRelationship("toFT1");
-        ObjectDiff diff = context.getObjectStore().registerDiff(ft3, null);
+        ObjectDiff diff = context.getObjectStore().registerDiff(ft3.getObjectId(), null);
         assertFalse(DataRowUtils.isToOneTargetModified(flattenedRel, ft3, diff));
         assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
     }



Mime
View raw message