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;
}
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());
}
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()));
}
}
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();
}
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();
}
Aggregations