cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r618112 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/
Date Sun, 03 Feb 2008 22:42:14 GMT
Author: aadamchik
Date: Sun Feb  3 14:42:14 2008
New Revision: 618112

URL: http://svn.apache.org/viewvc?rev=618112&view=rev
Log:
CAY-971  ROP GraphDiff "compressor"

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/GraphDiffCompressor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=618112&r1=618111&r2=618112&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Sun Feb  3 14:42:14 2008
@@ -15,6 +15,7 @@
 Changes/New Features Since M3:
 
 CAY-970 Allow application to add DbAdatperFactory to AutoAdapter
+CAY-971 ROP GraphDiff "compressor"
 CAY-980 Upgrade Derby to 10.3 to support alter table drop column
 
 Bug fixes since M3:

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/GraphDiffCompressor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/GraphDiffCompressor.java?rev=618112&r1=618111&r2=618112&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/GraphDiffCompressor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/graph/GraphDiffCompressor.java
Sun Feb  3 14:42:14 2008
@@ -20,11 +20,15 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
- * A utility class that removes redundant graph changes from the graph diff.
+ * A utility class that removes redundant and mutually exclusive graph changes from the
+ * graph diff.
  * 
  * @author Andrus Adamchik
  * @since 3.0
@@ -46,8 +50,43 @@
 
         private List<GraphDiff> compressed = new ArrayList<GraphDiff>();
         private Map<Object, List<NodeDiff>> diffsByNode = new HashMap<Object,
List<NodeDiff>>();
+        private Set<Object> deletedNodes;
+        private Set<Object> createdNodes;
 
         GraphDiff getCompressedDiff() {
+
+            // remove deleted nodes...
+            if (deletedNodes != null) {
+
+                for (Object nodeId : deletedNodes) {
+
+                    Iterator<GraphDiff> it = compressed.iterator();
+
+                    // if the node was inserted in the same transaction and later deleted,
+                    // remove all its ops. Otherwise preserve arc ops (since delete rules
+                    // depend on them), and delete operation itself.
+                    if (createdNodes != null && createdNodes.contains(nodeId)) {
+                        while (it.hasNext()) {
+                            NodeDiff diff = (NodeDiff) it.next();
+                            if (nodeId.equals(diff.getNodeId())) {
+                                it.remove();
+                            }
+                        }
+                    }
+                    else {
+                        while (it.hasNext()) {
+                            NodeDiff diff = (NodeDiff) it.next();
+                            if (nodeId.equals(diff.getNodeId())) {
+                                if (diff instanceof NodePropertyChangeOperation) {
+                                    it.remove();
+                                }
+                            }
+                        }
+                    }
+
+                }
+            }
+
             return new CompoundDiff(compressed);
         }
 
@@ -99,6 +138,12 @@
 
         public void nodeCreated(Object nodeId) {
             registerDiff(new NodeCreateOperation(nodeId));
+
+            if (createdNodes == null) {
+                createdNodes = new HashSet<Object>();
+            }
+
+            createdNodes.add(nodeId);
         }
 
         public void nodeIdChanged(Object nodeId, Object newId) {
@@ -106,7 +151,14 @@
         }
 
         public void nodeRemoved(Object nodeId) {
+
             registerDiff(new NodeDeleteOperation(nodeId));
+
+            if (deletedNodes == null) {
+                deletedNodes = new HashSet<Object>();
+            }
+
+            deletedNodes.add(nodeId);
         }
 
         public void nodePropertyChanged(
@@ -138,6 +190,7 @@
         }
 
         private void registerDiff(NodeDiff diff) {
+
             compressed.add(diff);
             List<NodeDiff> diffs = diffsByNode.get(diff.getNodeId());
             if (diffs == null) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java?rev=618112&r1=618111&r2=618112&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java
Sun Feb  3 14:42:14 2008
@@ -74,6 +74,24 @@
         assertEquals(0, serverChannel.arcsDeleted);
     }
 
+    public void testDelete() {
+        DiffCounter serverChannel = new DiffCounter(getDomain());
+        LocalConnection connection = new LocalConnection(
+                serverChannel,
+                LocalConnection.HESSIAN_SERIALIZATION);
+        ClientChannel channel = new ClientChannel(connection);
+        CayenneContext context = new CayenneContext(channel);
+
+        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
+        o1.setGlobalAttribute1("v1");
+        context.deleteObject(o1);
+
+        context.commitChanges();
+        assertEquals(0, serverChannel.nodePropertiesChanged);
+        assertEquals(0, serverChannel.nodesCreated);
+        assertEquals(0, serverChannel.nodesRemoved);
+    }
+
     final class DiffCounter extends ClientServerChannel implements GraphChangeHandler {
 
         int arcsCreated;



Mime
View raw message