Search in sources :

Example 36 with NodeBuilder

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

the class PropertyIndexTest method testPathAwarePropertyLookup.

@Test
public void testPathAwarePropertyLookup() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty("foo", "abc");
    builder.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("/a", Filter.PathRestriction.ALL_CHILDREN);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "abc", f));
}
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 37 with NodeBuilder

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

the class PropertyIndexTest method testPathInclude.

@Test
public void testPathInclude() 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));
    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("b").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("test/a"), find(lookup, "foo", "abc", f));
}
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 38 with NodeBuilder

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

the class PropertyIndexTest method testUniqueByTypeKO.

@Test(expected = CommitFailedException.class)
public void testUniqueByTypeKO() 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, "typeFoo", Type.NAME).setProperty("foo", "abc");
    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 39 with NodeBuilder

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

the class PropertyIndexTest method createTestData.

private NodeState createTestData(int entryCount) throws CommitFailedException {
    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);
    // disable the estimation
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    int depth = ContentMirrorStoreStrategy.TRAVERSING_WARN / entryCount + 10;
    for (int i = 0; i < entryCount; i++) {
        NodeBuilder parentNode = builder.child("n" + i);
        for (int j = 0; j < depth; j++) {
            parentNode = parentNode.child("c" + j);
        }
        parentNode.setProperty("foo", "bar");
    }
    NodeState after = builder.getNodeState();
    return 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)

Example 40 with NodeBuilder

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

the class PropertyIndexTest method mountAndUniqueIndexes.

@Test(expected = CommitFailedException.class)
public void mountAndUniqueIndexes() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, true, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a").build();
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip)));
    // should throw
    hook.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20