use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class EffectiveType method getDefaultType.
/**
* Finds the default node type for a child node with the given name.
*
* @param nameWithIndex child node name, possibly with an SNS index
* @return default type, or {@code null} if not found
*/
@CheckForNull
String getDefaultType(@Nonnull String nameWithIndex) {
String name = dropIndexFromName(nameWithIndex);
boolean sns = !name.equals(nameWithIndex);
for (NodeState type : types) {
NodeState named = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
for (ChildNodeEntry entry : concat(named.getChildNodeEntries(), residual.getChildNodeEntries())) {
NodeState definition = entry.getNodeState();
String defaultType = definition.getName(JCR_DEFAULTPRIMARYTYPE);
if (defaultType != null && snsMatch(sns, definition)) {
return defaultType;
}
}
}
return null;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class NodeCounter method collectCounts.
private void collectCounts(StringBuilder buff, String path, int level) {
long count = getEstimatedNodeCount(path);
if (count > 0) {
if (buff.length() > 0) {
buff.append(",\n");
}
buff.append(path).append(": ").append(count);
}
if (level <= 0) {
return;
}
NodeState s = child(store.getRoot(), PathUtils.elements(path));
if (!s.exists()) {
return;
}
ArrayList<String> names = new ArrayList<String>();
for (ChildNodeEntry c : s.getChildNodeEntries()) {
names.add(c.getName());
}
Collections.sort(names);
for (String cn : names) {
s.getChildNode(cn);
String child = PathUtils.concat(path, cn);
collectCounts(buff, child, level - 1);
}
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class NodeStateJsonUtils method copyNode.
private static void copyNode(NodeState state, JsopWriter json, boolean includeHiddenContent) {
copyProperties(state, json, includeHiddenContent);
for (ChildNodeEntry cne : state.getChildNodeEntries()) {
if (!includeHiddenContent && NodeStateUtils.isHidden(cne.getName())) {
continue;
}
json.key(cne.getName());
json.object();
copyNode(cne.getNodeState(), json, includeHiddenContent);
json.endObject();
}
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class ManyChildNodesTest method manyChildNodes.
@Test
public void manyChildNodes() throws Exception {
TestStore store = new TestStore();
DocumentMK mk = new DocumentMK.Builder().setDocumentStore(store).open();
NodeStore ns = mk.getNodeStore();
NodeBuilder builder = ns.getRoot().builder();
for (int i = 0; i < DocumentNodeState.MAX_FETCH_SIZE * 2; i++) {
builder.child("c-" + i);
}
ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
store.queries.clear();
// must fetch in batches
for (ChildNodeEntry entry : ns.getRoot().getChildNodeEntries()) {
entry.getName();
}
// maximum fetch size is MAX_FETCH_SIZE plus one because
// DocumentNodeStore will use this value to find out if there
// are more child nodes than requested
int maxFetchSize = DocumentNodeState.MAX_FETCH_SIZE + 1;
for (Map.Entry<String, Integer> e : store.queries.entrySet()) {
assertTrue(e.getValue() + " > " + maxFetchSize, e.getValue() <= maxFetchSize);
}
mk.dispose();
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method diffExternalChanges.
// OAK-2232
@Test
public void diffExternalChanges() throws Exception {
long modifiedResMillis = SECONDS.toMillis(MODIFIED_IN_SECS_RESOLUTION);
Clock clock = new Clock.Virtual();
clock.waitUntil(System.currentTimeMillis());
Revision.setClock(clock);
DocumentStore docStore = new MemoryDocumentStore();
DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(docStore).setClusterId(1).getNodeStore();
DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(docStore).setClusterId(2).getNodeStore();
NodeBuilder builder = ns1.getRoot().builder();
NodeBuilder test = builder.child("test");
for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
test.child("node-" + i);
}
ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
// make sure next change has a different _modified value
clock.waitUntil(clock.getTime() + modifiedResMillis * 2);
builder = ns2.getRoot().builder();
builder.child("test").child("foo");
ns2.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// 'wait' again for a different _modified value
clock.waitUntil(clock.getTime() + modifiedResMillis * 2);
builder = ns1.getRoot().builder();
builder.child("test").child("bar");
ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// remember current root for diff
NodeState r1 = ns1.getRoot();
ns2.runBackgroundOperations();
ns1.runBackgroundOperations();
NodeState r2 = ns1.getRoot();
// are we able to see foo?
boolean found = false;
for (ChildNodeEntry entry : r2.getChildNode("test").getChildNodeEntries()) {
if (entry.getName().equals("foo")) {
found = true;
break;
}
}
assertTrue(found);
// diff must report '/test' modified and '/test/foo' added
TrackingDiff diff = new TrackingDiff();
r2.compareAgainstBaseState(r1, diff);
assertEquals(1, diff.modified.size());
assertTrue(diff.modified.contains("/test"));
assertEquals(1, diff.added.size());
assertTrue(diff.added.contains("/test/foo"));
}
Aggregations