Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (date 1353106551000) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (date 1353254839000) @@ -34,47 +34,6 @@ public interface Root { /** - * Move the child located at {@code sourcePath} to a child at {@code destPath}. - * Both paths must be absolute and resolve to a child located beneath this - * root.
- * - * This method does nothing and returns {@code false} if - * - * If a tree at {@code destinationPath} exists but is not accessible to the - * editing content session this method succeeds but a subsequent - * {@link #commit()} will detect the violation and fail. - * - * @param sourcePath The source path - * @param destPath The destination path - * @return {@code true} on success, {@code false} otherwise. - */ - boolean move(String sourcePath, String destPath); - - /** - * Copy the child located at {@code sourcePath} to a child at {@code destPath}. - * Both paths must be absolute and resolve to a child located in this root.
- * - * This method does nothing an returns {@code false} if - * - * If a tree at {@code destinationPath} exists but is not accessible to the - * editing content session this method succeeds but a subsequent - * {@link #commit()} will detect the violation and fail. - * - * @param sourcePath source path - * @param destPath destination path - * @return {@code true} on success, {@code false} otherwise. - */ - boolean copy(String sourcePath, String destPath); - - /** * Retrieve the {@code Tree} at the given absolute {@code path}. The path * must resolve to a tree in this root. * Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (date 1353106551000) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (date 1353254839000) @@ -274,4 +274,26 @@ */ void removeProperty(String name); + /** + * Move this tree to a child of the destination tree with the + * given destination name. This method does nothing and returns + * {@code false} if a tree of that name already exists at the + * destination. + * @param destParent The parent tree of the destination + * @param destName The name of the moved tree + * @return {@code true} on success, {@code false} otherwise. + */ + boolean moveTo(Tree destParent, String destName); + + /** + * Copy this tree to a child of the destination tree with the + * given destination name. This method does nothing and returns + * {@code false} if a tree of that name already exists at the + * destination. + * @param destParent The parent tree of the destination + * @param destName The name of the copies tree + * @return {@code true} on success, {@code false} otherwise. + */ + boolean copyTo(Tree destParent, String destName); + } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java (date 1353106551000) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java (date 1353254839000) @@ -216,4 +216,14 @@ throw new UnsupportedOperationException(); } + @Override + public boolean moveTo(Tree destParent, String destName) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean copyTo(Tree destParent, String destName) { + throw new UnsupportedOperationException(); + } + } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (date 1353106551000) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (date 1353254839000) @@ -32,7 +32,9 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.SessionQueryEngine; +import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.TreeLocation; +import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.plugins.commit.DefaultConflictHandler; import org.apache.jackrabbit.oak.query.SessionQueryEngineImpl; import org.apache.jackrabbit.oak.spi.commit.ConflictHandler; @@ -51,7 +53,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.jackrabbit.oak.commons.PathUtils.getName; +import static org.apache.jackrabbit.oak.commons.PathUtils.concat; import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath; public class RootImpl implements Root { @@ -134,47 +136,8 @@ } //---------------------------------------------------------------< Root >--- - @Override - public boolean move(String sourcePath, String destPath) { - checkLive(); - TreeImpl source = rootTree.getTree(sourcePath); - if (source == null) { - return false; - } - TreeImpl destParent = rootTree.getTree(getParentPath(destPath)); - if (destParent == null) { - return false; - } - String destName = getName(destPath); - if (destParent.hasChild(destName)) { - return false; - } - - purgePendingChanges(); - source.moveTo(destParent, destName); - boolean success = branch.move(sourcePath, destPath); - reset(); - if (success) { - getTree(getParentPath(sourcePath)).updateChildOrder(); - getTree(getParentPath(destPath)).updateChildOrder(); - } - return success; - } - @Override - public boolean copy(String sourcePath, String destPath) { - checkLive(); - purgePendingChanges(); - boolean success = branch.copy(sourcePath, destPath); - reset(); - if (success) { - getTree(getParentPath(destPath)).updateChildOrder(); - } - return success; - } - - @Override public TreeImpl getTree(String path) { checkLive(); return rootTree.getTree(path); @@ -295,6 +258,51 @@ } //-----------------------------------------------------------< internal >--- + + /** + * Move a source tree to a child of the destination tree with the + * given destination name. This method does nothing and returns + * {@code false} if a tree of that name already exists at the + * destination. + * @param source The source tree + * @param destParent The parent tree of the destination + * @param destName The name of the moved tree + * @return {@code true} on success, {@code false} otherwise. + */ + boolean move(Tree source, Tree destParent, String destName) { + purgePendingChanges(); + String sourcePath = source.getPath(); + String destPath = concat(destParent.getPath(), destName); + boolean success = branch.move(sourcePath, destPath); + reset(); + if (success) { + getTree(getParentPath(sourcePath)).updateChildOrder(); + getTree(getParentPath(destPath)).updateChildOrder(); + } + return success; + } + + /** + * Copy a source tree to a child of the destination tree with the + * given destination name. This method does nothing and returns + * {@code false} if a tree of that name already exists at the + * destination. + * @param source The source tree + * @param destParent The parent tree of the destination + * @param destName The name of the copies tree + * @return {@code true} on success, {@code false} otherwise. + */ + boolean copy(Tree source, Tree destParent, String destName) { + purgePendingChanges(); + String sourcePath = source.getPath(); + String destPath = PathUtils.concat(destParent.getPath(), destName); + boolean success = branch.copy(sourcePath, destPath); + reset(); + if (success) { + getTree(getParentPath(destPath)).updateChildOrder(); + } + return success; + } /** * Returns the node state from which the current branch was created. Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (date 1353106551000) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (date 1353254839000) @@ -395,6 +395,49 @@ return new NodeLocation(this); } + /** + * Move this tree to the parent at {@code destParent} with the new name + * {@code destName}. + * + * @param destParent new parent for this tree + * @param destName new name for this tree + */ + @Override + public boolean moveTo(Tree destParent, String destName) { + root.checkLive(); + + checkArgument(destParent instanceof TreeImpl, "Cannot move between different implementations of Tree"); + if (isRemoved()) { + throw new IllegalStateException("Cannot move removed tree"); + } + + if (destParent.hasChild(destName)) { + return false; + } + + if (root.move(this, destParent, destName)) { + name = destName; + parent = (TreeImpl) destParent; + return true; + } else { + return false; + } + } + + @Override + public boolean copyTo(Tree destParent, String destName) { + root.checkLive(); + if (isRemoved()) { + throw new IllegalStateException("Cannot move removed tree"); + } + + if (destParent.hasChild(destName)) { + return false; + } + + return root.copy(this, destParent, destName); + } + //----------------------------------------------------------< protected >--- @CheckForNull @@ -418,22 +461,6 @@ } //-----------------------------------------------------------< internal >--- - - /** - * Move this tree to the parent at {@code destParent} with the new name - * {@code destName}. - * - * @param destParent new parent for this tree - * @param destName new name for this tree - */ - void moveTo(TreeImpl destParent, String destName) { - if (isRemoved()) { - throw new IllegalStateException("Cannot move removed tree"); - } - - name = destName; - parent = destParent; - } @Nonnull NodeState getNodeState() { Index: oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java (date 1353106551000) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/api/RootTest.java (date 1353254839000) @@ -59,7 +59,9 @@ t.addChild("node3"); r.commit(); - r.copy("/node3", "/c/node3"); + Tree node3 = r.getTree("/node3"); + c = r.getTree("/c"); + node3.moveTo(c, "node3"); c = r.getTree("/").getChild("c"); assertSequence(c.getChildren(), "node1", "node2", "node3"); r.commit(); @@ -82,7 +84,9 @@ t.addChild("node3"); r.commit(); - r.move("/node3", "/c/node3"); + Tree node3 = r.getTree("/node3"); + c = r.getTree("/c"); + node3.moveTo(c, "node3"); c = r.getTree("/").getChild("c"); assertSequence(c.getChildren(), "node1", "node2", "node3"); r.commit(); Index: oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java (date 1353106551000) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java (date 1353254839000) @@ -178,7 +178,9 @@ @Override void apply(RootImpl root) { - root.move(source, destination); + TreeImpl src = root.getTree(source); + TreeImpl destParent = root.getTree(PathUtils.getParentPath(destination)); + src.moveTo(destParent, PathUtils.getName(destination)); } @Override @@ -198,7 +200,9 @@ @Override void apply(RootImpl root) { - root.copy(source, destination); + TreeImpl src = root.getTree(source); + TreeImpl destParent = root.getTree(PathUtils.getParentPath(destination)); + src.copyTo(destParent, PathUtils.getName(destination)); } @Override Index: oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java (date 1353106551000) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java (date 1353254839000) @@ -95,10 +95,10 @@ Root root = session.getLatestRoot(); Tree tree = root.getTree("/"); + Tree x = tree.getChild("x"); Tree y = tree.getChild("y"); - assertTrue(tree.hasChild("x")); - root.move("/x", "/y/xx"); + x.moveTo(y, "xx"); assertFalse(tree.hasChild("x")); assertTrue(y.hasChild("xx")); @@ -117,10 +117,10 @@ public void removeMoved() throws CommitFailedException { Root root = session.getLatestRoot(); Tree r = root.getTree("/"); - r.addChild("a"); - r.addChild("b"); + Tree a = r.addChild("a"); + Tree b = r.addChild("b"); - root.move("/a", "/b/c"); + a.moveTo(b, "c"); assertFalse(r.hasChild("a")); assertTrue(r.hasChild("b")); @@ -137,9 +137,9 @@ public void rename() throws CommitFailedException { Root root = session.getLatestRoot(); Tree tree = root.getTree("/"); + Tree x = tree.getChild("x"); - assertTrue(tree.hasChild("x")); - root.move("/x", "/xx"); + x.moveTo(tree, "xx"); assertFalse(tree.hasChild("x")); assertTrue(tree.hasChild("xx")); @@ -155,11 +155,11 @@ Root root = session.getLatestRoot(); Tree tree = root.getTree("/"); + Tree x = tree.getChild("x"); Tree y = tree.getChild("y"); + x.copyTo(y, "xx"); assertTrue(tree.hasChild("x")); - root.copy("/x", "/y/xx"); - assertTrue(tree.hasChild("x")); assertTrue(y.hasChild("xx")); root.commit(); @@ -175,10 +175,11 @@ Root root = session.getLatestRoot(); Tree tree = root.getTree("/"); + Tree x = root.getTree("/x"); Tree y = tree.getChild("y"); + x.addChild("x1"); - root.getTree("/x").addChild("x1"); - root.copy("/x", "/y/xx"); + x.copyTo(y, "xx"); assertTrue(y.hasChild("xx")); assertTrue(y.getChild("xx").hasChild("x1")); @@ -190,7 +191,7 @@ assertTrue(tree.getChild("y").hasChild("xx")); assertTrue(tree.getChild("y").getChild("xx").hasChild("x1")); - Tree x = tree.getChild("x"); + x = tree.getChild("x"); Tree xx = tree.getChild("y").getChild("xx"); checkEqual(x, xx); } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (date 1353106551000) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (date 1353254839000) @@ -357,28 +357,29 @@ * @throws RepositoryException */ public void copy(String srcPath, String destPath) throws RepositoryException { + Root currentRoot = contentSession.getLatestRoot(); + // check destination - Tree dest = getTree(destPath); + Tree dest = currentRoot.getTree(destPath); if (dest != null) { throw new ItemExistsException(destPath); } // check parent of destination String destParentPath = PathUtils.getParentPath(destPath); - Tree destParent = getTree(destParentPath); + Tree destParent = currentRoot.getTree(destParentPath); if (destParent == null) { throw new PathNotFoundException(PathUtils.getParentPath(destPath)); } // check source exists - Tree src = getTree(srcPath); + Tree src = currentRoot.getTree(srcPath); if (src == null) { throw new PathNotFoundException(srcPath); } try { - Root currentRoot = contentSession.getLatestRoot(); - currentRoot.copy(srcPath, destPath); + src.copyTo(destParent, PathUtils.getName(destPath)); currentRoot.commit(); } catch (CommitFailedException e) { @@ -418,7 +419,7 @@ } try { - moveRoot.move(srcPath, destPath); + src.moveTo(destParent, PathUtils.getName(destPath)); if (!transientOp) { moveRoot.commit(); } Index: oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java (date 1353106551000) +++ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CompatibilityIssuesTest.java (date 1353254839000) @@ -135,7 +135,7 @@ assertFalse(y.hasChild("x")); assertEquals("", x.getParent().getName()); - root.move("/x", "/y/x"); + r.getChild("x").moveTo(r.getChild("y"), "x"); assertTrue(y.hasChild("x")); // assertEquals("y", x.getParent().getName()); // passed on JR2, fails on Oak assertEquals("", x.getParent().getName()); // fails on JR2, passes on Oak