Search in sources :

Example 21 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class ReportingNodeStateTest method getChildNodeEntriesReportsNode.

@Test
public void getChildNodeEntriesReportsNode() {
    final NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
    for (int i = 1; i < 20; i++) {
        builder.child("a" + i);
    }
    final AssertingPeriodicReporter reporter = new AssertingPeriodicReporter(10, 10);
    final NodeState nodeState = ReportingNodeState.wrap(builder.getNodeState(), reporter);
    reporter.reset();
    int counter = 0;
    String name = "<none>";
    for (final ChildNodeEntry child : nodeState.getChildNodeEntries()) {
        if (++counter == 10) {
            name = child.getName();
            break;
        }
    }
    assertThat(reporter, hasReportedNode(10, "/" + name));
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 22 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class CompositeNodeStoreTest method childNodeEntryForMountIsComposite.

@Test
public void childNodeEntryForMountIsComposite() {
    ChildNodeEntry libsNode = Iterables.find(store.getRoot().getChildNodeEntries(), new Predicate<ChildNodeEntry>() {

        @Override
        public boolean apply(ChildNodeEntry input) {
            return input.getName().equals("libs");
        }
    });
    assertThat("root.libs(childCount)", libsNode.getNodeState().getChildNodeCount(10), equalTo(3l));
}
Also used : ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Test(org.junit.Test)

Example 23 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class AggregateTest method noOfChildNodeRead.

@Test
public void noOfChildNodeRead() throws Exception {
    Aggregate ag = new Aggregate("nt:base", of(ni("a")));
    NodeBuilder nb = newNode("nt:base");
    nb.child("a");
    for (int i = 0; i < 10; i++) {
        nb.child("a" + i);
    }
    NodeState state = nb.getNodeState();
    final AtomicInteger counter = new AtomicInteger();
    Iterable<? extends ChildNodeEntry> countingIterator = Iterables.transform(state.getChildNodeEntries(), new Function<ChildNodeEntry, ChildNodeEntry>() {

        @Override
        public ChildNodeEntry apply(ChildNodeEntry input) {
            counter.incrementAndGet();
            return input;
        }
    });
    NodeState mocked = spy(state);
    doReturn(countingIterator).when(mocked).getChildNodeEntries();
    ag.collectAggregates(mocked, col);
    //Here at max a single call should happen for reading child nodes
    assertThat(counter.get(), is(lessThanOrEqualTo(1)));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 24 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class SameNameSiblingsEditor method parseNamedChildNodeDefs.

private static List<ChildTypeDef> parseNamedChildNodeDefs(NodeState root, NodeState parentType, TypePredicate parentTypePredicate) {
    List<ChildTypeDef> defs = new ArrayList<ChildTypeDef>();
    NodeState namedChildNodeDefinitions = parentType.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS);
    for (ChildNodeEntry childName : namedChildNodeDefinitions.getChildNodeEntries()) {
        for (String childType : filterChildren(childName.getNodeState(), NO_SNS_PROPERTY)) {
            TypePredicate childTypePredicate = new TypePredicate(root, childType);
            defs.add(new ChildTypeDef(parentTypePredicate, childName.getName(), childTypePredicate));
        }
    }
    return defs;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) ArrayList(java.util.ArrayList) TypePredicate(org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate)

Example 25 with ChildNodeEntry

use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.

the class VersionCopier method getVersionHistoryLastModified.

private Calendar getVersionHistoryLastModified(final NodeState versionHistory) {
    Calendar youngest = Calendar.getInstance();
    youngest.setTimeInMillis(0);
    for (final ChildNodeEntry entry : versionHistory.getChildNodeEntries()) {
        final NodeState version = entry.getNodeState();
        if (!isVersion.apply(version)) {
            continue;
        }
        if (version.hasProperty(JCR_CREATED)) {
            final Calendar created = ISO8601.parse(version.getProperty(JCR_CREATED).getValue(Type.DATE));
            if (created.after(youngest)) {
                youngest = created;
            }
        }
    }
    return youngest;
}
Also used : VersionHistoryUtil.getVersionHistoryNodeState(org.apache.jackrabbit.oak.upgrade.version.VersionHistoryUtil.getVersionHistoryNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Calendar(java.util.Calendar) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

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