Search in sources :

Example 11 with NodeState

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

the class PropertyIndexTest method testUnique.

@Test(expected = CommitFailedException.class)
public void testUnique() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definition
    NodeBuilder builder = root.builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, true, ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
    NodeState after = builder.getNodeState();
    // should throw
    HOOK.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 12 with NodeState

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

the class PropertyIndexTest method testUniqueByTypeOK.

@Test
public void testUniqueByTypeOK() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definition
    NodeBuilder builder = root.builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, true, ImmutableSet.of("foo"), ImmutableSet.of("typeFoo"));
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(JCR_PRIMARYTYPE, "typeFoo", Type.NAME).setProperty("foo", "abc");
    builder.child("b").setProperty(JCR_PRIMARYTYPE, "typeBar", Type.NAME).setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    // should not throw
    HOOK.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 13 with NodeState

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

the class PropertyIndexTest method testPathMismatch.

@Test
public void testPathMismatch() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    index.setProperty(createProperty(PROP_INCLUDED_PATHS, of("/test/a"), Type.STRINGS));
    index.setProperty(createProperty(PROP_EXCLUDED_PATHS, of("/test/a/b"), Type.STRINGS));
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("test").child("a").setProperty("foo", "abc");
    builder.child("test").child("a").child("b").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    f.restrictPath("/test2", Filter.PathRestriction.ALL_CHILDREN);
    PropertyIndexPlan plan = new PropertyIndexPlan("plan", root, index.getNodeState(), f);
    assertTrue(Double.POSITIVE_INFINITY == plan.getCost());
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with NodeState

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

the class S3DataStoreStats method findLeafNode.

private NodeState findLeafNode(final String nodePathName) {
    final Iterable<String> pathNodes = PathUtils.elements(PathUtils.getParentPath(nodePathName));
    final String leafNodeName = PathUtils.getName(nodePathName);
    NodeState currentNode = nodeStore.getRoot();
    for (String pathNodeName : pathNodes) {
        if (pathNodeName.length() > 0) {
            NodeState childNode = currentNode.getChildNode(pathNodeName);
            if (!childNode.exists()) {
                break;
            }
            currentNode = childNode;
        }
    }
    return currentNode.getChildNode(leafNodeName);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState)

Example 15 with NodeState

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

the class TypePredicate method isOrderable.

@Nonnull
public static TypePredicate isOrderable(@Nonnull NodeState root) {
    Set<String> orderable = newHashSet();
    NodeState types = checkNotNull(root).getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
    for (ChildNodeEntry entry : types.getChildNodeEntries()) {
        NodeState type = entry.getNodeState();
        if (type.getBoolean(JCR_HASORDERABLECHILDNODES)) {
            orderable.add(entry.getName());
        }
    }
    return new TypePredicate(root, orderable);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Nonnull(javax.annotation.Nonnull)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)779 Test (org.junit.Test)498 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)335 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)94 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)61 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)60 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)54 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)48 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)46 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)41 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)36 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)33 Nonnull (javax.annotation.Nonnull)32 Tree (org.apache.jackrabbit.oak.api.Tree)29 ArrayList (java.util.ArrayList)25 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.plugins.migration.NodeStateTestUtils.getNodeState)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)22 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)22 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)17