Search in sources :

Example 1 with Editor

use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method increment.

@Test
public void increment() throws CommitFailedException {
    NodeBuilder builder;
    Editor editor;
    builder = EMPTY_NODE.builder();
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertNoCounters(builder.getProperties());
    builder = EMPTY_NODE.builder();
    builder = setMixin(builder);
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertNull("the oak:increment should never be set", builder.getProperty(PROP_INCREMENT));
    assertTotalCountersValue(builder.getProperties(), 1);
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 2 with Editor

use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method consolidate.

@Test
public void consolidate() throws CommitFailedException {
    NodeBuilder builder;
    Editor editor;
    builder = EMPTY_NODE.builder();
    builder = setMixin(builder);
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertTotalCountersValue(builder.getProperties(), 1);
    editor.propertyAdded(INCREMENT_BY_1);
    assertTotalCountersValue(builder.getProperties(), 2);
    AtomicCounterEditor.consolidateCount(builder);
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER, PREFIX_PROP_REVISION), 2);
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 3 with Editor

use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.

the class IndexUpdate method childNodeAdded.

@Override
@Nonnull
public Editor childNodeAdded(String name, NodeState after) throws CommitFailedException {
    List<Editor> children = newArrayListWithCapacity(1 + editors.size());
    children.add(new IndexUpdate(this, name));
    for (Editor editor : editors) {
        Editor child = editor.childNodeAdded(name, after);
        if (child != null) {
            children.add(child);
        }
    }
    return compose(children);
}
Also used : Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Nonnull(javax.annotation.Nonnull)

Example 4 with Editor

use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.

the class IndexUpdate method collectIndexEditors.

private void collectIndexEditors(NodeBuilder definitions, NodeState before) throws CommitFailedException {
    for (String name : definitions.getChildNodeNames()) {
        NodeBuilder definition = definitions.getChildNode(name);
        if (isIncluded(rootState.async, definition)) {
            String type = definition.getString(TYPE_PROPERTY_NAME);
            if (type == null) {
                // probably not an index def
                continue;
            }
            boolean shouldReindex = shouldReindex(definition, before, name);
            String indexPath = getIndexPath(getPath(), name);
            if (definition.hasProperty(IndexConstants.CORRUPT_PROPERTY_NAME) && !shouldReindex) {
                String corruptSince = definition.getProperty(IndexConstants.CORRUPT_PROPERTY_NAME).getValue(Type.DATE);
                rootState.corruptIndexHandler.skippingCorruptIndex(rootState.async, indexPath, ISO8601.parse(corruptSince));
                continue;
            }
            Editor editor = rootState.provider.getIndexEditor(type, definition, rootState.root, rootState.newCallback(indexPath, shouldReindex, getEstimatedCount(definition)));
            if (editor == null) {
                rootState.missingProvider.onMissingIndex(type, definition, indexPath);
            } else if (shouldReindex) {
                if (definition.getBoolean(REINDEX_ASYNC_PROPERTY_NAME) && definition.getString(ASYNC_PROPERTY_NAME) == null) {
                    // switch index to an async update mode
                    definition.setProperty(ASYNC_PROPERTY_NAME, ASYNC_REINDEX_VALUE);
                } else {
                    definition.setProperty(REINDEX_PROPERTY_NAME, false);
                    incrementReIndexCount(definition);
                    // beforehand, we'll remove all child nodes
                    for (String rm : definition.getChildNodeNames()) {
                        if (NodeStateUtils.isHidden(rm)) {
                            definition.getChildNode(rm).remove();
                        }
                    }
                    clearCorruptFlag(definition, indexPath);
                    reindex.put(concat(getPath(), INDEX_DEFINITIONS_NAME, name), editor);
                }
            } else {
                editors.add(editor);
            }
        }
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor)

Example 5 with Editor

use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.

the class IndexUpdateTest method testMissingProviderFailsCommit.

/**
     * OAK-3505 Provide an optionally stricter policy for missing synchronous
     * index editor providers
     */
@Test
public void testMissingProviderFailsCommit() throws Exception {
    final IndexUpdateCallback noop = new IndexUpdateCallback() {

        @Override
        public void indexUpdate() {
        }
    };
    final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
    mips.setFailOnMissingIndexProvider(true);
    EditorHook hook = new EditorHook(new EditorProvider() {

        @Override
        public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
            return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
        }
    });
    NodeState before = builder.getNodeState();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
    builder.child("testRoot").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    try {
        hook.processCommit(before, after, CommitInfo.EMPTY);
        fail("commit should fail on missing index provider");
    } catch (CommitFailedException ex) {
    // expected
    }
}
Also used : MissingIndexProviderStrategy(org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Aggregations

Editor (org.apache.jackrabbit.oak.spi.commit.Editor)13 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 Test (org.junit.Test)6 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)3 IndexUpdateCallback (org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 Nonnull (javax.annotation.Nonnull)2 DocumentQueue (org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue)2 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)2 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)2 IOException (java.io.IOException)1 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)1 MissingIndexProviderStrategy (org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy)1 NodeCounterEditorProvider (org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider)1 LuceneIndexHelper.isLuceneIndexNode (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.isLuceneIndexNode)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 OrderedPropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider)1 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1 NamespaceEditorProvider (org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider)1