cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r632605 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: CayenneContextServerDiffsTest.java remote/ClientChannelServerDiffsListener1.java
Date Sat, 01 Mar 2008 15:47:26 GMT
Author: aadamchik
Date: Sat Mar  1 07:47:26 2008
New Revision: 632605

URL: http://svn.apache.org/viewvc?rev=632605&view=rev
Log:
CAY-789 return object diff to client in ROP after commit
(more tests)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextServerDiffsTest.java
Modified:
    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/CayenneContextServerDiffsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextServerDiffsTest.java?rev=632605&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextServerDiffsTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextServerDiffsTest.java
Sat Mar  1 07:47:26 2008
@@ -0,0 +1,166 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.map.LifecycleEvent;
+import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.ClientChannelServerDiffsListener1;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.ClientMtTable2;
+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;
+
+public class CayenneContextServerDiffsTest extends CayenneCase {
+
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    }
+
+    public void testReturnDiffInPrePersist() {
+
+        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));
+            CayenneContext context = new CayenneContext(channel);
+            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
+            o.setServerAttribute1("YY");
+            context.commitChanges();
+
+            assertFalse(o.getObjectId().isTemporary());
+            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+            assertEquals("XXX", o.getGlobalAttribute1());
+        }
+        finally {
+            registry.clear();
+        }
+    }
+
+    public void testReturnDiffInPreUpdate() {
+
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        try {
+
+            registry.addListener(
+                    LifecycleEvent.PRE_UPDATE,
+                    MtTable1.class,
+                    new ClientChannelServerDiffsListener1(),
+                    "preUpdate");
+
+            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
+            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
+            CayenneContext context = new CayenneContext(channel);
+            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
+            o.setServerAttribute1("YY");
+            context.commitChanges();
+
+            assertNull(o.getGlobalAttribute1());
+
+            o.setServerAttribute1("XX");
+            context.commitChanges();
+
+            assertFalse(o.getObjectId().isTemporary());
+            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+            assertEquals("111", o.getGlobalAttribute1());
+        }
+        finally {
+            registry.clear();
+        }
+    }
+
+    public void testReturnDiffClientArcChanges() {
+
+        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));
+            CayenneContext context = new CayenneContext(channel);
+            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
+            ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
+            o.addToTable2Array(o1);
+            context.commitChanges();
+
+            assertFalse(o.getObjectId().isTemporary());
+            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+            assertEquals("XXX", o.getGlobalAttribute1());
+        }
+        finally {
+            registry.clear();
+        }
+    }
+
+    public void testReturnDiffServerArcChanges() {
+
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        try {
+            registry.addListener(
+                    LifecycleEvent.PRE_PERSIST,
+                    MtTable1.class,
+                    new ClientChannelServerDiffsListener1(),
+                    "prePersistAddRelationship");
+
+            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
+            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
+            CayenneContext context = new CayenneContext(channel);
+            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
+            ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
+            o.addToTable2Array(o1);
+            context.commitChanges();
+
+            assertFalse(o.getObjectId().isTemporary());
+            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+            assertEquals(2, o.getTable2Array().size());
+            
+        }
+        finally {
+            registry.clear();
+        }
+    }
+}

Modified: 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=632605&r1=632604&r2=632605&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/ClientChannelServerDiffsListener1.java
Sat Mar  1 07:47:26 2008
@@ -19,10 +19,19 @@
 package org.apache.cayenne.remote;
 
 import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.testdo.mt.MtTable2;
 
 public class ClientChannelServerDiffsListener1 {
 
     public void prePersist(MtTable1 object) {
         object.setGlobalAttribute1("XXX");
+    }
+    
+    public void preUpdate(MtTable1 object) {
+        object.setGlobalAttribute1("111");
+    }
+    
+    public void prePersistAddRelationship(MtTable1 object) {
+        object.addToTable2Array(object.getObjectContext().newObject(MtTable2.class));
     }
 }



Mime
View raw message