jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1485629 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
Date Thu, 23 May 2013 09:41:14 GMT
Author: mduerig
Date: Thu May 23 09:41:14 2013
New Revision: 1485629

URL: http://svn.apache.org/r1485629
Log:
OAK-769: Add utility method to JsopDiff for debugging node states
Add utility method back, which was removed at revision 1479858. Add documentation to indicate
debugging purpose

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java?rev=1485629&r1=1485628&r2=1485629&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
Thu May 23 09:41:14 2013
@@ -22,6 +22,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import javax.jcr.PropertyType;
 
@@ -55,12 +56,48 @@ class JsopDiff implements NodeStateDiff 
         this(store, new JsopBuilder(), "/");
     }
 
+    /**
+     * Create the jsop diff between {@code before} and {@code after} and
+     * stores binaries to {@code store}.
+     *
+     * @param store   node store for storing binaries.
+     * @param before  before node state
+     * @param after   after node state
+     * @param path    base path
+     * @param jsop    builder to feed in the diff
+     */
     public static void diffToJsop(
             KernelNodeStore store, NodeState before, NodeState after,
             String path, JsopBuilder jsop) {
         after.compareAgainstBaseState(before, new JsopDiff(store, jsop, path));
     }
 
+    /**
+     * Create the jsop diff between {@code before} and {@code after} for
+     * debugging purposes.
+     * <p>
+     * This method does not store binaries but returns them inlined
+     * in the format
+     * <pre>
+     *   "Blob{" + Arrays.toString(blob.sha256()) + "}"
+     * </pre>.
+     *
+     * @param before  before node state
+     * @param after  after node state
+     * @return  jsop diff between {@code before} and {@code after}
+     */
+    public static String diffToJsop(NodeState before, NodeState after) {
+        JsopDiff diff = new JsopDiff(null) {
+            @Override
+            protected String writeBlob(Blob blob) {
+                return "Blob{" + Arrays.toString(blob.sha256()) + '}';
+            }
+        };
+        after.compareAgainstBaseState(before, diff);
+        return diff.toString();
+    }
+
+
     protected JsopDiff createChildDiff(JsopBuilder jsop, String path) {
         return new JsopDiff(store, jsop, path);
     }
@@ -184,7 +221,7 @@ class JsopDiff implements NodeStateDiff 
      * @param blob  blob to persist
      * @return  id of the persisted blob
      */
-    private String writeBlob(Blob blob) {
+    protected String writeBlob(Blob blob) {
         KernelBlob kernelBlob;
         if (blob instanceof KernelBlob) {
             kernelBlob = (KernelBlob) blob;



Mime
View raw message