jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1407119 [5/9] - in /jackrabbit/oak/trunk: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mk-perf/ oak-mk-perf/src/main/java/org/apache/jackrabbit/mk/tasks/ oak-...
Date Thu, 08 Nov 2012 15:18:02 GMT
Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/command/InconsistentNodeHierarchyException.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java Thu Nov  8 15:17:50 2012
@@ -14,10 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.command;
+package org.apache.jackrabbit.mongomk.impl.instruction;
 
-public class InconsistentNodeHierarchyException extends Exception {
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction;
 
-    private static final long serialVersionUID = 6361719178625761034L;
+/**
+ * Base instruction implementation.
+ */
+public abstract class BaseInstruction implements Instruction {
+
+    protected final String path;
+
+    public BaseInstruction(String path) {
+        this.path = path;
+    }
 
+    @Override
+    public String getPath() {
+        return path;
+    }
 }

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/BaseInstruction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,342 @@
+/*
+ * 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.mongomk.impl.instruction;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.AddNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.CopyNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.MoveNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.RemoveNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.SetPropertyInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.InstructionVisitor;
+import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
+import org.apache.jackrabbit.mongomk.impl.action.FetchNodesAction;
+import org.apache.jackrabbit.mongomk.impl.command.NodeExistsCommand;
+import org.apache.jackrabbit.mongomk.impl.exception.NotFoundException;
+import org.apache.jackrabbit.mongomk.impl.model.MongoNode;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+/**
+ * This class reads in the instructions generated from JSON, applies basic checks
+ * and creates a node map for {@code CommitCommandMongo} to work on later.
+ */
+public class CommitCommandInstructionVisitor implements InstructionVisitor {
+
+    private final long headRevisionId;
+    private final MongoNodeStore nodeStore;
+    private final Map<String, MongoNode> pathNodeMap;
+
+    private String branchId;
+
+    /**
+     * Creates {@code CommitCommandInstructionVisitor}
+     *
+     * @param nodeStore Node store.
+     * @param headRevisionId Head revision.
+     */
+    public CommitCommandInstructionVisitor(MongoNodeStore nodeStore, long headRevisionId) {
+        this.nodeStore = nodeStore;
+        this.headRevisionId = headRevisionId;
+        pathNodeMap = new HashMap<String, MongoNode>();
+    }
+
+    /**
+     * Sets the branch id associated with the commit. It can be null.
+     *
+     * @param branchId Branch id or null.
+     */
+    public void setBranchId(String branchId) {
+        this.branchId = branchId;
+    }
+
+    /**
+     * Returns the generated node map after visit methods are called.
+     *
+     * @return Node map.
+     */
+    public Map<String, MongoNode> getPathNodeMap() {
+        return pathNodeMap;
+    }
+
+    @Override
+    public void visit(AddNodeInstruction instruction) {
+        String nodePath = instruction.getPath();
+        checkAbsolutePath(nodePath);
+
+        String nodeName = PathUtils.getName(nodePath);
+        if (nodeName.isEmpty()) { // This happens in initial commit.
+            getStagedNode(nodePath);
+            return;
+        }
+
+        String parentNodePath = PathUtils.getParentPath(nodePath);
+        MongoNode parent = getStoredNode(parentNodePath);
+        if (parent.childExists(nodeName)) {
+            throw new RuntimeException("There's already a child node with name '" + nodeName + "'");
+        }
+        getStagedNode(nodePath);
+        parent.addChild(nodeName);
+    }
+
+    @Override
+    public void visit(SetPropertyInstruction instruction) {
+        String key = instruction.getKey();
+        Object value = instruction.getValue();
+        MongoNode node = getStoredNode(instruction.getPath());
+        if (value == null) {
+            node.removeProp(key);
+        } else {
+            node.addProperty(key, value);
+        }
+    }
+
+    @Override
+    public void visit(RemoveNodeInstruction instruction) {
+        String nodePath = instruction.getPath();
+        checkAbsolutePath(nodePath);
+
+        String parentPath = PathUtils.getParentPath(nodePath);
+        String nodeName = PathUtils.getName(nodePath);
+        MongoNode parent = getStoredNode(parentPath);
+        if (!parent.childExists(nodeName)) {
+            throw new RuntimeException("Node " + nodeName
+                    + " does not exists at parent path: " + parentPath);
+        }
+        parent.removeChild(PathUtils.getName(nodePath));
+    }
+
+    @Override
+    public void visit(CopyNodeInstruction instruction) {
+        String srcPath = instruction.getSourcePath();
+        checkAbsolutePath(srcPath);
+
+        String destPath = instruction.getDestPath();
+        if (!PathUtils.isAbsolute(destPath)) {
+            destPath = PathUtils.concat(instruction.getPath(), destPath);
+            checkAbsolutePath(destPath);
+        }
+
+        String srcParentPath = PathUtils.getParentPath(srcPath);
+        String srcNodeName = PathUtils.getName(srcPath);
+
+        String destParentPath = PathUtils.getParentPath(destPath);
+        String destNodeName = PathUtils.getName(destPath);
+
+        MongoNode srcParent = getStoredNode(srcParentPath);
+        if (!srcParent.childExists(srcNodeName)) {
+            throw new NotFoundException(srcPath);
+        }
+        MongoNode destParent = getStoredNode(destParentPath);
+        if (destParent.childExists(destNodeName)) {
+            throw new RuntimeException("Node already exists at copy destination path: " + destPath);
+        }
+
+        // First, copy the existing nodes.
+        List<MongoNode> nodesToCopy = new FetchNodesAction(nodeStore,
+                srcPath, true, headRevisionId).execute();
+        for (MongoNode nodeMongo : nodesToCopy) {
+            String oldPath = nodeMongo.getPath();
+            String oldPathRel = PathUtils.relativize(srcPath, oldPath);
+            String newPath = PathUtils.concat(destPath, oldPathRel);
+
+            nodeMongo.setPath(newPath);
+            nodeMongo.removeField("_id");
+            pathNodeMap.put(newPath, nodeMongo);
+        }
+
+        // Then, copy any staged changes.
+        MongoNode srcNode = getStoredNode(srcPath);
+        MongoNode destNode = getStagedNode(destPath);
+        copyStagedChanges(srcNode, destNode);
+
+        // Finally, add to destParent.
+        pathNodeMap.put(destPath, destNode);
+        destParent.addChild(destNodeName);
+    }
+
+    @Override
+    public void visit(MoveNodeInstruction instruction) {
+        String srcPath = instruction.getSourcePath();
+        String destPath = instruction.getDestPath();
+        if (PathUtils.isAncestor(srcPath, destPath)) {
+            throw new RuntimeException("Target path cannot be descendant of source path: "
+                    + destPath);
+        }
+
+        String srcParentPath = PathUtils.getParentPath(srcPath);
+        String srcNodeName = PathUtils.getName(srcPath);
+
+        String destParentPath = PathUtils.getParentPath(destPath);
+        String destNodeName = PathUtils.getName(destPath);
+
+        MongoNode srcParent = getStoredNode(srcParentPath);
+        if (!srcParent.childExists(srcNodeName)) {
+            throw new NotFoundException(srcPath);
+        }
+
+        MongoNode destParent = getStoredNode(destParentPath);
+        if (destParent.childExists(destNodeName)) {
+            throw new RuntimeException("Node already exists at move destination path: " + destPath);
+        }
+
+        // First, copy the existing nodes.
+        List<MongoNode> nodesToCopy = new FetchNodesAction(nodeStore,
+                srcPath, true, headRevisionId).execute();
+        for (MongoNode nodeMongo : nodesToCopy) {
+            String oldPath = nodeMongo.getPath();
+            String oldPathRel = PathUtils.relativize(srcPath, oldPath);
+            String newPath = PathUtils.concat(destPath, oldPathRel);
+
+            nodeMongo.setPath(newPath);
+            nodeMongo.removeField("_id");
+            pathNodeMap.put(newPath, nodeMongo);
+        }
+
+        // Then, copy any staged changes.
+        MongoNode srcNode = getStoredNode(srcPath);
+        MongoNode destNode = getStagedNode(destPath);
+        copyStagedChanges(srcNode, destNode);
+
+        // Finally, add to destParent and remove from srcParent.
+        getStagedNode(destPath);
+        destParent.addChild(destNodeName);
+        srcParent.removeChild(srcNodeName);
+    }
+
+    private void checkAbsolutePath(String srcPath) {
+        if (!PathUtils.isAbsolute(srcPath)) {
+            throw new RuntimeException("Absolute path expected: " + srcPath);
+        }
+    }
+
+    private MongoNode getStagedNode(String path) {
+        MongoNode node = pathNodeMap.get(path);
+        if (node == null) {
+            node = new MongoNode();
+            node.setPath(path);
+            pathNodeMap.put(path, node);
+        }
+        return node;
+    }
+
+    private MongoNode getStoredNode(String path) {
+        MongoNode node = pathNodeMap.get(path);
+        if (node != null) {
+            return node;
+        }
+
+        // First need to check that the path is indeed valid.
+        NodeExistsCommand existCommand = new NodeExistsCommand(nodeStore,
+                path, headRevisionId);
+        existCommand.setBranchId(branchId);
+        boolean exists = false;
+        try {
+            exists = existCommand.execute();
+        } catch (Exception ignore) {}
+
+        if (!exists) {
+            throw new NotFoundException(path);
+        }
+
+        // Fetch the node without its descendants.
+        FetchNodesAction query = new FetchNodesAction(nodeStore,
+                path, false /*fetchDescendants*/, headRevisionId);
+        query.setBranchId(branchId);
+        List<MongoNode> nodes = query.execute();
+
+        if (!nodes.isEmpty()) {
+            node = nodes.get(0);
+            node.removeField("_id");
+            pathNodeMap.put(path, node);
+        }
+
+        return node;
+    }
+
+    private void copyStagedChanges(MongoNode srcNode, MongoNode destNode) {
+
+        // Copy staged changes at the top level.
+        copyAddedNodes(srcNode, destNode);
+        copyRemovedNodes(srcNode, destNode);
+        copyAddedProperties(srcNode, destNode);
+        copyRemovedProperties(srcNode, destNode);
+
+        // Recursively add staged changes of the descendants.
+        List<String> srcChildren = srcNode.getChildren();
+        if (srcChildren == null || srcChildren.isEmpty()) {
+            return;
+        }
+
+        for (String childName : srcChildren) {
+            String oldChildPath = PathUtils.concat(srcNode.getPath(), childName);
+            MongoNode oldChild = getStoredNode(oldChildPath);
+
+            String newChildPath = PathUtils.concat(destNode.getPath(), childName);
+            MongoNode newChild = getStagedNode(newChildPath);
+            copyStagedChanges(oldChild, newChild);
+        }
+    }
+
+    private void copyRemovedProperties(MongoNode srcNode, MongoNode destNode) {
+        Map<String, Object> removedProps = srcNode.getRemovedProps();
+        if (removedProps == null || removedProps.isEmpty()) {
+            return;
+        }
+
+        for (String key : removedProps.keySet()) {
+            destNode.removeProp(key);
+        }
+    }
+
+    private void copyAddedNodes(MongoNode srcNode, MongoNode destNode) {
+        List<String> addedChildren = srcNode.getAddedChildren();
+        if (addedChildren == null || addedChildren.isEmpty()) {
+            return;
+        }
+
+        for (String childName : addedChildren) {
+            getStagedNode(PathUtils.concat(destNode.getPath(), childName));
+            destNode.addChild(childName);
+        }
+    }
+
+    private void copyRemovedNodes(MongoNode srcNode, MongoNode destNode) {
+        List<String> removedChildren = srcNode.getRemovedChildren();
+        if (removedChildren == null || removedChildren.isEmpty()) {
+            return;
+        }
+
+        for (String child : removedChildren) {
+            destNode.removeChild(child);
+        }
+    }
+
+    private void copyAddedProperties(MongoNode srcNode, MongoNode destNode) {
+        Map<String, Object> addedProps = srcNode.getAddedProps();
+        if (addedProps == null || addedProps.isEmpty()) {
+            return;
+        }
+
+        for (Entry<String, Object> entry : addedProps.entrySet()) {
+            destNode.addProperty(entry.getKey(), entry.getValue());
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CommitCommandInstructionVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CopyNodeInstructionImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CopyNodeInstructionImpl.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CopyNodeInstructionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java Thu Nov  8 15:17:50 2012
@@ -14,30 +14,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl.model;
+package org.apache.jackrabbit.mongomk.impl.instruction;
 
-import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor;
-import org.apache.jackrabbit.mongomk.api.model.Instruction.CopyNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.InstructionVisitor;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.CopyNodeInstruction;
 
 /**
- * Implementation of {@link CopyNodeInstruction}.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ * Implementation of the copy node operation => "*" STRING ":" STRING
  */
-public class CopyNodeInstructionImpl implements CopyNodeInstruction {
+public class CopyNodeInstructionImpl extends BaseInstruction implements CopyNodeInstruction {
+
     private final String destPath;
-    private final String path;
     private final String sourcePath;
 
     /**
-     * Constructs a new {@code CopyNodeInstructionImpl}.
+     * Constructs a new {@code CopyNodeInstruction}.
      *
      * @param path The path.
      * @param sourcePath The source path.
      * @param destPath The destination path.
      */
     public CopyNodeInstructionImpl(String path, String sourcePath, String destPath) {
-        this.path = path;
+        super(path);
         this.sourcePath = sourcePath;
         this.destPath = destPath;
     }
@@ -47,18 +45,21 @@ public class CopyNodeInstructionImpl imp
         visitor.visit(this);
     }
 
-    @Override
+    /**
+     * Returns the destination path.
+     *
+     * @return The destination path.
+     */
     public String getDestPath() {
         return destPath;
     }
 
-    @Override
-    public String getPath() {
-        return path;
-    }
-
-    @Override
+    /**
+     * Returns the source path.
+     *
+     * @return The source path.
+     */
     public String getSourcePath() {
         return sourcePath;
     }
-}
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/CopyNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MoveNodeInstructionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java Thu Nov  8 15:17:50 2012
@@ -14,18 +14,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl.model;
+package org.apache.jackrabbit.mongomk.impl.instruction;
 
-import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor;
-import org.apache.jackrabbit.mongomk.api.model.Instruction.MoveNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.InstructionVisitor;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.MoveNodeInstruction;
+
+/**
+ * Implementation of the move node operation => ">" STRING ":" STRING
+ */
+public class MoveNodeInstructionImpl extends BaseInstruction implements MoveNodeInstruction {
 
-public class MoveNodeInstructionImpl implements MoveNodeInstruction {
     private final String destPath;
-    private final String path;
     private final String sourcePath;
 
+    /**
+     * Constructs a new {@code MoveNodeInstruction}.
+     *
+     * @param path The path.
+     * @param sourcePath The source path.
+     * @param destPath The destination path.
+     */
     public MoveNodeInstructionImpl(String path, String sourcePath, String destPath) {
-        this.path = path;
+        super(path);
         this.sourcePath = sourcePath;
         this.destPath = destPath;
     }
@@ -35,17 +45,20 @@ public class MoveNodeInstructionImpl imp
         visitor.visit(this);
     }
 
-    @Override
+    /**
+     * Returns the destination path.
+     *
+     * @return The destination path.
+     */
     public String getDestPath() {
         return destPath;
     }
 
-    @Override
-    public String getPath() {
-        return path;
-    }
-
-    @Override
+    /**
+     * Returns the source path.
+     *
+     * @return The source path.
+     */
     public String getSourcePath() {
         return sourcePath;
     }

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/MoveNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/RemoveNodeInstructionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java Thu Nov  8 15:17:50 2012
@@ -14,48 +14,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl.model;
+package org.apache.jackrabbit.mongomk.impl.instruction;
 
-import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor;
-import org.apache.jackrabbit.mongomk.api.model.Instruction.RemoveNodeInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.InstructionVisitor;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.RemoveNodeInstruction;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-
 /**
- * Implementation of {@link RemoveNodeInstruction}.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ * Implementation for the remove node operation => "-" STRING
  */
-public class RemoveNodeInstructionImpl implements RemoveNodeInstruction {
-
-    private final String path;
+public class RemoveNodeInstructionImpl extends BaseInstruction implements RemoveNodeInstruction {
 
     /**
-     * Constructs a new {@code RemoveNodeInstructionImpl}.
+     * Constructs a new {@code RemoveNodeInstruction}.
      *
      * @param parentPath The parent path.
      * @param name The name
      */
     public RemoveNodeInstructionImpl(String parentPath, String name) {
-        path = PathUtils.concat(parentPath, name);
+        super(PathUtils.concat(parentPath, name));
     }
 
     @Override
     public void accept(InstructionVisitor visitor) {
         visitor.visit(this);
     }
-
-    @Override
-    public String getPath() {
-        return path;
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("RemoveNodeInstructionImpl [path=");
-        builder.append(path);
-        builder.append("]");
-        return builder.toString();
-    }
-}
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/RemoveNodeInstructionImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/SetPropertyInstructionImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/SetPropertyInstructionImpl.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/SetPropertyInstructionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java Thu Nov  8 15:17:50 2012
@@ -14,31 +14,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.impl.model;
+package org.apache.jackrabbit.mongomk.impl.instruction;
 
-import org.apache.jackrabbit.mongomk.api.model.InstructionVisitor;
-import org.apache.jackrabbit.mongomk.api.model.Instruction.SetPropertyInstruction;
+import org.apache.jackrabbit.mongomk.api.instruction.InstructionVisitor;
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction.SetPropertyInstruction;
 
 /**
- * Implementation of {@link SetPropertyInstruction}.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ * Implementation for the set property operation => "^" STRING ":" ATOM | ARRAY
  */
-public class SetPropertyInstructionImpl implements SetPropertyInstruction {
+public class SetPropertyInstructionImpl extends BaseInstruction implements SetPropertyInstruction {
 
     private final String key;
-    private final String path;
     private final Object value;
 
     /**
-     * Constructs a new {@code SetPropertyInstructionImpl}.
+     * Constructs a new {@code SetPropertyInstruction}.
      *
      * @param path The path.
      * @param key The key.
      * @param value The value.
      */
     public SetPropertyInstructionImpl(String path, String key, Object value) {
-        this.path = path;
+        super(path);
         this.key = key;
         this.value = value;
     }
@@ -48,31 +45,21 @@ public class SetPropertyInstructionImpl 
         visitor.visit(this);
     }
 
-    @Override
+    /**
+     * Returns the name of the property.
+     *
+     * @return The name of the property.
+     */
     public String getKey() {
         return key;
     }
 
-    @Override
-    public String getPath() {
-        return path;
-    }
-
-    @Override
+    /**
+     * Returns the value of the property.
+     *
+     * @return The value of the property.
+     */
     public Object getValue() {
         return value;
     }
-
-    @Override
-    public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("SetPropertyInstructionImpl [path=");
-        builder.append(path);
-        builder.append(", key=");
-        builder.append(key);
-        builder.append(", value=");
-        builder.append(value);
-        builder.append("]");
-        return builder.toString();
-    }
-}
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/instruction/SetPropertyInstructionImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/DefaultJsopHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/DefaultJsopHandler.java?rev=1407119&r1=1407118&r2=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/DefaultJsopHandler.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/DefaultJsopHandler.java Thu Nov  8 15:17:50 2012
@@ -69,17 +69,6 @@ public class DefaultJsopHandler {
     }
 
     /**
-     * Event: A property was added.
-     *
-     * @param path The path of the node where the property was added.
-     * @param key The key of the property.
-     * @param value The value of the property.
-     */
-    public void propertyAdded(String path, String key, Object value) {
-        // No-op
-    }
-
-    /**
      * Event: A property was set.
      *
      * @param path The path of the node where the property was set.

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java?rev=1407119&r1=1407118&r2=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsonUtil.java Thu Nov  8 15:17:50 2012
@@ -16,126 +16,127 @@
  */
 package org.apache.jackrabbit.mongomk.impl.json;
 
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.model.tree.ChildNode;
+import org.apache.jackrabbit.mk.model.tree.NodeState;
+import org.apache.jackrabbit.mk.model.tree.PropertyState;
+import org.apache.jackrabbit.mk.util.NameFilter;
 import org.apache.jackrabbit.mk.util.NodeFilter;
-import org.apache.jackrabbit.mongomk.api.model.Node;
 import org.json.JSONArray;
 import org.json.JSONObject;
 
-
 /**
- * FIXME - [Mete] This should really merge with MicroKernelImpl#toJson.
- *
- * <a href="http://en.wikipedia.org/wiki/JavaScript_Object_Notation">JSON</a> related utility classes.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
+ * JSON related utility class.
  */
 public class JsonUtil {
 
-    public static Object convertJsonValue(String jsonValue) throws Exception {
+    public static Object toJsonValue(String jsonValue) throws Exception {
         if (jsonValue == null) {
             return null;
         }
 
-        String dummyJson = "{dummy : " + jsonValue + "}";
-        JSONObject jsonObject = new JSONObject(dummyJson);
-        Object dummyObject = jsonObject.get("dummy");
-        return convertJsonValue(dummyObject);
+        JSONObject jsonObject = new JSONObject("{dummy : " + jsonValue + "}");
+        Object obj = jsonObject.get("dummy");
+        return convertJsonValue(obj);
     }
 
-    public static String convertToJson(Node node, int depth, int offset, int maxChildNodes,
-            boolean inclVirtualProps, NodeFilter filter) {
-        JsopBuilder builder = new JsopBuilder();
-        convertToJson(builder, node, depth, 0, offset, maxChildNodes, inclVirtualProps, filter);
-        return builder.toString();
+    private static Object convertJsonValue(Object jsonObject) throws Exception {
+        if (jsonObject == JSONObject.NULL) {
+            return null;
+        }
+
+        if (jsonObject instanceof JSONArray) {
+            List<Object> elements = new LinkedList<Object>();
+            JSONArray dummyArray = (JSONArray) jsonObject;
+            for (int i = 0; i < dummyArray.length(); ++i) {
+                Object raw = dummyArray.get(i);
+                Object parsed = convertJsonValue(raw);
+                elements.add(parsed);
+            }
+            return elements;
+        }
+
+        return jsonObject;
     }
 
-    static void convertToJson(JsopBuilder builder, Node node, int depth, int currentDepth,
-            int offset, int maxChildNodes, boolean inclVirtualProps,  NodeFilter filter) {
-        builder.object();
-
-        Map<String, Object> properties = node.getProperties();
-        if (properties != null) {
-            for (Map.Entry<String, Object> entry : properties.entrySet()) {
-                String key = entry.getKey();
-                if (filter == null || filter.includeProperty(key)) {
-                    Object value = entry.getValue();
-                    builder.key(key);
-                    if (value instanceof String) {
-                        builder.value(value.toString());
-                    } else {
-                        builder.encodedValue(value.toString());
-                    }
-                }
+    // Most of this method borrowed from MicroKernelImpl#toJson. It'd be nice if
+    // this somehow consolidated with MicroKernelImpl#toJson.
+    public static void toJson(JsopBuilder builder, NodeState node, int depth,
+            int offset, int maxChildNodes, boolean inclVirtualProps, NodeFilter filter) {
+
+        for (PropertyState property : node.getProperties()) {
+            if (filter == null || filter.includeProperty(property.getName())) {
+                builder.key(property.getName()).encodedValue(property.getEncodedValue());
             }
         }
 
-        long childCount = node.getChildCount();
+        long childCount = node.getChildNodeCount();
         if (inclVirtualProps) {
             if (filter == null || filter.includeProperty(":childNodeCount")) {
                 // :childNodeCount is by default always included
                 // unless it is explicitly excluded in the filter
                 builder.key(":childNodeCount").value(childCount);
             }
-            // FIXME [Mete] See if :hash is still being used.
-            /*check whether :hash has been explicitly included
-            if (filter != null) {
-                NameFilter nf = filter.getPropertyFilter();
-                if (nf != null
-                        && nf.getInclusionPatterns().contains(":hash")
-                        && !nf.getExclusionPatterns().contains(":hash")) {
-                    builder.key(":hash").value(rep.getRevisionStore().getId(node).toString());
-                }
-            }
-            */
         }
 
-        // FIXME [Mete] There's still some more work here.
-        Iterator<Node> entries = node.getChildEntries(offset, maxChildNodes);
-        while (entries.hasNext()) {
-            Node child = entries.next();
-            int numSiblings = 0;
-            if (maxChildNodes != -1 && ++numSiblings > maxChildNodes) {
-                break;
-            }
-            builder.key(child.getName());
-            if ((depth == -1) || (currentDepth < depth)) {
-                convertToJson(builder, child, depth, currentDepth + 1, offset,
-                        maxChildNodes, inclVirtualProps, filter);
-            } else {
-                builder.object();
-                builder.endObject();
-            }
+        if (childCount <= 0 || depth < 0) {
+            return;
         }
 
-        builder.endObject();
-    }
+        if (filter != null) {
+            NameFilter childFilter = filter.getChildNodeFilter();
+            if (childFilter != null && !childFilter.containsWildcard()) {
+                // Optimization for large child node lists:
+                // no need to iterate over the entire child node list if the filter
+                // does not include wildcards
+                int count = maxChildNodes == -1 ? Integer.MAX_VALUE : maxChildNodes;
+                for (String name : childFilter.getInclusionPatterns()) {
+                    NodeState child = node.getChildNode(name);
+                    if (child != null) {
+                        boolean incl = true;
+                        for (String exclName : childFilter.getExclusionPatterns()) {
+                            if (name.equals(exclName)) {
+                                incl = false;
+                                break;
+                            }
+                        }
+                        if (incl) {
+                            if (count-- <= 0) {
+                                break;
+                            }
+                            builder.key(name).object();
+                            if (depth > 0) {
+                                toJson(builder, child, depth - 1, 0, maxChildNodes, inclVirtualProps, filter);
+                            }
+                            builder.endObject();
+                        }
+                    }
+                }
+                return;
+            }
+        }
 
-    private static Object convertJsonValue(Object jsonObject) throws Exception {
-        if (jsonObject == JSONObject.NULL) {
-            return null;
+        int count = maxChildNodes;
+        if (count != -1 && filter != null && filter.getChildNodeFilter() != null) {
+            // Specific maxChildNodes limit and child node filter
+            count = -1;
         }
+        int numSiblings = 0;
+        for (ChildNode entry : node.getChildNodeEntries(offset, count)) {
 
-        if (jsonObject instanceof JSONArray) {
-            List<Object> elements = new LinkedList<Object>();
-            JSONArray dummyArray = (JSONArray) jsonObject;
-            for (int i = 0; i < dummyArray.length(); ++i) {
-                Object raw = dummyArray.get(i);
-                Object parsed = convertJsonValue(raw);
-                elements.add(parsed);
+            if (filter == null || filter.includeNode(entry.getName())) {
+                if (maxChildNodes != -1 && ++numSiblings > maxChildNodes) {
+                    break;
+                }
+                builder.key(entry.getName()).object();
+                if (depth > 0) {
+                    toJson(builder, entry.getNode(), depth - 1, 0, maxChildNodes, inclVirtualProps, filter);
+                }
+                builder.endObject();
             }
-            return elements;
         }
-
-        return jsonObject;
-    }
-
-    private JsonUtil() {
-        // no instantiation
     }
-}
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java?rev=1407119&r1=1407118&r2=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/json/JsopParser.java Thu Nov  8 15:17:50 2012
@@ -34,8 +34,6 @@ import org.apache.jackrabbit.oak.commons
  * <p>
  * The underlying token parser is the {@link JsopTokenizer}.
  * </p>
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
  */
 public class JsopParser {
 
@@ -121,21 +119,16 @@ public class JsopParser {
                         tokenizer.setPos(pos);
                         tokenizer.read();
                         parseOpAdded(path);
-                    } else { // Property.
+                    }
+                    else { // Property.
                         String valueAsString = tokenizer.readRawValue().trim();
-                        Object value = JsonUtil.convertJsonValue(valueAsString);
-                        defaultHandler.propertyAdded(path, propName, value);
+                        Object value = JsonUtil.toJsonValue(valueAsString);
+                        defaultHandler.propertySet(path, propName, value);
                     }
                 } while (tokenizer.matches(','));
 
                 tokenizer.read('}'); // explicitly close the bracket
             }
-        } else { // Property.
-            String parentPath = PathUtils.denotesRoot(path) ? "" : PathUtils.getParentPath(path);
-            String propName = PathUtils.denotesRoot(path) ? "/" : PathUtils.getName(path);
-            String valueAsString = tokenizer.readRawValue().trim();
-            Object value = JsonUtil.convertJsonValue(valueAsString);
-            defaultHandler.propertyAdded(parentPath, propName, value);
         }
     }
 
@@ -192,7 +185,7 @@ public class JsopParser {
         }
         String parentPath = PathUtils.getParentPath(targetPath);
         String propName = PathUtils.getName(targetPath);
-        defaultHandler.propertySet(parentPath, propName, JsonUtil.convertJsonValue(value));
+        defaultHandler.propertySet(parentPath, propName, JsonUtil.toJsonValue(value));
     }
 
     private void parseOpRemoved() throws Exception {

Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,110 @@
+/*
+ * 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.mongomk.impl.model;
+
+import org.apache.jackrabbit.mongomk.api.model.Commit;
+import org.apache.jackrabbit.mongomk.impl.instruction.AddNodeInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.instruction.CopyNodeInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.instruction.MoveNodeInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.instruction.RemoveNodeInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.instruction.SetPropertyInstructionImpl;
+import org.apache.jackrabbit.mongomk.impl.json.DefaultJsopHandler;
+import org.apache.jackrabbit.mongomk.impl.json.JsopParser;
+import org.apache.jackrabbit.mongomk.util.MongoUtil;
+
+/**
+ * A builder to convert a <a href="http://wiki.apache.org/jackrabbit/Jsop">JSOP</a>
+ * diff into a {@link Commit}.
+ */
+public class CommitBuilder {
+
+    /**
+     * Creates and returns a {@link Commit} without a base revision id.
+     *
+     * @param path The root path of the {@code Commit}.
+     * @param diff The {@code JSOP} diff of the {@code Commit}.
+     * @param message The message of the {@code Commit}.
+     *
+     * @return The {@code Commit}.
+     * @throws Exception If an error occurred while creating the {@code Commit}.
+     */
+    public static Commit build(String path, String diff, String message)
+            throws Exception {
+        return CommitBuilder.build(path, diff, null, message);
+    }
+
+    /**
+     * Creates and returns a {@link Commit}.
+     *
+     * @param path The root path of the {@code Commit}.
+     * @param diff The {@code JSOP} diff of the {@code Commit}.
+     * @param revisionId The revision id the commit is based on.
+     * @param message The message of the {@code Commit}.
+     *
+     * @return The {@code Commit}.
+     * @throws Exception If an error occurred while creating the {@code Commit}.
+     */
+    public static Commit build(String path, String diff, String revisionId,
+            String message) throws Exception {
+        MongoCommit commit = new MongoCommit();
+        commit.setBaseRevisionId(MongoUtil.toMongoRepresentation(revisionId));
+        commit.setDiff(diff);
+        commit.setMessage(message);
+        commit.setPath(path);
+
+        JsopParser jsopParser = new JsopParser(path, diff, new CommitHandler(commit));
+        jsopParser.parse();
+
+        return commit;
+    }
+
+    /**
+     * The {@link DefaultJaopHandler} for the {@code JSOP} diff.
+     */
+    private static class CommitHandler extends DefaultJsopHandler {
+        private final MongoCommit commit;
+
+        CommitHandler(MongoCommit commit) {
+            this.commit = commit;
+        }
+
+        @Override
+        public void nodeAdded(String parentPath, String name) {
+            commit.addInstruction(new AddNodeInstructionImpl(parentPath, name));
+        }
+
+        @Override
+        public void nodeCopied(String rootPath, String oldPath, String newPath) {
+            commit.addInstruction(new CopyNodeInstructionImpl(rootPath, oldPath, newPath));
+        }
+
+        @Override
+        public void nodeMoved(String rootPath, String oldPath, String newPath) {
+            commit.addInstruction(new MoveNodeInstructionImpl(rootPath, oldPath, newPath));
+        }
+
+        @Override
+        public void nodeRemoved(String parentPath, String name) {
+            commit.addInstruction(new RemoveNodeInstructionImpl(parentPath, name));
+        }
+
+        @Override
+        public void propertySet(String path, String key, Object value) {
+            commit.addInstruction(new SetPropertyInstructionImpl(path, key, value));
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/CommitBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java?rev=1407119&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java (added)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java Thu Nov  8 15:17:50 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.mongomk.impl.model;
+
+import com.mongodb.BasicDBObject;
+
+/**
+ * The {@code MongoDB} representation of a blob. Only used by {@link MongoBlobStore}
+ */
+public class MongoBlob extends BasicDBObject {
+
+    public static final String KEY_ID = "_id";
+    public static final String KEY_DATA = "data";
+    public static final String KEY_LAST_MOD = "lastMod";
+    public static final String KEY_LEVEL = "level";
+
+    private static final long serialVersionUID = 5119970546251968672L;
+
+    /**
+     * Default constructor. Needed for MongoDB serialization.
+     */
+    public MongoBlob() {
+    }
+
+    public String getId() {
+        return getString(KEY_ID);
+    }
+
+    public void setId(String id) {
+        put(KEY_ID, id);
+    }
+
+    public byte[] getData() {
+        return (byte[])get(KEY_DATA);
+    }
+
+    public void setData(byte[] data) {
+        put(KEY_DATA, data);
+    }
+
+    public int getLevel() {
+        return getInt(KEY_LEVEL);
+    }
+
+    public void setLevel(int level) {
+        put(KEY_LEVEL, level);
+    }
+
+    public long getLastMod() {
+        return getLong(KEY_LAST_MOD);
+    }
+
+    public void setLastMod(long lastMod) {
+        put(KEY_LAST_MOD, lastMod);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoBlob.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/CommitMongo.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java Thu Nov  8 15:17:50 2012
@@ -14,137 +14,154 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.model;
+package org.apache.jackrabbit.mongomk.impl.model;
 
+import java.util.Collections;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
 
+import org.apache.jackrabbit.mongomk.api.instruction.Instruction;
 import org.apache.jackrabbit.mongomk.api.model.Commit;
-import org.apache.jackrabbit.mongomk.api.model.Instruction;
-import org.apache.jackrabbit.mongomk.api.model.Instruction.AddNodeInstruction;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 
 import com.mongodb.BasicDBObject;
 
 /**
  * The {@code MongoDB} representation of a commit.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
  */
-@SuppressWarnings("javadoc")
-public class CommitMongo extends BasicDBObject {
+public class MongoCommit extends BasicDBObject implements Commit {
 
     public static final String KEY_AFFECTED_PATH = "affPaths";
     public static final String KEY_BASE_REVISION_ID = "baseRevId";
+    public static final String KEY_BRANCH_ID = "branchId";
     public static final String KEY_DIFF = "diff";
     public static final String KEY_FAILED = "failed";
     public static final String KEY_MESSAGE = "msg";
     public static final String KEY_PATH = "path";
     public static final String KEY_REVISION_ID = "revId";
     public static final String KEY_TIMESTAMP = "ts";
-    private static final long serialVersionUID = 6656294757102309827L;
-
-    public static CommitMongo fromCommit(Commit commit) {
-        CommitMongo commitMongo = new CommitMongo();
-
-        String message = commit.getMessage();
-        commitMongo.setMessage(message);
-
-        String path = commit.getPath();
-        commitMongo.setPath(path);
-
-        String diff = commit.getDiff();
-        commitMongo.setDiff(diff);
-
-        Long revisionId = commit.getRevisionId();
-        if (revisionId != null) {
-            commitMongo.setRevisionId(revisionId);
-        }
 
-        commitMongo.setTimestamp(commit.getTimestamp());
+    private final List<Instruction> instructions;
 
-        Set<String> affectedPaths = new HashSet<String>();
-        for (Instruction instruction : commit.getInstructions()) {
-            affectedPaths.add(instruction.getPath());
-
-            if (instruction instanceof AddNodeInstruction) {
-                affectedPaths.add(PathUtils.getParentPath(instruction.getPath()));
-            }
-        }
-        commitMongo.setAffectedPaths(new LinkedList<String>(affectedPaths));
-
-        return commitMongo;
-    }
+    private static final long serialVersionUID = 6656294757102309827L;
 
-    public CommitMongo() {
+    /**
+     * Default constructor. Needed for MongoDB serialization.
+     */
+    public MongoCommit() {
+        instructions = new LinkedList<Instruction>();
         setTimestamp(new Date().getTime());
     }
 
+    //--------------------------------------------------------------------------
+    //
+    // These properties are persisted to MongoDB
+    //
+    //--------------------------------------------------------------------------
+
+    @Override
     @SuppressWarnings("unchecked")
     public List<String> getAffectedPaths() {
         return (List<String>) get(KEY_AFFECTED_PATH);
     }
 
-    public long getBaseRevisionId() {
-        return getLong(KEY_BASE_REVISION_ID);
-    }
-
-    public String getDiff() {
-        return getString(KEY_DIFF);
+    public void setAffectedPaths(List<String> affectedPaths) {
+        put(KEY_AFFECTED_PATH, affectedPaths);
     }
 
-    public String getMessage() {
-        return getString(KEY_MESSAGE);
+    @Override
+    public Long getBaseRevisionId() {
+        return containsField(KEY_BASE_REVISION_ID)? getLong(KEY_BASE_REVISION_ID) : null;
     }
 
-    public String getPath() {
-        return getString(KEY_PATH);
+    public void setBaseRevisionId(Long baseRevisionId) {
+        if (baseRevisionId == null) {
+            removeField(KEY_BASE_REVISION_ID);
+        } else {
+            put(KEY_BASE_REVISION_ID, baseRevisionId);
+        }
     }
 
-    public long getRevisionId() {
-        return getLong(KEY_REVISION_ID);
+    @Override
+    public String getBranchId() {
+        return getString(KEY_BRANCH_ID);
     }
 
-    public boolean hasFailed() {
-        return getBoolean(KEY_FAILED);
+    public void setBranchId(String branchId) {
+        put(KEY_BRANCH_ID, branchId);
     }
 
-    public void setAffectedPaths(List<String> affectedPaths) {
-        put(KEY_AFFECTED_PATH, affectedPaths);
-    }
-
-    public void setBaseRevId(long baseRevisionId) {
-        put(KEY_BASE_REVISION_ID, baseRevisionId);
+    @Override
+    public String getDiff() {
+        return getString(KEY_DIFF);
     }
 
     public void setDiff(String diff) {
         put(KEY_DIFF, diff);
     }
 
+    public boolean isFailed() {
+        return getBoolean(KEY_FAILED);
+    }
+
     public void setFailed() {
         put(KEY_FAILED, Boolean.TRUE);
     }
 
+    @Override
+    public String getMessage() {
+        return getString(KEY_MESSAGE);
+    }
+
     public void setMessage(String message) {
         put(KEY_MESSAGE, message);
     }
 
+    @Override
+    public String getPath() {
+        return getString(KEY_PATH);
+    }
+
     public void setPath(String path) {
         put(KEY_PATH, path);
     }
 
-    public void setRevisionId(long revisionId) {
-        put(KEY_REVISION_ID, revisionId);
+    @Override
+    public Long getRevisionId() {
+        return containsField(KEY_REVISION_ID)? getLong(KEY_REVISION_ID) : null;
     }
 
-    public void setTimestamp(long timestamp) {
-        put(KEY_TIMESTAMP, timestamp);
+    @Override
+    public void setRevisionId(Long revisionId) {
+        put(KEY_REVISION_ID, revisionId);
     }
 
+    @Override
     public Long getTimestamp() {
         return getLong(KEY_TIMESTAMP);
     }
+
+    public void setTimestamp(Long timestamp) {
+        put(KEY_TIMESTAMP, timestamp);
+    }
+
+    //--------------------------------------------------------------------------
+    //
+    // These properties are used to keep track but not persisted to MongoDB
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     * Adds the given {@link Instruction}.
+     *
+     * @param instruction The {@code Instruction}.
+     */
+    public void addInstruction(Instruction instruction) {
+        instructions.add(instruction);
+    }
+
+    @Override
+    public List<Instruction> getInstructions() {
+        return Collections.unmodifiableList(instructions);
+    }
 }
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoCommit.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/NodeMongo.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java Thu Nov  8 15:17:50 2012
@@ -14,237 +14,202 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.model;
+package org.apache.jackrabbit.mongomk.impl.model;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
-import org.apache.jackrabbit.mongomk.api.model.Node;
-import org.apache.jackrabbit.mongomk.impl.model.NodeImpl;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
 import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
 
 /**
  * The {@code MongoDB} representation of a node.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
  */
-@SuppressWarnings("javadoc")
-public class NodeMongo extends BasicDBObject {
+public class MongoNode extends BasicDBObject {
 
     public static final String KEY_BASE_REVISION_ID = "baseRevId";
-    public static final String KEY_CHILDREN = "kids";
+    public static final String KEY_CHILDREN = "children";
     public static final String KEY_PATH = "path";
     public static final String KEY_PROPERTIES = "props";
     public static final String KEY_REVISION_ID = "revId";
-    private static final long serialVersionUID = 3153393934945155106L;
-
-    public static NodeMongo fromDBObject(DBObject node) {
-        NodeMongo nodeMongo = new NodeMongo();
-        nodeMongo.putAll(node);
-
-        return nodeMongo;
-    }
-
-    public static NodeMongo fromNode(Node node) {
-        NodeMongo nodeMongo = new NodeMongo();
-
-        String path = node.getPath();
-        nodeMongo.setPath(path);
-
-        Long revisionId = node.getRevisionId();
-        if (revisionId != null) {
-            nodeMongo.setRevisionId(revisionId);
-        }
-
-        Map<String, Object> properties = node.getProperties();
-        if (properties != null) {
-            nodeMongo.setProperties(properties);
-        }
+    public static final String KEY_BRANCH_ID = "branchId";
 
-        Set<Node> children = node.getChildren();
-        if (children != null) {
-            List<String> childNames = new LinkedList<String>();
-            for (Node child : children) {
-                childNames.add(child.getName());
-            }
-            nodeMongo.setChildren(childNames);
-        }
-
-        return nodeMongo;
-    }
-
-    public static Set<NodeMongo> fromNodes(Collection<Node> nodes) {
-        Set<NodeMongo> nodeMongos = new HashSet<NodeMongo>(nodes.size());
-        for (Node node : nodes) {
-            NodeMongo nodeMongo = NodeMongo.fromNode(node);
-            nodeMongos.add(nodeMongo);
-        }
-
-        return nodeMongos;
-    }
-
-    public static List<Node> toNode(Collection<NodeMongo> nodeMongos) {
-        List<Node> nodes = new ArrayList<Node>(nodeMongos.size());
-        for (NodeMongo nodeMongo : nodeMongos) {
-            Node node = NodeMongo.toNode(nodeMongo);
-            nodes.add(node);
-        }
+    private static final long serialVersionUID = 3153393934945155106L;
 
-        return nodes;
-    }
+    private List<String> addedChildren;
+    private Map<String, Object> addedProps;
+    private List<String> removedChildren;
+    private Map<String, Object> removedProps;
 
-    public static NodeImpl toNode(NodeMongo nodeMongo) {
+    public static NodeImpl toNode(MongoNode nodeMongo) {
         String path = nodeMongo.getPath();
+        NodeImpl nodeImpl = new NodeImpl(path);
+
         List<String> childNames = nodeMongo.getChildren();
-        long childCount = childNames != null ? childNames.size() : 0;
-        Map<String, Object> properties = nodeMongo.getProperties();
-        Set<Node> children = null;
         if (childNames != null) {
-            children = new HashSet<Node>();
             for (String childName : childNames) {
-                NodeImpl child = new NodeImpl();
-                child.setPath(PathUtils.concat(path, childName));
-                children.add(child);
+                String childPath = PathUtils.concat(path, childName);
+                NodeImpl child = new NodeImpl(childPath);
+                nodeImpl.addChildNodeEntry(child);
             }
         }
 
-        Long revisionId = nodeMongo.getRevisionId();
-        NodeImpl nodeImpl = new NodeImpl();
-        nodeImpl.setPath(path);
-        nodeImpl.setChildCount(childCount);
-        nodeImpl.setRevisionId(revisionId);
-        nodeImpl.setProperties(properties);
-        nodeImpl.setChildren(children);
-
+        nodeImpl.setRevisionId(nodeMongo.getRevisionId());
+        for (Map.Entry<String, Object> entry : nodeMongo.getProperties().entrySet()) {
+            nodeImpl.addProperty(entry.getKey(), convertObjectValue(entry.getValue()));
+        }
         return nodeImpl;
     }
 
-    private List<String> addedChildren;
-    private Map<String, Object> addedProps;
-    private List<String> removedChildren;
-    private Map<String, Object> removedProps;
-
-    public void addChild(String childName) {
-        if (addedChildren == null) {
-            addedChildren = new LinkedList<String>();
+    private static String convertObjectValue(Object value) {
+        if (value == null) {
+            return null;
         }
-
-        addedChildren.add(childName);
+        if (value instanceof String) {
+            return JsopBuilder.encode(value.toString());
+        }
+        return value.toString();
     }
 
-    public void addProperty(String key, Object value) {
-        if (addedProps == null) {
-            addedProps = new HashMap<String, Object>();
-        }
+    //--------------------------------------------------------------------------
+    //
+    // These properties are persisted to MongoDB
+    //
+    //--------------------------------------------------------------------------
 
-        addedProps.put(key, value);
+    public void setBaseRevisionId(long baseRevisionId) {
+        put(KEY_BASE_REVISION_ID, baseRevisionId);
     }
 
-    public List<String> getAddedChildren() {
-        return addedChildren;
+    public String getBranchId() {
+        return getString(KEY_BRANCH_ID);
     }
 
-    public Map<String, Object> getAddedProps() {
-        return addedProps;
+    public void setBranchId(String branchId) {
+        put(KEY_BRANCH_ID, branchId);
     }
 
     @SuppressWarnings("unchecked")
     public List<String> getChildren() {
-        return (List<String>) this.get(KEY_CHILDREN);
+        return (List<String>)get(KEY_CHILDREN);
     }
 
-    public boolean childExists(String childName) {
-        List<String> children = getChildren();
-        if (children != null && !children.isEmpty()) {
-            if (children.contains(childName)) {
-                return true;
-            }
+    public void setChildren(List<String> children) {
+        if (children != null) {
+            put(KEY_CHILDREN, children);
+        } else {
+            removeField(KEY_CHILDREN);
         }
-        return false;
-        //return addedChildExists(childName);
-    }
-
-    private boolean addedChildExists(String childName) {
-        return addedChildren != null && !addedChildren.isEmpty()?
-                addedChildren.contains(childName) : false;
-    }
-
-    public String getName() {
-        return PathUtils.getName(getString(KEY_PATH));
     }
 
     public String getPath() {
         return getString(KEY_PATH);
     }
 
-    @SuppressWarnings("unchecked")
-    public Map<String, Object> getProperties() {
-        return (Map<String, Object>) this.get(KEY_PROPERTIES);
+    public void setPath(String path) {
+        put(KEY_PATH, path);
     }
 
-    public List<String> getRemovedChildren() {
-        return removedChildren;
+    @SuppressWarnings("unchecked")
+    public Map<String, Object> getProperties() {
+        Object properties = get(KEY_PROPERTIES);
+        return properties != null? (Map<String, Object>)properties : new HashMap<String, Object>();
     }
 
-    public Map<String, Object> getRemovedProps() {
-        return removedProps;
+    public void setProperties(Map<String, Object> properties) {
+        if (properties != null && !properties.isEmpty()) {
+            put(KEY_PROPERTIES, properties);
+        } else {
+            removeField(KEY_PROPERTIES);
+        }
     }
 
     public Long getRevisionId() {
         return getLong(KEY_REVISION_ID);
     }
 
+    public void setRevisionId(long revisionId) {
+        put(KEY_REVISION_ID, revisionId);
+    }
+
+    //--------------------------------------------------------------------------
+    //
+    // These properties are used to keep track of changes but not persisted
+    //
+    //--------------------------------------------------------------------------
+
+    public void addChild(String childName) {
+        if (addedChildren == null) {
+            addedChildren = new LinkedList<String>();
+        }
+        addedChildren.add(childName);
+    }
+
+    public List<String> getAddedChildren() {
+        return addedChildren;
+    }
+
     public void removeChild(String childName) {
         if (removedChildren == null) {
             removedChildren = new LinkedList<String>();
         }
-
         removedChildren.add(childName);
     }
 
+    public List<String> getRemovedChildren() {
+        return removedChildren;
+    }
+
+    public void addProperty(String key, Object value) {
+        if (addedProps == null) {
+            addedProps = new HashMap<String, Object>();
+        }
+        addedProps.put(key, value);
+    }
+
+    public Map<String, Object> getAddedProps() {
+        return addedProps;
+    }
+
     public void removeProp(String key) {
         if (removedProps == null) {
             removedProps = new HashMap<String, Object>();
         }
-
         removedProps.put(key, null);
     }
 
-    public void setBaseRevisionId(long baseRevisionId) {
-        put(KEY_BASE_REVISION_ID, baseRevisionId);
+    public Map<String, Object> getRemovedProps() {
+        return removedProps;
     }
 
-    public void setChildren(List<String> children) {
-        if (children != null) {
-            put(KEY_CHILDREN, children);
-        } else {
-            removeField(KEY_CHILDREN);
-        }
-    }
+    //--------------------------------------------------------------------------
+    //
+    // Other methods
+    //
+    //--------------------------------------------------------------------------
 
-    public void setPath(String path) {
-        put(KEY_PATH, path);
+    public boolean childExists(String childName) {
+        List<String> children = getChildren();
+        if (children != null && !children.isEmpty()) {
+            if (children.contains(childName) && !childExistsInRemovedChildren(childName)) {
+                return true;
+            }
+        }
+        return childExistsInAddedChildren(childName);
     }
 
-    public void setProperties(Map<String, Object> properties) {
-        if (properties != null) {
-            put(KEY_PROPERTIES, properties);
-        } else {
-            removeField(KEY_PROPERTIES);
-        }
+    private boolean childExistsInAddedChildren(String childName) {
+        return addedChildren != null && !addedChildren.isEmpty()?
+                addedChildren.contains(childName) : false;
     }
 
-    public void setRevisionId(long revisionId) {
-        put(KEY_REVISION_ID, revisionId);
+    private boolean childExistsInRemovedChildren(String childName) {
+        return removedChildren != null && !removedChildren.isEmpty()?
+                removedChildren.contains(childName) : false;
     }
 
     @Override
@@ -252,14 +217,22 @@ public class NodeMongo extends BasicDBOb
         StringBuilder sb = new StringBuilder();
         sb.append(super.toString());
         sb.deleteCharAt(sb.length() - 1);
-        sb.append(", addedChildren : ");
-        sb.append(addedChildren);
-        sb.append(", removedChildren : ");
-        sb.append(removedChildren);
-        sb.append(", addedProps : ");
-        sb.append(addedProps);
-        sb.append(", removedProps : ");
-        sb.append(removedProps);
+        if (addedChildren != null && !addedChildren.isEmpty()) {
+            sb.append(", addedChildren : ");
+            sb.append(addedChildren);
+        }
+        if (removedChildren != null && !removedChildren.isEmpty()) {
+            sb.append(", removedChildren : ");
+            sb.append(removedChildren);
+        }
+        if (addedProps != null && !addedProps.isEmpty()) {
+            sb.append(", addedProps : ");
+            sb.append(addedProps);
+        }
+        if (removedProps != null && !removedProps.isEmpty()) {
+            sb.append(", removedProps : ");
+            sb.append(removedProps);
+        }
         sb.append(" }");
         return sb.toString();
     }

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoNode.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java (from r1407101, jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/HeadMongo.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java?p2=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java&p1=jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/HeadMongo.java&r1=1407101&r2=1407119&rev=1407119&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/model/HeadMongo.java (original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java Thu Nov  8 15:17:50 2012
@@ -14,28 +14,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mongomk.model;
+package org.apache.jackrabbit.mongomk.impl.model;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DBObject;
 
 /**
  * The {@code MongoDB} representation of the head revision.
- *
- * @author <a href="mailto:pmarx@adobe.com>Philipp Marx</a>
  */
-@SuppressWarnings("javadoc")
-public class HeadMongo extends BasicDBObject {
+public class MongoSync extends BasicDBObject {
 
     public static final String KEY_HEAD_REVISION_ID = "headRevId";
     public static final String KEY_NEXT_REVISION_ID = "nextRevId";
     private static final long serialVersionUID = 3541425042129003691L;
 
-    public static HeadMongo fromDBObject(DBObject dbObject) {
-        HeadMongo headMongo = new HeadMongo();
-        headMongo.putAll(dbObject);
-
-        return headMongo;
+    public static MongoSync fromDBObject(DBObject dbObject) {
+        if (dbObject == null) {
+            return null;
+        }
+        MongoSync syncMongo = new MongoSync();
+        syncMongo.putAll(dbObject);
+        return syncMongo;
     }
 
     public long getHeadRevisionId() {

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/model/MongoSync.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message