Search in sources :

Example 6 with ChildNodeEntry

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;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) CheckForNull(javax.annotation.CheckForNull)

Example 7 with ChildNodeEntry

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);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) ArrayList(java.util.ArrayList)

Example 8 with ChildNodeEntry

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();
    }
}
Also used : ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 9 with ChildNodeEntry

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();
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Map(java.util.Map) Test(org.junit.Test)

Example 10 with ChildNodeEntry

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"));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)58 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)43 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)2 JsopBuilder.prettyPrint (org.apache.jackrabbit.oak.commons.json.JsopBuilder.prettyPrint)2 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)2