Search in sources :

Example 1 with NodeBuilder

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

the class InitialContent method createInitialContent.

private static NodeState createInitialContent() {
    NodeBuilder builder = EMPTY_NODE.builder();
    new InitialContent().initialize(builder);
    return squeeze(builder.getNodeState());
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 2 with NodeBuilder

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

the class OakInitializer method initialize.

public static void initialize(@Nonnull NodeStore store, @Nonnull RepositoryInitializer initializer, @Nonnull IndexEditorProvider indexEditor) {
    try {
        NodeBuilder builder = store.getRoot().builder();
        initializer.initialize(builder);
        store.merge(builder, createHook(indexEditor), createCommitInfo());
    } catch (CommitFailedException e) {
        throw new RuntimeException(e);
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 3 with NodeBuilder

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

the class PropertyIndexTest method testUpdateUnique.

@Test
public void testUpdateUnique() throws Exception {
    NodeState root = EMPTY_NODE;
    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");
    NodeState after = builder.getNodeState();
    NodeState done = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // remove, and then re-add the same node
    builder = done.builder();
    builder.child("a").setProperty("foo", "abc");
    after = builder.getNodeState();
    // apply the changes to the state before adding the entries
    done = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // re-apply the changes
    done = HOOK.processCommit(done, 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 4 with NodeBuilder

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

the class PropertyIndexTest method valuePattern.

@Test
public void valuePattern() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definitions
    NodeBuilder builder = root.builder();
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder indexDef = createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo"), null);
    indexDef.setProperty(IndexConstants.VALUE_PATTERN, "(a.*|b)");
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a");
    builder.child("a1").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a1");
    builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "b");
    builder.child("c").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "c");
    NodeState after = builder.getNodeState();
    // Add an index
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(after, NT_UNSTRUCTURED);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    PropertyIndex pIndex = new PropertyIndex(Mounts.defaultMountInfoProvider());
    assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "a", f));
    assertEquals(ImmutableSet.of("a1"), find(lookup, "foo", "a1", f));
    assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "b", f));
    // expected: no index for "is not null"
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("c"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value c
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    f = createFilter(after, NT_UNSTRUCTURED);
    list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("a"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value a
    assertTrue(pIndex.getCost(f, indexed) < Double.POSITIVE_INFINITY);
}
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) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 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)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1190 Test (org.junit.Test)849 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)338 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)96 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)82 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)80 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)77 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)75 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)73 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)69 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)64 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)61 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)43 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)40 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)38 Blob (org.apache.jackrabbit.oak.api.Blob)36 ArrayList (java.util.ArrayList)29 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)28 Nonnull (javax.annotation.Nonnull)26