jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r725292 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ItemImpl.java test/java/org/apache/jackrabbit/core/MoveTest.java
Date Wed, 10 Dec 2008 14:17:31 GMT
Author: thomasm
Date: Wed Dec 10 06:17:30 2008
New Revision: 725292

URL: http://svn.apache.org/viewvc?rev=725292&view=rev
Log:
JCR-1883 Moved node disappears

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=725292&r1=725291&r2=725292&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Wed Dec 10 06:17:30 2008
@@ -1171,11 +1171,20 @@
             switch (transientState.getStatus()) {
                 case ItemState.STATUS_STALE_MODIFIED:
                 case ItemState.STATUS_STALE_DESTROYED:
-                case ItemState.STATUS_EXISTING_MODIFIED:
                     // add this item's state to the list
                     list.add(transientState);
                     break;
 
+                case ItemState.STATUS_EXISTING_MODIFIED:
+                    if (!transientState.getParentId().equals(
+                            transientState.getOverlayedState().getParentId())) {
+                        throw new RepositoryException(
+                                "Cannot refresh a moved item: " + this +
+                                " - possible solution: refresh the parent");
+                    }
+                    list.add(transientState);
+                    break;
+
                 case ItemState.STATUS_NEW:
                     throw new RepositoryException(
                             "Cannot refresh a new item: " + this);

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java?rev=725292&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
Wed Dec 10 06:17:30 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.jackrabbit.core;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Tests moving, refreshing, and saving nodes.
+ */
+public class MoveTest extends AbstractJCRTest {
+
+    /**
+     * Tests moving a node, and then refreshing or saving it.
+     */
+    public void testMove() throws RepositoryException {
+        doTestMove(true);
+        doTestMove(false);
+    }
+
+    private void doTestMove(boolean save) throws RepositoryException {
+        Session session = testRootNode.getSession();
+        for (NodeIterator it = testRootNode.getNodes(); it.hasNext();) {
+            it.nextNode().remove();
+            session.save();
+        }
+        Node node1 = testRootNode.addNode(nodeName1);
+        Node node2 = node1.addNode(nodeName2);
+        session.save();
+        String from = node2.getPath();
+        String to = node1.getParent().getPath() + "/" + nodeName2;
+        session.move(from, to);
+        try {
+            if (save) {
+                node2.save();
+            } else {
+                node2.refresh(false);
+            }
+            fail("Refresh and Save should not work for moved nodes");
+        } catch (RepositoryException e) {
+            // expected
+        }
+        session.save();
+        NodeIterator it = node2.getParent().getNodes(nodeName2);
+        assertTrue(it.hasNext());
+        it.nextNode();
+        assertFalse(it.hasNext());
+        node2.getParent().getPath();
+
+        // for (it = testRootNode.getNodes(); it.hasNext();) {
+             // System.out.println(it.nextNode().getPath());
+        // }
+        String now = node2.getPath();
+        assertEquals(testRootNode.getPath() + "/" + nodeName2, now);
+    }
+
+}



Mime
View raw message