jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1154221 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: ./ json/ mem/ store/
Date Fri, 05 Aug 2011 14:04:11 GMT
Author: stefan
Date: Fri Aug  5 14:04:10 2011
New Revision: 1154221

URL: http://svn.apache.org/viewvc?rev=1154221&view=rev
Log:
representing moves correctly in journal and some minor improvements (WIP)...

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java
      - copied, changed from r1151857, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/ExceptionFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java

Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java
(from r1151857, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java&r1=1151857&r2=1154221&rev=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Constants.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Constants.java Fri
Aug  5 14:04:10 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.mem;
+package org.apache.jackrabbit.mk;
 
 /**
  * Constants used in this project.

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Aug  5 14:04:10 2011
@@ -142,6 +142,8 @@ public class MicroKernelImpl implements 
         }
 
         JsopBuilder commitBuff = new JsopBuilder().array();
+        // iterate over commits in chronological order,
+        // starting with oldest commit
         for (int i = commits.size() - 1; i >= 0; i--) {
             Commit commit = commits.get(i);
             if (commit.getParentId() == null) {
@@ -152,6 +154,11 @@ public class MicroKernelImpl implements 
                 key("ts").value(commit.getCommitTS()).
                 key("msg").value(commit.getMsg());
             final JsopBuilder buff = new JsopBuilder();
+            // maps (key: id of target node, value: path/to/target)
+            // for tracking added/removed nodes; this allows us
+            // to detect 'move' operations
+            final HashMap<String, String> addedNodes =  new HashMap<String, String>();
+            final HashMap<String, String> removedNodes =  new HashMap<String, String>();
             try {
                 String path = "/";
                 Node node1 = rep.getNode(commit.getParentId(), path);
@@ -183,6 +190,7 @@ public class MicroKernelImpl implements 
                     }
 
                     public void childNodeAdded(String nodePath, String childName, String
id) {
+                        addedNodes.put(id, PathUtils.concat(nodePath, childName));
                         buff.append("+ ").
                             key(PathUtils.concat(nodePath, childName)).object();
                         try {
@@ -194,6 +202,7 @@ public class MicroKernelImpl implements 
                     }
 
                     public void childNodeDeleted(String nodePath, String childName, String
id) {
+                        removedNodes.put(id, PathUtils.concat(nodePath, childName));
                         buff.append("- ");
                         buff.value(PathUtils.concat(nodePath, childName));
                         buff.appendWhitespace("\n");
@@ -203,6 +212,83 @@ public class MicroKernelImpl implements 
                         // we're not interested
                     }
                 });
+
+                // check if this commit includes 'move' operations
+                // by building intersection of added and removed nodes
+                addedNodes.keySet().retainAll(removedNodes.keySet());
+                if (!addedNodes.isEmpty()) {
+                    // this commit includes 'move' operations
+                    removedNodes.keySet().retainAll(addedNodes.keySet());
+                    // addedNodes & removedNodes now only contain information about moved
nodes
+
+                    // re-build the diff in a 2nd pass, this time representing moves correctly
+                    buff.reset();
+
+                    // TODO refactor code, avoid duplication
+                    NodeUtils.diff(path, node1, node2, true, rep.getStore(), new NodeDiffHandler()
{
+                        public void propAdded(String nodePath, String propName, String value)
{
+                            buff.append("+ ").
+                                key(PathUtils.concat(nodePath, propName)).
+                                encodedValue(value).
+                                append("\n");
+                        }
+
+                        public void propChanged(String nodePath, String propName, String
oldValue, String newValue) {
+                            buff.append("^ ").
+                                key(PathUtils.concat(nodePath, propName)).
+                                encodedValue(newValue).
+                                append("\n");
+                        }
+
+                        public void propDeleted(String nodePath, String propName, String
value) {
+                            // since property and node deletions can't be distinguished
+                            // using the "- <path>" notation we're representing
+                            // property deletions as "^ <path>:null"
+                            buff.append("^ ").
+                                key(PathUtils.concat(nodePath, propName)).
+                                encodedValue("null").
+                                append("\n");
+                        }
+
+                        public void childNodeAdded(String nodePath, String childName, String
id) {
+                            if (addedNodes.containsKey(id)) {
+                                // moved node, will be processed separately
+                                return;
+                            }
+                            buff.append("+ ").
+                                key(PathUtils.concat(nodePath, childName)).object();
+                            try {
+                                toJson(buff, rep.getStore().getNode(id), childName, Integer.MAX_VALUE,
0, -1);
+                            } catch (Exception e) {
+                                buff.value("ERROR: failed to retrieve node " + id);
+                            }
+                            buff.endObject().append("\n");
+                        }
+
+                        public void childNodeDeleted(String nodePath, String childName, String
id) {
+                            if (addedNodes.containsKey(id)) {
+                                // moved node, will be processed separately
+                                return;
+                            }
+                            buff.append("- ");
+                            buff.value(PathUtils.concat(nodePath, childName));
+                            buff.append("\n");
+                        }
+
+                        public void childNodeChanged(String nodePath, String childName, String
oldId, String newId) {
+                            // we're not interested
+                        }
+                    });
+                    // finally process moved nodes
+                    for (Map.Entry<String, String> entry : addedNodes.entrySet()) {
+                        buff.append("> ").
+                            // path/to/deleted/node
+                            key(removedNodes.get(entry.getKey())).
+                            // path/to/added/node
+                            value(entry.getValue()).
+                            append("\n");
+                    }
+                }
             } catch (Exception e) {
                 throw new MicroKernelException(e);
             }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java
Fri Aug  5 14:04:10 2011
@@ -248,7 +248,7 @@ public final class JsonBuilder {
             return null;
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         for(int i = 0; i < string.length(); i++) {
             char ch = string.charAt(i);
             switch(ch) {
@@ -338,7 +338,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (String value : values) {
             sb.append(encode(value));
@@ -354,7 +354,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (int value : values) {
             sb.append(encode(value));
@@ -370,7 +370,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (long value : values) {
             sb.append(encode(value));
@@ -386,7 +386,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (float value : values) {
             sb.append(encode(value));
@@ -402,7 +402,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (double value : values) {
             sb.append(encode(value));
@@ -418,7 +418,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (Number value : values) {
             sb.append(encode(value));
@@ -434,7 +434,7 @@ public final class JsonBuilder {
             return "[]";
         }
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (boolean value : values) {
             sb.append(encode(value));

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Fri Aug  5 14:04:10 2011
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.mk.json;
 
-import org.apache.jackrabbit.mk.mem.Constants;
+import org.apache.jackrabbit.mk.Constants;
 
 /**
  * A builder for Json and Jsop strings. It encodes string values, and knows when
@@ -30,6 +30,14 @@ public class JsopBuilder {
     private boolean needComma;
 
     /**
+     * Resets this instance.
+     */
+    public void reset() {
+        needComma = false;
+        buff.setLength(0);
+    }
+
+    /**
      * Append an already formatted string. This will reset the comma flag, so no
      * comma is added before the next key or value.
      *

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/ExceptionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/ExceptionFactory.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/ExceptionFactory.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/ExceptionFactory.java
Fri Aug  5 14:04:10 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.mem;
 
+import org.apache.jackrabbit.mk.Constants;
+
 import java.text.MessageFormat;
 import java.util.ConcurrentModificationException;
 import java.util.HashMap;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Fri Aug  5 14:04:10 2011
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map.Entry;
+
+import org.apache.jackrabbit.mk.Constants;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.util.PathUtils;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java?rev=1154221&r1=1154220&r2=1154221&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
Fri Aug  5 14:04:10 2011
@@ -158,7 +158,7 @@ public class SimpleRevisionStore impleme
     }
 
     private File getFile(String id) {
-        StringBuffer buf = new StringBuffer(id.substring(0, 2));
+        StringBuilder buf = new StringBuilder(id.substring(0, 2));
         buf.append('/');
         buf.append(id.substring(2));
         return new File(dataDir, buf.toString());



Mime
View raw message