You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2013/12/16 17:15:00 UTC

svn commit: r1551250 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/

Author: mduerig
Date: Mon Dec 16 16:14:59 2013
New Revision: 1551250

URL: http://svn.apache.org/r1551250
Log:
OAK-1284: Root.commit(String, CommitHook) : CommitHook is not part of oak-api
Pass path of the target sub tree of the commit to Root.commit instead of a CommitHook

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1551250&r1=1551249&r2=1551250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Mon Dec 16 16:14:59 2013
@@ -108,11 +108,13 @@ public interface Root {
     void refresh();
 
     /**
-     * Atomically persists all changes made to the tree attached to this root.
-     * Before any changes are actually persisted the passed commit hook is
-     * run and it fail the commit by throwing a {@code CommitFailedException}.
-     * The commit hook is invoked <em>before</em> any other commit hooks that
-     * might be present in this root.
+     * Atomically persists all changes made to the tree attached to this root
+     * at the given {@code path}. An implementations may throw a
+     * {@code CommitFailedException} if there are changes outside of the subtree
+     * designated by {@code path} and the implementation does not support
+     * such partial commits. However all implementation must handler the
+     * case where a {@code path} designates a subtree that contains all
+     * unpersisted changes.
      * <p>
      * The message string (if given) is passed to the underlying storage
      * as a part of the internal commit information attached to this commit.
@@ -124,17 +126,17 @@ public interface Root {
      * through {@link #getTree(String)} may become non existing.
      *
      * @param message custom message to be associated with this commit
-     * @param hook commit hook to run before any changes are persisted
+     * @param path of the subtree to commit
      * @throws CommitFailedException if the commit failed
      */
-    void commit(@Nullable String message, @Nullable CommitHook hook)
+    void commit(@Nullable String message, @Nullable String path)
             throws CommitFailedException;
 
     /**
      * Atomically persists all changes made to the tree attached to this root.
      * Calling this method is equivalent to calling the
-     * {@link #commit(String, CommitHook)} method with no user data and an
-     * empty commit hook.
+     * {@link #commit(String, String)} method with {@code null} parameters for
+     * {@code message} and {@code path}.
      *
      * @throws CommitFailedException if the commit failed
      */

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java?rev=1551250&r1=1551249&r2=1551250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractRoot.java Mon Dec 16 16:14:59 2013
@@ -18,10 +18,18 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Lists.newArrayList;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
+import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.security.auth.Subject;
@@ -29,6 +37,7 @@ import javax.security.auth.Subject;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -40,10 +49,15 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
+import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.FailingValidator;
 import org.apache.jackrabbit.oak.spi.commit.MoveTracker;
 import org.apache.jackrabbit.oak.spi.commit.PostValidationHook;
+import org.apache.jackrabbit.oak.spi.commit.SubtreeExcludingValidator;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.Context;
@@ -56,12 +70,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.util.LazyValue;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor;
-
 public abstract class AbstractRoot implements Root {
 
     /**
@@ -258,7 +266,7 @@ public abstract class AbstractRoot imple
     }
 
     @Override
-    public void commit(@Nullable String message, @Nullable CommitHook hook)
+    public void commit(@Nullable String message, @Nullable String path)
             throws CommitFailedException {
         checkLive();
         ContentSession session = getContentSession();
@@ -266,7 +274,7 @@ public abstract class AbstractRoot imple
                 session.toString(),
                 session.getAuthInfo().getUserID(),
                 permissionProvider.get(), moveTracker, message);
-        base = store.merge(builder, getCommitHook(hook, info), info);
+        base = store.merge(builder, getCommitHook(path, info), info);
         secureBuilder.baseChanged();
         modCount = 0;
         if (permissionProvider.hasValue()) {
@@ -276,19 +284,25 @@ public abstract class AbstractRoot imple
     }
 
     /**
-     * Combine the passed {@code hook}, the globally defined commit hook(s)
-     * and the hooks and validators defined by the various security related
-     * configurations.
+     * Combine the globally defined commit hook(s) and the hooks and validators defined by the
+     * various security related configurations. In addition a commit hook is added to check
+     * that the {@code path} to commit contains all unpersisted changes and to fail the
+     * commit otherwise.
      *
-     * @param extraHook extra hook to be used for just this commit, or {@code null}
+     * @param path path to commit
      * @return A commit hook combining repository global commit hook(s) with the pluggable hooks
      *         defined with the security modules and the padded {@code hooks}.
      */
-    private CommitHook getCommitHook(@Nullable CommitHook extraHook, @Nonnull CommitInfo commitInfo) {
+    private CommitHook getCommitHook(@Nullable final String path, @Nonnull CommitInfo commitInfo) {
         List<CommitHook> hooks = newArrayList();
 
-        if (extraHook != null) {
-            hooks.add(extraHook);
+        if (path != null) {
+            hooks.add(new EditorHook(new EditorProvider() {
+                @Override
+                public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder) {
+                    return new ItemSaveValidator(path);
+                }
+            }));
         }
 
         hooks.add(hook);
@@ -456,4 +470,53 @@ public abstract class AbstractRoot imple
                     : '>' + source + ':' + PathUtils.concat(destParent.getPathInternal(), destName);
         }
     }
+
+    //------------------------------------------------------------< ItemSaveValidator >---
+
+    /**
+     * This validator checks that all changes are contained within the subtree
+     * rooted at a given path.
+     */
+    private static class ItemSaveValidator extends SubtreeExcludingValidator {
+
+        /**
+         * Name of the property whose {@link #propertyChanged(org.apache.jackrabbit.oak.api.PropertyState, org.apache.jackrabbit.oak.api.PropertyState)} to
+         * ignore or {@code null} if no property should be ignored.
+         */
+        private final String ignorePropertyChange;
+
+        /**
+         * Create a new validator that only throws a {@link CommitFailedException} whenever
+         * there are changes not contained in the subtree rooted at {@code path}.
+         * @param path
+         */
+        public ItemSaveValidator(String path) {
+            this(new FailingValidator(CommitFailedException.UNSUPPORTED, 0,
+                    "Failed to save subtree at " + path + ". There are " +
+                            "transient modifications outside that subtree."),
+                    newArrayList(elements(path)));
+        }
+
+        private ItemSaveValidator(Validator validator, List<String> path) {
+            super(validator, path);
+            // Ignore property changes if this is the head of the path.
+            // This allows for calling save on a changed property.
+            ignorePropertyChange = path.size() == 1 ? path.get(0) : null;
+        }
+
+        @Override
+        public void propertyChanged(PropertyState before, PropertyState after)
+                throws CommitFailedException {
+            if (!before.getName().equals(ignorePropertyChange)) {
+                super.propertyChanged(before, after);
+            }
+        }
+
+        @Override
+        protected SubtreeExcludingValidator createValidator(
+                Validator validator, final List<String> path) {
+            return new ItemSaveValidator(validator, path);
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java?rev=1551250&r1=1551249&r2=1551250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java Mon Dec 16 16:14:59 2013
@@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider;
 import org.apache.jackrabbit.oak.query.ExecutionContext;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
@@ -98,7 +97,7 @@ public final class ImmutableRoot impleme
     }
 
     @Override
-    public void commit(String message, CommitHook hooks) {
+    public void commit(String message, String path) {
         throw new UnsupportedOperationException();
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1551250&r1=1551249&r2=1551250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java Mon Dec 16 16:14:59 2013
@@ -16,8 +16,11 @@
  */
 package org.apache.jackrabbit.oak.jcr.delegate;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
+
 import java.io.IOException;
-import java.util.List;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
@@ -28,7 +31,6 @@ import javax.jcr.nodetype.ConstraintViol
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -36,25 +38,11 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
-import org.apache.jackrabbit.oak.spi.commit.FailingValidator;
-import org.apache.jackrabbit.oak.spi.commit.SubtreeExcludingValidator;
-import org.apache.jackrabbit.oak.spi.commit.Validator;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
-import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
-
 /**
  * TODO document
  */
@@ -213,12 +201,7 @@ public class SessionDelegate {
      * @throws CommitFailedException if the commit failed
      */
     public void commit(Root root) throws CommitFailedException {
-        commit(root, null);
-    }
-
-    private void commit(Root root, CommitHook hook)
-            throws CommitFailedException {
-        root.commit(userData, hook);
+        root.commit(userData, null);
     }
 
     public void checkProtectedNode(String path) throws RepositoryException {
@@ -347,12 +330,7 @@ public class SessionDelegate {
             save();
         } else {
             try {
-                root.commit(null, new EditorHook(new EditorProvider() {
-                    @Override
-                    public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder) {
-                        return new ItemSaveValidator(path);
-                    }
-                }));
+                root.commit(null, path);
             } catch (CommitFailedException e) {
                 throw newRepositoryException(e);
             }
@@ -467,50 +445,4 @@ public class SessionDelegate {
         return exception.asRepositoryException();
     }
 
-    /**
-     * This validator checks that all changes are contained within the subtree
-     * rooted at a given path.
-     */
-    private static class ItemSaveValidator extends SubtreeExcludingValidator {
-
-        /**
-         * Name of the property whose {@link #propertyChanged(PropertyState, PropertyState)} to
-         * ignore or {@code null} if no property should be ignored.
-         */
-        private final String ignorePropertyChange;
-
-        /**
-         * Create a new validator that only throws a {@link CommitFailedException} whenever
-         * there are changes not contained in the subtree rooted at {@code path}.
-         * @param path
-         */
-        public ItemSaveValidator(String path) {
-            this(new FailingValidator(CommitFailedException.UNSUPPORTED, 0,
-                    "Failed to save subtree at " + path + ". There are " +
-                            "transient modifications outside that subtree."),
-                    newArrayList(elements(path)));
-        }
-
-        private ItemSaveValidator(Validator validator, List<String> path) {
-            super(validator, path);
-            // Ignore property changes if this is the head of the path.
-            // This allows for calling save on a changed property.
-            ignorePropertyChange = path.size() == 1 ? path.get(0) : null;
-        }
-
-        @Override
-        public void propertyChanged(PropertyState before, PropertyState after)
-                throws CommitFailedException {
-            if (!before.getName().equals(ignorePropertyChange)) {
-                super.propertyChanged(before, after);
-            }
-        }
-
-        @Override
-        protected SubtreeExcludingValidator createValidator(
-                Validator validator, final List<String> path) {
-            return new ItemSaveValidator(validator, path);
-        }
-    }
-
 }