jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1466546 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/JsopDiff.java
Date Wed, 10 Apr 2013 16:22:29 GMT
Author: mduerig
Date: Wed Apr 10 16:22:29 2013
New Revision: 1466546

URL: http://svn.apache.org/r1466546
Log:
OAK-769: Add utility method to JsopDiff for debugging node states

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=1466546&r1=1466545&r2=1466546&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
Wed Apr 10 16:22:29 2013
@@ -16,8 +16,14 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import static org.apache.jackrabbit.oak.api.Type.BINARIES;
+import static org.apache.jackrabbit.oak.api.Type.BOOLEANS;
+import static org.apache.jackrabbit.oak.api.Type.LONGS;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 
 import javax.jcr.PropertyType;
 
@@ -32,11 +38,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.oak.api.Type.BINARIES;
-import static org.apache.jackrabbit.oak.api.Type.BOOLEANS;
-import static org.apache.jackrabbit.oak.api.Type.LONGS;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-
 /**
  * TODO document
  */
@@ -65,6 +66,17 @@ class JsopDiff implements NodeStateDiff 
         after.compareAgainstBaseState(before, new JsopDiff(kernel, jsop, path));
     }
 
+    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(kernel, jsop, path);
     }
@@ -156,14 +168,7 @@ class JsopDiff implements NodeStateDiff 
                 break;
             case PropertyType.BINARY:
                 for (Blob value : property.getValue(BINARIES)) {
-                    String binId;
-                    if (value instanceof KernelBlob) {
-                        binId = ((KernelBlob) value).getBinaryID();
-                    } else {
-                        InputStream is = value.getNewStream();
-                        binId = kernel.write(is);
-                        close(is);
-                    }
+                    String binId = writeBlob(value);
                     jsop.value(TypeCodes.encode(type, binId));
                 }
                 break;
@@ -178,6 +183,23 @@ class JsopDiff implements NodeStateDiff 
         }
     }
 
+    /**
+     * Make sure {@code blob} is persisted and return the id of the persisted blob.
+     * @param blob  blob to persist
+     * @return  id of the persisted blob
+     */
+    protected String writeBlob(Blob blob) {
+        String blobId;
+        if (blob instanceof KernelBlob) {
+            blobId = ((KernelBlob) blob).getBinaryID();
+        } else {
+            InputStream is = blob.getNewStream();
+            blobId = kernel.write(is);
+            close(is);
+        }
+        return blobId;
+    }
+
     private static void close(InputStream stream) {
         try {
             stream.close();



Mime
View raw message