cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r703991 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/ test/java/org/apache/cayenne/remote/
Date Mon, 13 Oct 2008 09:48:38 GMT
Author: andrey
Date: Mon Oct 13 02:48:38 2008
New Revision: 703991

URL: http://svn.apache.org/viewvc?rev=703991&view=rev
Log:
CAY-1118 ROP: setToXXX(null) does not update reverse rel
Changes, tests, some modifications to rollback processing

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RelationshipChangeTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteCayenneCase.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteRollbackTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java?rev=703991&r1=703990&r2=703991&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphAction.java
Mon Oct 13 02:48:38 2008
@@ -140,12 +140,28 @@
 
     private void unsetReverse(
             ArcProperty property,
-            Persistent sourceObject,
-            Persistent targetObject) {
+            final Persistent sourceObject,
+            final Persistent targetObject) {
 
         ArcProperty reverseArc = property.getComplimentaryReverseArc();
         if (reverseArc != null) {
-            reverseArc.writePropertyDirectly(targetObject, sourceObject, null);
+            reverseArc.visit(new PropertyVisitor() {
+
+                public boolean visitToMany(ToManyProperty property) {
+                    property.removeTarget(targetObject, sourceObject, false);
+                    return false;
+                }
+
+                public boolean visitToOne(ToOneProperty property) {
+                    property.setTarget(targetObject, null, false);
+                    return false;
+                }
+
+                public boolean visitAttribute(AttributeProperty property) {
+                    return false;
+                }
+
+            });
 
             context.getGraphManager().arcDeleted(
                     targetObject.getObjectId(),

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java?rev=703991&r1=703990&r2=703991&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextGraphManager.java
Mon Oct 13 02:48:38 2008
@@ -343,10 +343,12 @@
      */
     class RollbackChangeHandler implements GraphChangeHandler {
         public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
+            context.mergeHandler.arcCreated(nodeId, targetNodeId, arcId);
             CayenneContextGraphManager.this.arcCreated(nodeId, targetNodeId, arcId);
         }
 
         public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
+            context.mergeHandler.arcDeleted(nodeId, targetNodeId, arcId);
             CayenneContextGraphManager.this.arcDeleted(nodeId, targetNodeId, arcId);
         }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RelationshipChangeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RelationshipChangeTest.java?rev=703991&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RelationshipChangeTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RelationshipChangeTest.java
Mon Oct 13 02:48:38 2008
@@ -0,0 +1,57 @@
+/*****************************************************************
+ *   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.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.ClientMtTable2;
+
+/**
+ * This is a test primarily for CAY-1118
+ */
+public class RelationshipChangeTest extends RemoteCayenneCase {
+
+    public void testNullify() {
+        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
+        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
+        
+        o2.setTable1(o1);
+
+        assertEquals(1, o1.getTable2Array().size());
+        context.commitChanges();
+
+        o2.setTable1(null);
+        assertEquals(0, o1.getTable2Array().size());
+    }
+    
+    public void testChange() {
+        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
+        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
+        
+        ClientMtTable1 o3 = context.newObject(ClientMtTable1.class);
+        
+        o2.setTable1(o1);
+
+        assertEquals(1, o1.getTable2Array().size());
+        context.commitChanges();
+
+        o2.setTable1(o3);
+        assertEquals(0, o1.getTable2Array().size());
+        assertEquals(1, o3.getTable2Array().size());
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteCayenneCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteCayenneCase.java?rev=703991&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteCayenneCase.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteCayenneCase.java
Mon Oct 13 02:48:38 2008
@@ -0,0 +1,52 @@
+/*****************************************************************
+ *   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.CayenneContext;
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.UnitLocalConnection;
+
+/**
+ * JUnit case to test ROP functionality
+ * @author Andrey Razumovsky
+ */
+public abstract class RemoteCayenneCase extends CayenneCase {
+    protected CayenneContext context;
+    
+    @Override
+    public void setUp() throws Exception {
+        DataContext dataContext = createDataContext();
+        ClientServerChannel clientServerChannel = new ClientServerChannel(dataContext);
+        UnitLocalConnection connection = new UnitLocalConnection(
+                clientServerChannel,
+                LocalConnection.HESSIAN_SERIALIZATION);
+        ClientChannel channel = new ClientChannel(connection);
+        context = new CayenneContext(channel, true, true);
+    }
+    
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteRollbackTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteRollbackTest.java?rev=703991&r1=703990&r2=703991&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteRollbackTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/RemoteRollbackTest.java
Mon Oct 13 02:48:38 2008
@@ -18,40 +18,14 @@
  ****************************************************************/
 package org.apache.cayenne.remote;
 
-import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataContext;
-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.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
-import org.apache.cayenne.unit.UnitLocalConnection;
 
 /**
  * This is a test primarily for CAY-1103
  */
-public class RemoteRollbackTest extends CayenneCase {
-    CayenneContext context;
-    
-    @Override
-    public void setUp() throws Exception {
-        DataContext dataContext = createDataContext();
-        ClientServerChannel clientServerChannel = new ClientServerChannel(dataContext);
-        UnitLocalConnection connection = new UnitLocalConnection(
-                clientServerChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel channel = new ClientChannel(connection);
-        context = new CayenneContext(channel, true, true);
-    }
-    
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
-       
+public class RemoteRollbackTest extends RemoteCayenneCase {
     public void testRollbackNew() {
         ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
         o1.setGlobalAttribute1("a");
@@ -117,31 +91,26 @@
         assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
     }
 
-// TODO: Recheck once CAY-1118 is fixed    
-//    public void testRollbackRelationshipModification() {
-//        String o1Name = "relationshipModClientMtTable1";
-//        String o2Title = "relationshipTestClientMtTable2";
-//        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
-//        o1.setGlobalAttribute1(o1Name);
-//        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
-//        o2.setGlobalAttribute(o2Title);
-//        o2.setTable1(o1);
-//        
-//        assertEquals(1, o1.getTable2Array().size());
-//        context.commitChanges();
-//
-//        assertEquals(1, o1.getTable2Array().size());
-//        o2.setTable1(null);
-//        assertEquals(0, o1.getTable2Array().size());
-//        context.rollbackChanges();
-//
-//        assertTrue(((ValueHolder) o1.getTable2Array()).isFault());
-//        assertEquals(1, o1.getTable2Array().size());
-//        assertEquals(o1, o2.getTable1());
-//
-//        // Check that the reverse relationship was handled
-//        assertEquals(1, o1.getTable2Array().size());
-//    }
+    public void testRollbackRelationshipModification() {
+        String o1Name = "relationshipModClientMtTable1";
+        String o2Title = "relationshipTestClientMtTable2";
+        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
+        o1.setGlobalAttribute1(o1Name);
+        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
+        o2.setGlobalAttribute(o2Title);
+        o2.setTable1(o1);
+        
+        assertEquals(1, o1.getTable2Array().size());
+        context.commitChanges();
+
+        assertEquals(1, o1.getTable2Array().size());
+        o2.setTable1(null);
+        assertEquals(0, o1.getTable2Array().size());
+        context.rollbackChanges();
+
+        assertEquals(1, o1.getTable2Array().size());
+        assertEquals(o1, o2.getTable1());
+    }
 
     public void testRollbackDeletedObject() {
         String o1Name = "deleteTestClientMtTable1";



Mime
View raw message