Search in sources :

Example 1 with JsopWriter

use of org.apache.jackrabbit.oak.commons.json.JsopWriter in project jackrabbit-oak by apache.

the class DocumentNodeStore method diffImpl.

private String diffImpl(AbstractDocumentNodeState from, AbstractDocumentNodeState to) throws DocumentStoreException {
    int max = MANY_CHILDREN_THRESHOLD;
    final boolean debug = LOG.isDebugEnabled();
    final long start = debug ? now() : 0;
    long getChildrenDoneIn = start;
    String diff;
    String diffAlgo;
    RevisionVector fromRev = from.getLastRevision();
    RevisionVector toRev = to.getLastRevision();
    long minTimestamp = Utils.getMinTimestampForDiff(from.getRootRevision(), to.getRootRevision(), getMinExternalRevisions());
    // use journal if possible
    Revision tailRev = journalGarbageCollector.getTailRevision();
    if (!disableJournalDiff && tailRev.getTimestamp() < minTimestamp) {
        diffAlgo = "diffJournalChildren";
        fromRev = from.getRootRevision();
        toRev = to.getRootRevision();
        diff = new JournalDiffLoader(from, to, this).call();
    } else {
        JsopWriter w = new JsopStream();
        boolean continueDiff = bundledDocDiffer.diff(from, to, w);
        if (continueDiff) {
            DocumentNodeState.Children fromChildren, toChildren;
            fromChildren = getChildren(from, null, max);
            toChildren = getChildren(to, null, max);
            getChildrenDoneIn = debug ? now() : 0;
            if (!fromChildren.hasMore && !toChildren.hasMore) {
                diffAlgo = "diffFewChildren";
                diffFewChildren(w, from.getPath(), fromChildren, fromRev, toChildren, toRev);
            } else {
                if (FAST_DIFF) {
                    diffAlgo = "diffManyChildren";
                    fromRev = from.getRootRevision();
                    toRev = to.getRootRevision();
                    diffManyChildren(w, from.getPath(), fromRev, toRev);
                } else {
                    diffAlgo = "diffAllChildren";
                    max = Integer.MAX_VALUE;
                    fromChildren = getChildren(from, null, max);
                    toChildren = getChildren(to, null, max);
                    diffFewChildren(w, from.getPath(), fromChildren, fromRev, toChildren, toRev);
                }
            }
        } else {
            diffAlgo = "allBundledChildren";
        }
        diff = w.toString();
    }
    if (debug) {
        long end = now();
        LOG.debug("Diff performed via '{}' at [{}] between revisions [{}] => [{}] took {} ms ({} ms), diff '{}', external '{}", diffAlgo, from.getPath(), fromRev, toRev, end - start, getChildrenDoneIn - start, diff, to.isFromExternalChange());
    }
    return diff;
}
Also used : JsopStream(org.apache.jackrabbit.oak.commons.json.JsopStream) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 2 with JsopWriter

use of org.apache.jackrabbit.oak.commons.json.JsopWriter in project jackrabbit-oak by apache.

the class BundledDocumentDifferTest method testDiff.

@Test
public void testDiff() throws Exception {
    NodeBuilder builder = createContentStructure();
    NodeState r1 = merge(store, builder);
    builder = store.getRoot().builder();
    childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", "bar");
    NodeState r2 = merge(store, builder);
    JsopWriter w = new JsopBuilder();
    String path = "/test";
    assertTrue(differ.diff(dns(r1, path), dns(r2, path), w));
    assertTrue(w.toString().isEmpty());
    w = new JsopBuilder();
    path = "/test/book.jpg";
    assertFalse(differ.diff(dns(r1, path), dns(r2, path), w));
    assertEquals("^\"jcr:content\":{}", w.toString());
    builder = store.getRoot().builder();
    childBuilder(builder, "/test/book.jpg/foo");
    NodeState r3 = merge(store, builder);
    w = new JsopBuilder();
    path = "/test/book.jpg";
    //As there is a non bundled child differ should return true to continue diffing
    assertTrue(differ.diff(dns(r1, path), dns(r3, path), w));
    assertEquals("^\"jcr:content\":{}", w.toString());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) DelegatingDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter) Test(org.junit.Test)

Example 3 with JsopWriter

use of org.apache.jackrabbit.oak.commons.json.JsopWriter in project jackrabbit-oak by apache.

the class IndexDefinitionPrinter method print.

@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
    if (format == Format.JSON) {
        NodeState root = nodeStore.getRoot();
        JsopWriter json = new JsopBuilder();
        json.object();
        for (String indexPath : indexPathService.getIndexPaths()) {
            json.key(indexPath);
            NodeState idxState = NodeStateUtils.getNode(root, indexPath);
            NodeStateJsonUtils.copyAsJson(json, idxState, false);
        }
        json.endObject();
        printWriter.print(JsopBuilder.prettyPrint(json.toString()));
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 4 with JsopWriter

use of org.apache.jackrabbit.oak.commons.json.JsopWriter in project jackrabbit-oak by apache.

the class ChangeSet method asString.

//~----------------------------------------------------< json support >
public String asString() {
    JsopWriter json = new JsopBuilder();
    json.object();
    json.key("maxPathDepth").value(maxPathDepth);
    addToJson(json, "parentPaths", parentPaths);
    addToJson(json, "parentNodeNames", parentNodeNames);
    addToJson(json, "parentNodeTypes", parentNodeTypes);
    addToJson(json, "propertyNames", propertyNames);
    addToJson(json, "allNodeTypes", allNodeTypes);
    json.endObject();
    return json.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Example 5 with JsopWriter

use of org.apache.jackrabbit.oak.commons.json.JsopWriter in project jackrabbit-oak by apache.

the class NodeDocument method asString.

public String asString() {
    JsopWriter json = new JsopBuilder();
    toJson(json, data);
    return json.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsopWriter(org.apache.jackrabbit.oak.commons.json.JsopWriter)

Aggregations

JsopWriter (org.apache.jackrabbit.oak.commons.json.JsopWriter)11 JsopBuilder (org.apache.jackrabbit.oak.commons.json.JsopBuilder)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 Test (org.junit.Test)3 Map (java.util.Map)2 JsopStream (org.apache.jackrabbit.oak.commons.json.JsopStream)2 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)2 DelegatingDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1