jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1325174 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Date Thu, 12 Apr 2012 09:47:07 GMT
Author: mduerig
Date: Thu Apr 12 09:47:06 2012
New Revision: 1325174

URL: http://svn.apache.org/viewvc?rev=1325174&view=rev
Log:
OAK-63: Implement workspace copy and move

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1325174&r1=1325173&r2=1325174&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Thu Apr 12 09:47:06 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.Connection;
+import org.apache.jackrabbit.oak.api.NodeStateEditor;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,8 +77,19 @@ public class WorkspaceImpl implements Wo
         getSessionImpl().checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
         getSessionImpl().checkIsAlive();
 
-        // TODO -> SPI
+        try {
+            Connection connection = sessionContext.getConnection();
+            NodeStateEditor editor = connection.getNodeStateEditor(connection.getCurrentRoot());
+
+            String srcPath = Paths.relativize("/", srcAbsPath);
+            String destPath = Paths.relativize("/", destAbsPath);
+            editor.copy(srcPath, destPath);
 
+            connection.commit(editor);
+        }
+        catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     @SuppressWarnings("deprecation")
@@ -94,8 +108,19 @@ public class WorkspaceImpl implements Wo
         getSessionImpl().checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
         getSessionImpl().checkIsAlive();
 
-        // TODO -> SPI
+        try {
+            Connection connection = sessionContext.getConnection();
+            NodeStateEditor editor = connection.getNodeStateEditor(connection.getCurrentRoot());
+
+            String srcPath = Paths.relativize("/", srcAbsPath);
+            String destPath = Paths.relativize("/", destAbsPath);
+            editor.move(srcPath, destPath);
 
+            connection.commit(editor);
+        }
+        catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1325174&r1=1325173&r2=1325174&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Thu Apr 12 09:47:06 2012
@@ -1212,6 +1212,51 @@ public class RepositoryTest extends Abst
         assertTrue(node.hasNode("target/moved"));
     }
 
+    @Test
+    public void workspaceMove() throws RepositoryException {
+        Session session = getSession();
+
+        Node node = getNode(TEST_PATH);
+        node.addNode("source").addNode("node");
+        node.addNode("target");
+        session.save();
+
+        session.getWorkspace().move(TEST_PATH + "/source/node", TEST_PATH + "/target/moved");
+
+        // Move must not be visible in session
+        assertTrue(node.hasNode("source/node"));
+        assertFalse(node.hasNode("target/moved"));
+
+        session.refresh(false);
+
+        // Move must be visible in session after refresh
+        assertFalse(node.hasNode("source/node"));
+        assertTrue(node.hasNode("source"));
+        assertTrue(node.hasNode("target/moved"));
+    }
+
+    @Test
+    public void workspaceCopy() throws RepositoryException {
+        Session session = getSession();
+
+        Node node = getNode(TEST_PATH);
+        node.addNode("source").addNode("node");
+        node.addNode("target");
+        session.save();
+
+        session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
+
+        // Copy must not be visible in session
+        assertTrue(node.hasNode("source/node"));
+        assertFalse(node.hasNode("target/copied"));
+
+        session.refresh(false);
+
+        // Copy must be visible in session after refresh
+        assertTrue(node.hasNode("source/node"));
+        assertTrue(node.hasNode("target/copied"));
+    }
+
     @Ignore // TODO implement node type support
     @Test
     public void setPrimaryType() throws RepositoryException {



Mime
View raw message