use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState.Children 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.plugins.document.DocumentNodeState.Children in project jackrabbit-oak by apache.
the class SimpleTest method commit.
@Test
public void commit() {
DocumentMK mk = createMK();
DocumentNodeStore ns = mk.getNodeStore();
String rev = mk.commit("/", "+\"test\":{\"name\": \"Hello\"}", null, null);
String test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
assertEquals("{\"name\":\"Hello\",\":childNodeCount\":0}", test);
String r0 = mk.commit("/test", "+\"a\":{\"name\": \"World\"}", null, null);
String r1 = mk.commit("/test", "+\"b\":{\"name\": \"!\"}", null, null);
test = mk.getNodes("/test", r0, 0, 0, Integer.MAX_VALUE, null);
DocumentNodeState n = ns.getNode("/", RevisionVector.fromString(r0));
assertNotNull(n);
Children c = ns.getChildren(n, null, Integer.MAX_VALUE);
assertEquals("[test]", c.toString());
n = ns.getNode("/test", RevisionVector.fromString(r1));
assertNotNull(n);
c = ns.getChildren(n, null, Integer.MAX_VALUE);
assertEquals("[a, b]", c.toString());
rev = mk.commit("", "^\"/test\":1", null, null);
test = mk.getNodes("/", rev, 0, 0, Integer.MAX_VALUE, null);
assertEquals("{\"test\":1,\"test\":{},\":childNodeCount\":1}", test);
// System.out.println(test);
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentNodeState.Children in project jackrabbit-oak by apache.
the class SimpleTest method delete.
@Test
public void delete() {
DocumentMK mk = createMK();
DocumentNodeStore ns = mk.getNodeStore();
mk.commit("/", "+\"testDel\":{\"name\": \"Hello\"}", null, null);
mk.commit("/testDel", "+\"a\":{\"name\": \"World\"}", null, null);
mk.commit("/testDel", "+\"b\":{\"name\": \"!\"}", null, null);
String r1 = mk.commit("/testDel", "+\"c\":{\"name\": \"!\"}", null, null);
DocumentNodeState n = ns.getNode("/testDel", RevisionVector.fromString(r1));
assertNotNull(n);
Children c = ns.getChildren(n, null, Integer.MAX_VALUE);
assertEquals(3, c.children.size());
String r2 = mk.commit("/testDel", "-\"c\"", null, null);
n = ns.getNode("/testDel", RevisionVector.fromString(r2));
assertNotNull(n);
c = ns.getChildren(n, null, Integer.MAX_VALUE);
assertEquals(2, c.children.size());
String r3 = mk.commit("/", "-\"testDel\"", null, null);
n = ns.getNode("/testDel", RevisionVector.fromString(r3));
assertNull(n);
}
Aggregations