cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r631720 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote: ClientChannelServerDiffsListener1.java ClientChannelServerDiffsTest.java
Date Wed, 27 Feb 2008 20:49:38 GMT
Author: aadamchik
Date: Wed Feb 27 12:49:37 2008
New Revision: 631720

URL: http://svn.apache.org/viewvc?rev=631720&view=rev
Log:
CAY-789 return object diff to client in ROP after commit
(simple property change test)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsTest.java

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java?rev=631720&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
Wed Feb 27 12:49:37 2008
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.remote;
+
+import org.apache.cayenne.testdo.mt.MtTable1;
+
+public class ClientChannelServerDiffsListener1 {
+
+    public void prePersist(MtTable1 object) {
+        object.setGlobalAttribute1("XXX");
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsTest.java?rev=631720&r1=631719&r2=631720&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsTest.java
Wed Feb 27 12:49:37 2008
@@ -18,14 +18,20 @@
  ****************************************************************/
 package org.apache.cayenne.remote;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.access.ClientServerChannel;
 import org.apache.cayenne.graph.GraphChangeHandler;
 import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.map.LifecycleEvent;
+import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
 import org.apache.cayenne.remote.service.LocalConnection;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.MtTable1;
 import org.apache.cayenne.unit.AccessStack;
 import org.apache.cayenne.unit.CayenneCase;
 import org.apache.cayenne.unit.CayenneResources;
@@ -74,11 +80,78 @@
 
         assertTrue(ids[0] instanceof ObjectId);
         assertTrue(((ObjectId) ids[0]).isTemporary());
-        
+
         assertTrue(ids[1] instanceof ObjectId);
         assertFalse(((ObjectId) ids[1]).isTemporary());
     }
 
+    public void testReturnDiffInPrePersist() {
+
+        final List<GenericDiff> diffs = new ArrayList<GenericDiff>();
+        final GraphChangeHandler diffReader = new NoopGraphChangeHandler() {
+
+            @Override
+            public void nodePropertyChanged(
+                    Object nodeId,
+                    String property,
+                    Object oldValue,
+                    Object newValue) {
+                diffs
+                        .add(new GenericDiff(
+                                (ObjectId) nodeId,
+                                property,
+                                oldValue,
+                                newValue));
+            }
+        };
+
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        try {
+
+            registry.addListener(
+                    LifecycleEvent.PRE_PERSIST,
+                    MtTable1.class,
+                    new ClientChannelServerDiffsListener1(),
+                    "prePersist");
+
+            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
+            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel)) {
+
+                @Override
+                public GraphDiff onSync(
+                        ObjectContext originatingContext,
+                        GraphDiff changes,
+                        int syncType) {
+
+                    GraphDiff serverDiff = super.onSync(
+                            originatingContext,
+                            changes,
+                            syncType);
+
+                    assertNotNull(serverDiff);
+                    serverDiff.apply(diffReader);
+                    return serverDiff;
+                }
+            };
+
+            CayenneContext context = new CayenneContext(channel);
+            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
+            context.commitChanges();
+
+//            assertEquals(1, diffs.size());
+//            assertEquals(o.getObjectId(), diffs.get(0).sourceId);
+//            assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, diffs.get(0).property);
+//            assertNull(diffs.get(0).oldValue);
+//            assertEquals("XXX", diffs.get(0).newValue);
+        }
+        finally {
+            registry.clear();
+        }
+    }
+
     class NoopGraphChangeHandler implements GraphChangeHandler {
 
         public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
@@ -102,6 +175,29 @@
 
         public void nodeRemoved(Object nodeId) {
         }
+    }
+
+    class GenericDiff {
+
+        private String property;
+        private Object oldValue;
+        private Object newValue;
+        private ObjectId sourceId;
+        private ObjectId targetId;
+
+        GenericDiff(ObjectId sourceId, String property, Object oldValue, Object newValue)
{
+
+            this(sourceId, null, property, oldValue, newValue);
+        }
 
+        GenericDiff(ObjectId sourceId, ObjectId targetId, String property,
+                Object oldValue, Object newValue) {
+
+            this.sourceId = sourceId;
+            this.targetId = targetId;
+            this.property = property;
+            this.oldValue = oldValue;
+            this.newValue = newValue;
+        }
     }
 }



Mime
View raw message