use of org.apache.jackrabbit.oak.commons.json.JsopStream in project jackrabbit-oak by apache.
the class DocumentMK method getNodes.
public String getNodes(String path, String revisionId, int depth, long offset, int maxChildNodes, String filter) throws DocumentStoreException {
if (depth != 0) {
throw new DocumentStoreException("Only depth 0 is supported, depth is " + depth);
}
revisionId = revisionId != null ? revisionId : nodeStore.getHeadRevision().toString();
RevisionVector rev = RevisionVector.fromString(revisionId);
try {
DocumentNodeState n = nodeStore.getNode(path, rev);
if (n == null) {
return null;
}
JsopStream json = new JsopStream();
boolean includeId = filter != null && filter.contains(":id");
includeId |= filter != null && filter.contains(":hash");
json.object();
append(n, json, includeId);
int max;
if (maxChildNodes == -1) {
max = Integer.MAX_VALUE;
maxChildNodes = Integer.MAX_VALUE;
} else {
// use long to avoid overflows
long m = ((long) maxChildNodes) + offset;
max = (int) Math.min(m, Integer.MAX_VALUE);
}
Children c = nodeStore.getChildren(n, null, max);
for (long i = offset; i < c.children.size(); i++) {
if (maxChildNodes-- <= 0) {
break;
}
String name = c.children.get((int) i);
json.key(name).object().endObject();
}
if (c.hasMore) {
json.key(":childNodeCount").value(Long.MAX_VALUE);
} else {
json.key(":childNodeCount").value(c.children.size());
}
json.endObject();
return json.toString();
} catch (DocumentStoreException e) {
throw new DocumentStoreException(e);
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopStream 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.JsopStream in project jackrabbit-oak by apache.
the class Commit method addChangesToDiffCacheEntry.
/**
* Apply the changes of a node to the cache.
*
* @param path the path
* @param added the list of added child nodes
* @param removed the list of removed child nodes
* @param changed the list of changed child nodes
* @param cacheEntry the cache entry changes are added to
*/
private void addChangesToDiffCacheEntry(String path, List<String> added, List<String> removed, List<String> changed, DiffCache.Entry cacheEntry) {
// update diff cache
JsopWriter w = new JsopStream();
for (String p : added) {
w.tag('+').key(PathUtils.getName(p)).object().endObject();
}
for (String p : removed) {
w.tag('-').value(PathUtils.getName(p));
}
for (String p : changed) {
w.tag('^').key(PathUtils.getName(p)).object().endObject();
}
cacheEntry.append(path, w.toString());
}
Aggregations