cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1033690 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Wed, 10 Nov 2010 20:12:54 GMT
Author: aadamchik
Date: Wed Nov 10 20:12:53 2010
New Revision: 1033690

URL: http://svn.apache.org/viewvc?rev=1033690&view=rev
Log:
CAY-1505 Callbacks: POST_UPDATE is called on updated removed object, instead of POST_REMOVE

Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java

Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1033690&r1=1033689&r2=1033690&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Wed Nov
10 20:12:53 2010
@@ -25,6 +25,7 @@ CAY-1488 OutOfMemory when selecting "Rem
 CAY-1489 NPE using DataContext.objectFromDataRow for a nested context
 CAY-1490 Maven cgen: all and datamap modes can not be activated
 CAY-1496 Problem in derby: comparison operators are not supported on Clob object values.

+CAY-1505 Callbacks: POST_UPDATE is called on updated removed object, instead of POST_REMOVE
 
 ----------------------------------
 Release: 3.0.1

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java?rev=1033690&r1=1033689&r2=1033690&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
Wed Nov 10 20:12:53 2010
@@ -20,8 +20,8 @@ package org.apache.cayenne.access;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.graph.GraphChangeHandler;
@@ -35,6 +35,10 @@ import org.apache.cayenne.reflect.Lifecy
  */
 abstract class DataChannelSyncCallbackAction implements GraphChangeHandler {
 
+    static enum Op {
+        INSERT, UPDATE, DELETE
+    }
+
     static DataChannelSyncCallbackAction getCallbackAction(
             LifecycleCallbackRegistry callbackRegistry,
             GraphManager graphManager,
@@ -56,7 +60,7 @@ abstract class DataChannelSyncCallbackAc
     Collection updated;
     Collection persisted;
     Collection removed;
-    private Set<Object> seenIds;
+    private Map<Object, Op> seenIds;
     private GraphManager graphManager;
 
     DataChannelSyncCallbackAction(LifecycleCallbackRegistry callbackRegistry,
@@ -66,7 +70,7 @@ abstract class DataChannelSyncCallbackAc
         this.graphManager = graphManager;
 
         if (hasListeners()) {
-            this.seenIds = new HashSet<Object>();
+            this.seenIds = new HashMap<Object, Op>();
             changes.apply(this);
         }
     }
@@ -84,13 +88,14 @@ abstract class DataChannelSyncCallbackAc
     }
 
     public void nodeCreated(Object nodeId) {
-        if (seenIds.add(nodeId)) {
+        Op op = seenIds.put(nodeId, Op.INSERT);
+        if (op == null) {
 
             Object node = graphManager.getNode(nodeId);
             if (node != null) {
 
                 if (persisted == null) {
-                    persisted = new ArrayList();
+                    persisted = new ArrayList<Object>();
                 }
 
                 persisted.add(node);
@@ -99,16 +104,26 @@ abstract class DataChannelSyncCallbackAc
     }
 
     public void nodeRemoved(Object nodeId) {
-        if (seenIds.add(nodeId)) {
+        Op op = seenIds.put(nodeId, Op.DELETE);
+
+        // the node may have been updated prior to delete
+        if (op != Op.DELETE) {
 
             Object node = graphManager.getNode(nodeId);
             if (node != null) {
 
                 if (removed == null) {
-                    removed = new ArrayList();
+                    removed = new ArrayList<Object>();
                 }
 
                 removed.add(node);
+
+                if (op == Op.UPDATE) {
+                    updated.remove(node);
+                }
+
+                // don't care about preceding Op.INSERT, as NEW -> DELETED objects are
+                // purged from the change log upstream and we don't see them here
             }
         }
     }
@@ -135,13 +150,16 @@ abstract class DataChannelSyncCallbackAc
     }
 
     private void nodeUpdated(Object nodeId) {
-        if (seenIds.add(nodeId)) {
+        
+        Op op = seenIds.put(nodeId, Op.UPDATE);
+        
+        if (op == null) {
 
             Object node = graphManager.getNode(nodeId);
             if (node != null) {
 
                 if (updated == null) {
-                    updated = new ArrayList();
+                    updated = new ArrayList<Object>();
                 }
 
                 updated.add(node);

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java?rev=1033690&r1=1033689&r2=1033690&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
Wed Nov 10 20:12:53 2010
@@ -219,6 +219,81 @@ public class DataDomainCallbacksTest ext
         assertTrue(a1.isPostRemoved());
         assertSame(a1, listener2.getPublicCalledbackEntity());
     }
+    
+    public void testPostRemove_UpdatedDeleted() {
+
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        ObjectContext context = createDataContext();
+
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("XX");
+        context.commitChanges();
+
+        MockCallingBackListener listener1 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.POST_REMOVE,
+                Artist.class,
+                listener1,
+                "publicCallback");
+
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.POST_UPDATE,
+                Artist.class,
+                listener2,
+                "publicCallback");
+
+
+        // change before removing
+        a1.setArtistName("YY");
+        context.deleteObject(a1);
+        context.commitChanges();
+
+        assertNull(listener2.getPublicCalledbackEntity());
+        assertSame(a1, listener1.getPublicCalledbackEntity());
+    }
+    
+    public void testPostRemove_InsertedUpdatedDeleted() {
+
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        ObjectContext context = createDataContext();
+
+        MockCallingBackListener listener0 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.POST_PERSIST,
+                Artist.class,
+                listener0,
+                "publicCallback");
+        
+        MockCallingBackListener listener1 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.POST_REMOVE,
+                Artist.class,
+                listener1,
+                "publicCallback");
+
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.POST_UPDATE,
+                Artist.class,
+                listener2,
+                "publicCallback");
+
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("XX");
+        context.deleteObject(a1);
+        context.commitChanges();
+
+        assertNull(listener0.getPublicCalledbackEntity());
+        assertNull(listener1.getPublicCalledbackEntity());
+        assertNull(listener2.getPublicCalledbackEntity());
+    }
 
     public void testPostPersist() {
 



Mime
View raw message