Search in sources :

Example 71 with ChildNodeEntry

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

the class SameNameSiblingsEditor method prepareChildDefsWithoutSns.

/**
 * Prepare a list of node definitions that doesn't allow having SNS children.
 *
 * @param root Repository root
 * @return a list of node definitions denying SNS children
 */
private static List<ChildTypeDef> prepareChildDefsWithoutSns(NodeState root) {
    List<ChildTypeDef> defs = new ArrayList<ChildTypeDef>();
    NodeState types = root.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
    for (ChildNodeEntry typeEntry : types.getChildNodeEntries()) {
        NodeState type = typeEntry.getNodeState();
        TypePredicate typePredicate = new TypePredicate(root, typeEntry.getName());
        defs.addAll(parseResidualChildNodeDefs(root, type, typePredicate));
        defs.addAll(parseNamedChildNodeDefs(root, type, typePredicate));
    }
    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 72 with ChildNodeEntry

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

the class VersionHistoryUtil method getVersionableNodes.

private static void getVersionableNodes(NodeState node, NodeState versionStorage, TypePredicate isVersionable, Calendar olderThan, String path, List<String> paths) {
    if (isVersionable.apply(node)) {
        if (olderThan == null) {
            paths.add(path);
        } else {
            NodeState versionHistory = getVersionHistoryNodeState(versionStorage, node.getString(JCR_UUID));
            Calendar lastModified = getVersionHistoryLastModified(versionHistory);
            if (lastModified.before(olderThan)) {
                paths.add(path);
            }
        }
    }
    for (ChildNodeEntry c : node.getChildNodeEntries()) {
        getVersionableNodes(c.getNodeState(), versionStorage, isVersionable, olderThan, PathUtils.concat(path, c.getName()), paths);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Calendar(java.util.Calendar) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 73 with ChildNodeEntry

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

the class IndexDefinitionUpdaterTest method createIndexDefn.

private String createIndexDefn(NodeState nodeState, String... indexPaths) throws CommitFailedException {
    NodeStore store = new MemoryNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    for (ChildNodeEntry cne : nodeState.getChildNodeEntries()) {
        builder.setChildNode(cne.getName(), cne.getNodeState());
    }
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    IndexDefinitionPrinter printer = new IndexDefinitionPrinter(store, () -> asList(indexPaths));
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    printer.print(pw, Format.JSON, false);
    pw.flush();
    return sw.toString();
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) StringWriter(java.io.StringWriter) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexDefinitionPrinter(org.apache.jackrabbit.oak.plugins.index.inventory.IndexDefinitionPrinter) PrintWriter(java.io.PrintWriter)

Example 74 with ChildNodeEntry

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

the class DepthFirstNodeIterator method switchRoot.

public DepthFirstNodeIterator switchRoot(NodeState newRoot) {
    Deque<Iterator<? extends ChildNodeEntry>> newQueue = new ArrayDeque<>();
    NodeState current = newRoot;
    for (String name : nameQueue) {
        boolean found = false;
        Iterator<? extends ChildNodeEntry> it = current.getChildNodeEntries().iterator();
        newQueue.add(it);
        while (it.hasNext()) {
            ChildNodeEntry e = it.next();
            if (name.equals(e.getName())) {
                current = e.getNodeState();
                found = true;
                break;
            }
        }
        if (!found) {
            log.warn("Can't found {} in the new root. Switching to /", getPath());
            return new DepthFirstNodeIterator(newRoot);
        }
    }
    newQueue.add(current.getChildNodeEntries().iterator());
    return new DepthFirstNodeIterator(newRoot, newQueue, nameQueue);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) ArrayDeque(java.util.ArrayDeque)

Example 75 with ChildNodeEntry

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

the class UniqueIndexCleaner method clean.

public int clean(NodeBuilder builder, long lastIndexedTo) {
    int removalCount = 0;
    NodeState baseState = builder.getBaseState();
    for (ChildNodeEntry e : baseState.getChildNodeEntries()) {
        long entryCreationTime = e.getNodeState().getLong(PROP_CREATED);
        if (entryCovered(entryCreationTime, lastIndexedTo)) {
            builder.child(e.getName()).remove();
            removalCount++;
        }
    }
    return removalCount;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)80 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)23 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)7 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 Calendar (java.util.Calendar)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Nonnull (javax.annotation.Nonnull)2