jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1467892 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit: EditorDiff.java EditorHook.java
Date Mon, 15 Apr 2013 08:16:54 GMT
Author: jukka
Date: Mon Apr 15 08:16:53 2013
New Revision: 1467892

URL: http://svn.apache.org/r1467892
Log:
OAK-673: Unified hook processing

Extract EditorDiff to a standalone class to make the EditorHook functionality easier to reuse
in different situations.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java?rev=1467892&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java
Mon Apr 15 08:16:53 2013
@@ -0,0 +1,161 @@
+/*
+ * 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.oak.spi.commit;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
+
+public class EditorDiff implements NodeStateDiff {
+
+    /**
+     * Validates and possibly edits the given subtree by diffing
+     * and recursing through it.
+     *
+     * @param editor editor for the root of the subtree
+     * @param before state of the original subtree
+     * @param after state of the modified subtree
+     * @return exception if the processing failed, {@code null} otherwise
+     */
+    @CheckForNull
+    public static CommitFailedException process(
+            @CheckForNull Editor editor,
+            @Nonnull NodeState before, @Nonnull NodeState after) {
+        checkNotNull(before);
+        checkNotNull(after);
+        if (editor != null) {
+            EditorDiff diff = new EditorDiff(editor);
+            return diff.process(before, after);
+        } else {
+            return null;
+        }
+    }
+
+    private final Editor editor;
+
+    /**
+     * Checked exceptions don't compose. So we need to hack around.
+     * See http://markmail.org/message/ak67n5k7mr3vqylm and
+     * http://markmail.org/message/bhocbruikljpuhu6
+     */
+    private CommitFailedException exception;
+
+    private EditorDiff(Editor editor) {
+        this.editor = editor;
+    }
+
+    private CommitFailedException process(NodeState before, NodeState after) {
+        try {
+            editor.enter(before, after);
+        } catch (CommitFailedException e) {
+            return e;
+        }
+
+        after.compareAgainstBaseState(before, this);
+        if (exception != null) {
+            return exception;
+        }
+
+        try {
+            editor.leave(before, after);
+        } catch (CommitFailedException e) {
+            return e;
+        }
+
+        return null;
+    }
+
+    //-------------------------------------------------< NodeStateDiff >--
+
+    @Override
+    public void propertyAdded(PropertyState after) {
+        if (exception == null) {
+            try {
+                editor.propertyAdded(after);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after) {
+        if (exception == null) {
+            try {
+                editor.propertyChanged(before, after);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+    @Override
+    public void propertyDeleted(PropertyState before) {
+        if (exception == null) {
+            try {
+                editor.propertyDeleted(before);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+    @Override
+    public void childNodeAdded(String name, NodeState after) {
+        if (exception == null) {
+            try {
+                Editor e = editor.childNodeAdded(name, after);
+                exception = EditorHook.process(e, EMPTY_NODE, after);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+    @Override
+    public void childNodeChanged(
+            String name, NodeState before, NodeState after) {
+        if (exception == null) {
+            try {
+                Editor e = editor.childNodeChanged(name, before, after);
+                exception = EditorHook.process(e, before, after);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+    @Override
+    public void childNodeDeleted(String name, NodeState before) {
+        if (exception == null) {
+            try {
+                Editor e = editor.childNodeDeleted(name, before);
+                exception = EditorHook.process(e, before, EMPTY_NODE);
+            } catch (CommitFailedException e) {
+                exception = e;
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorDiff.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java?rev=1467892&r1=1467891&r2=1467892&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EditorHook.java
Mon Apr 15 08:16:53 2013
@@ -16,17 +16,13 @@
  */
 package org.apache.jackrabbit.oak.spi.commit;
 
-import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 /**
  * This commit hook implementation processes changes to be committed
@@ -51,7 +47,8 @@ public class EditorHook implements Commi
         checkNotNull(after);
         NodeBuilder builder = after.builder();
         Editor editor = provider.getRootEditor(before, after, builder);
-        CommitFailedException exception = process(editor, before, after);
+        CommitFailedException exception =
+                EditorDiff.process(editor, before, after);
         if (exception == null) {
             return builder.getNodeState();
         } else {
@@ -59,139 +56,4 @@ public class EditorHook implements Commi
         }
     }
 
-    //------------------------------------------------------------< private >---
-
-    /**
-     * Validates and possibly edits the given subtree by diffing and recursing through it.
-     *
-     * @param editor editor for the root of the subtree
-     * @param before state of the original subtree
-     * @param after state of the modified subtree
-     * @return exception if the processing failed, {@code null} otherwise
-     */
-    @CheckForNull
-    private static CommitFailedException process(
-            @CheckForNull Editor editor,
-            @Nonnull NodeState before, @Nonnull NodeState after) {
-        checkNotNull(before);
-        checkNotNull(after);
-        if (editor != null) {
-            EditorDiff diff = new EditorDiff(editor);
-            return diff.process(before, after);
-        } else {
-            return null;
-        }
-    }
-
-    private static class EditorDiff implements NodeStateDiff {
-
-        private final Editor editor;
-
-        /**
-         * Checked exceptions don't compose. So we need to hack around.
-         * See http://markmail.org/message/ak67n5k7mr3vqylm and
-         * http://markmail.org/message/bhocbruikljpuhu6
-         */
-        private CommitFailedException exception;
-
-        private EditorDiff(Editor editor) {
-            this.editor = editor;
-        }
-
-        public CommitFailedException process(
-                NodeState before, NodeState after) {
-            try {
-                editor.enter(before, after);
-            } catch (CommitFailedException e) {
-                return e;
-            }
-
-            after.compareAgainstBaseState(before, this);
-            if (exception != null) {
-                return exception;
-            }
-
-            try {
-                editor.leave(before, after);
-            } catch (CommitFailedException e) {
-                return e;
-            }
-
-            return null;
-        }
-
-        //-------------------------------------------------< NodeStateDiff >--
-
-        @Override
-        public void propertyAdded(PropertyState after) {
-            if (exception == null) {
-                try {
-                    editor.propertyAdded(after);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-        @Override
-        public void propertyChanged(PropertyState before, PropertyState after) {
-            if (exception == null) {
-                try {
-                    editor.propertyChanged(before, after);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-        @Override
-        public void propertyDeleted(PropertyState before) {
-            if (exception == null) {
-                try {
-                    editor.propertyDeleted(before);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-        @Override
-        public void childNodeAdded(String name, NodeState after) {
-            if (exception == null) {
-                try {
-                    Editor e = editor.childNodeAdded(name, after);
-                    exception = EditorHook.process(e, EMPTY_NODE, after);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-        @Override
-        public void childNodeChanged(
-                String name, NodeState before, NodeState after) {
-            if (exception == null) {
-                try {
-                    Editor e = editor.childNodeChanged(name, before, after);
-                    exception = EditorHook.process(e, before, after);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-        @Override
-        public void childNodeDeleted(String name, NodeState before) {
-            if (exception == null) {
-                try {
-                    Editor e = editor.childNodeDeleted(name, before);
-                    exception = EditorHook.process(e, before, EMPTY_NODE);
-                } catch (CommitFailedException e) {
-                    exception = e;
-                }
-            }
-        }
-
-    }
-
 }



Mime
View raw message