jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1097137 - /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Date Wed, 27 Apr 2011 15:08:20 GMT
Author: stefan
Date: Wed Apr 27 15:08:20 2011
New Revision: 1097137

URL: http://svn.apache.org/viewvc?rev=1097137&view=rev
Log:
MicroKernel prototype (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java?rev=1097137&r1=1097136&r2=1097137&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Wed Apr 27 15:08:20 2011
@@ -70,6 +70,47 @@ public class CommitBuilder {
         }
 
         parent.getChildNodeEntries().remove(nodeName);
+
+        // update staging area
+        removeStagedNodes(nodePath);
+    }
+
+    public void moveNode(String srcPath, String destPath) throws Exception {
+        String srcParentPath = getParentPath(srcPath);
+        String srcNodeName = getName(srcPath);
+
+        String destParentPath = getParentPath(destPath);
+        String destNodeName = getName(destPath);
+
+        MutableNode srcParent = getOrCreateStagedNode(srcParentPath);
+        String targetId = srcParent.getChildNodeEntries().get(srcNodeName);
+        if (targetId == null) {
+            throw new Exception("node not found: " + srcPath);
+        }
+        srcParent.getChildNodeEntries().remove(srcNodeName);
+
+        MutableNode destParent = getOrCreateStagedNode(destParentPath);
+        destParent.getChildNodeEntries().put(destNodeName, targetId);
+
+        // update staging area
+        moveStagedNodes(srcPath, destPath);
+    }
+
+    public void copyNode(String srcPath, String destPath) throws Exception {
+        String srcParentPath = getParentPath(srcPath);
+        String srcNodeName = getName(srcPath);
+
+        String destParentPath = getParentPath(destPath);
+        String destNodeName = getName(destPath);
+
+        MutableNode srcParent = getOrCreateStagedNode(srcParentPath);
+        String targetId = srcParent.getChildNodeEntries().get(srcNodeName);
+        if (targetId == null) {
+            throw new Exception("node not found: " + srcPath);
+        }
+
+        MutableNode destParent = getOrCreateStagedNode(destParentPath);
+        destParent.getChildNodeEntries().put(destNodeName, targetId);
     }
 
     public void setProperty(String nodePath, String propName, String propValue) throws Exception
{
@@ -87,7 +128,7 @@ public class CommitBuilder {
 
     public String /* new revId */ doCommit() throws Exception {
         if (rep.getHeadRevision() != baseRevId) {
-            // todo implement merge
+            // todo lock head revision and re-apply changes
         }
 
         ArrayList<String> orderedPaths = new ArrayList<String>(staged.keySet());
@@ -159,6 +200,27 @@ public class CommitBuilder {
         return node;
     }
 
+    void moveStagedNodes(String srcPath, String destPath) throws Exception {
+        MutableNode node = staged.get(srcPath);
+        if (node != null) {
+            staged.remove(srcPath);
+            staged.put(destPath, node);
+            for (String childName : node.getChildNodeEntries().keySet()) {
+                moveStagedNodes(srcPath + "/" + childName, destPath + "/" + childName);
+            }
+        }
+    }
+
+    void removeStagedNodes(String nodePath) throws Exception {
+        MutableNode node = staged.get(nodePath);
+        if (node != null) {
+            staged.remove(nodePath);
+            for (String childName : node.getChildNodeEntries().keySet()) {
+                removeStagedNodes(nodePath + "/" + childName);
+            }
+        }
+    }
+
     static String getParentPath(String path) {
         int pos = path.lastIndexOf('/');
         if (pos > 0) {



Mime
View raw message