jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1511643 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/delegate/ main/java/org/apache/jackrabbit/oak/jcr/version/ test/java/org/apache/jackrabbit/oak/jcr/version/
Date Thu, 08 Aug 2013 09:22:26 GMT
Author: mreutegg
Date: Thu Aug  8 09:22:25 2013
New Revision: 1511643

URL: http://svn.apache.org/r1511643
Log:
OAK-168: Basic JCR VersionManager support
- Do not persist transient changes on checkout (test currently fails because of OAK-947)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java?rev=1511643&r1=1511642&r2=1511643&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
Thu Aug  8 09:22:25 2013
@@ -82,7 +82,10 @@ public class VersionManagerDelegate {
 
     public void checkout(@Nonnull NodeDelegate nodeDelegate)
             throws RepositoryException {
-        versionManager.checkout(getTree(nodeDelegate));
+        // perform the operation on a fresh root because
+        // it must not save pending changes in the workspace
+        Root fresh = sessionDelegate.getContentSession().getLatestRoot();
+        versionManager.checkout(fresh, nodeDelegate.getPath());
     }
 
     public boolean isCheckedOut(@Nonnull NodeDelegate nodeDelegate)

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java?rev=1511643&r1=1511642&r2=1511643&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/ReadWriteVersionManager.java
Thu Aug  8 09:22:25 2013
@@ -37,7 +37,9 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 import static org.apache.jackrabbit.JcrConstants.JCR_ISCHECKEDOUT;
 import static org.apache.jackrabbit.JcrConstants.JCR_VERSIONLABELS;
 import static org.apache.jackrabbit.oak.plugins.version.VersionConstants.REP_ADD_VERSION_LABELS;
@@ -132,34 +134,36 @@ public class ReadWriteVersionManager ext
     /**
      * Performs a checkout on a versionable tree.
      *
-     * @param versionable the versionable node to check out.
+     * @param workspaceRoot a fresh workspace root without pending changes.
+     * @param versionablePath the absolute path to the versionable node to check out.
      * @throws UnsupportedRepositoryOperationException
      *                             if the versionable tree isn't actually
      *                             versionable.
      * @throws RepositoryException if an error occurs while checking the
      *                             node type of the tree.
+     * @throws IllegalStateException if the workspaceRoot has pending changes.
+     * @throws IllegalArgumentException if the <code>versionablePath</code> is
+     *                             not absolute.
      */
-    public void checkout(@Nonnull Tree versionable)
+    public void checkout(@Nonnull Root workspaceRoot,
+                         @Nonnull String versionablePath)
             throws UnsupportedRepositoryOperationException,
             InvalidItemStateException, RepositoryException {
+        checkState(!workspaceRoot.hasPendingChanges());
+        checkArgument(PathUtils.isAbsolute(versionablePath));
+        Tree versionable = workspaceRoot.getTree(versionablePath);
         if (!isVersionable(versionable)) {
             throw new UnsupportedRepositoryOperationException(
                     versionable.getPath() + " is not versionable");
         }
         if (!isCheckedOut(versionable)) {
-            if (workspaceRoot.hasPendingChanges()) {
-                // TODO: perform checkout on separate root and refresh session
-                //       while keeping pending changes.
-                log.warn("Session has pending changes. Checkout operation will " +
-                        "save those changes as well.");
-            }
             versionable.setProperty(JCR_ISCHECKEDOUT,
                     Boolean.TRUE, Type.BOOLEAN);
             try {
-                getWorkspaceRoot().commit();
+                workspaceRoot.commit();
                 refresh();
             } catch (CommitFailedException e) {
-                getWorkspaceRoot().refresh();
+                workspaceRoot.refresh();
                 throw e.asRepositoryException();
             }
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java?rev=1511643&r1=1511642&r2=1511643&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
Thu Aug  8 09:22:25 2013
@@ -26,6 +26,7 @@ import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 /**
  * <code>VersionableTest</code> contains tests for method relevant to
@@ -100,4 +101,20 @@ public class VersionableTest extends Abs
         Property secondBodeVersionFrozenUuid = secondNodeVersion.getFrozenNode().getProperty(JcrConstants.JCR_FROZENUUID);
         assertFalse(JcrConstants.JCR_FROZENUUID + " should not be the same for two different
versions of different nodes! ",
                 secondBodeVersionFrozenUuid.getValue().equals(firstNodeVersionFrozenUuid.getValue()));
-    }}
+    }
+
+    public void testCheckoutWithPendingChanges() throws Exception {
+        if (true) {
+            throw new NotExecutableException("OAK-947");
+        }
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        node.addMixin(mixVersionable);
+        superuser.save();
+        node.checkin();
+        Node newNode = testRootNode.addNode(nodeName2, testNodeType);
+        assertTrue(newNode.isNew());
+        node.checkout();
+        assertTrue(node.isCheckedOut());
+        assertTrue(newNode.isNew());
+    }
+}



Mime
View raw message