Search in sources :

Example 51 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState 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 52 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState 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 53 with NodeState

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

the class NodeTypeIndexLookup method isIndexed.

/**
     * Returns <code>true</code> if a node type index lookup exists at the given
     * <code>path</code> or further up the tree.
     *
     * @param path the path to check.
     * @return <code>true</code> if a node type index exists; <code>false</code>
     *         otherwise.
     */
public boolean isIndexed(String path, Filter f) {
    PropertyIndexLookup lookup = new PropertyIndexLookup(root, mountInfoProvider);
    if (lookup.isIndexed(JCR_PRIMARYTYPE, path, f) && lookup.isIndexed(JCR_MIXINTYPES, path, f)) {
        return true;
    }
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    int slash = path.indexOf('/');
    if (slash == -1) {
        return false;
    }
    NodeState child = root.getChildNode(path.substring(0, slash));
    return new NodeTypeIndexLookup(child, mountInfoProvider).isIndexed(path.substring(slash), f);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)

Example 54 with NodeState

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

the class NodeStoreDiffTest method testDiff.

/**
     * This testcase demonstrates that diff logic in merge part traverses node path
     * which are not affected by the commit
     * @throws Exception
     */
@Test
public void testDiff() throws Exception {
    createNodes("/oak:index/prop-a", "/oak:index/prop-b", "/etc/workflow");
    //1. Make some other changes so as to bump root rev=3
    createNodes("/fake/a");
    createNodes("/fake/b");
    //2 - Start change
    NodeBuilder b2 = ns.getRoot().builder();
    createNodes(b2, "/etc/workflow/instance1");
    tds.reset();
    //3. Merge which does a rebase
    ns.merge(b2, new CommitHook() {

        @Nonnull
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            NodeBuilder rb = after.builder();
            createNodes(rb, "/oak:index/prop-a/a1");
            //2.1 Commit some change under prop-
            //This cause diff in lastRev of base node state in ModifiedNodeState for
            //oak:index due to which when the base state is compared in ModifiedNodeState
            //then it fetches the new DocumentNodeState whose lastRev is greater than this.base.lastRev
            //but less then lastRev of the of readRevision. Where readRevision is the rev of root node when
            //rebase was performed
            // remember paths accessed so far
            List<String> paths = Lists.newArrayList(tds.paths);
            //This is not to be done in actual cases as CommitHooks are invoked in critical sections
            //and creating nodes from within CommitHooks would cause deadlock. This is done here to ensure
            //that changes are done when rebase has been performed and merge is about to happen
            createNodes("/oak:index/prop-b/b1");
            // reset accessed paths
            tds.reset();
            tds.paths.addAll(paths);
            return rb.getNodeState();
        }
    }, CommitInfo.EMPTY);
    //Assert that diff logic does not traverse to /oak:index/prop-b/b1 as
    //its not part of commit
    assertFalse(tds.paths.contains("/oak:index/prop-b/b1"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) List(java.util.List) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 55 with NodeState

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

the class NodeStoreDiffTest method merge.

private NodeState merge(NodeBuilder nb) throws CommitFailedException {
    NodeState result = ns.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    prRev(result);
    ops();
    return result;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)580 Test (org.junit.Test)375 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)254 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)69 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)46 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)45 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)43 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)39 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)36 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)33 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)32 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)29 Nonnull (javax.annotation.Nonnull)28 Tree (org.apache.jackrabbit.oak.api.Tree)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)19 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)18 ArrayList (java.util.ArrayList)17 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15