Search in sources :

Example 46 with EditorHook

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

the class VersionHook method processCommit.

@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
    Set<String> existingVersionables = newHashSet();
    List<EditorProvider> providers = newArrayList();
    providers.add(new VersionEditorProvider());
    providers.add(new VersionableCollector.Provider(existingVersionables));
    providers.add(new OrphanedVersionCleaner.Provider(existingVersionables));
    return compose(transform(providers, new Function<EditorProvider, CommitHook>() {

        @Nullable
        @Override
        public CommitHook apply(@Nullable EditorProvider input) {
            return new EditorHook(input);
        }
    })).processCommit(before, after, info);
}
Also used : CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Example 47 with EditorHook

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

the class IndexUpdateTest method shouldNotReindexAsyncIndexInSyncMode.

@Test
public void shouldNotReindexAsyncIndexInSyncMode() throws Exception {
    String indexPath = "/oak:index/rootIndex";
    CallbackCapturingProvider provider = new CallbackCapturingProvider();
    IndexUpdateProvider indexUpdate = new IndexUpdateProvider(provider);
    EditorHook hook = new EditorHook(indexUpdate);
    NodeState before = builder.getNodeState();
    NodeBuilder idx = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    idx.setProperty("async", asList("async", "sync"), Type.STRINGS);
    builder.child("a").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    assertFalse(provider.getContext(indexPath).isReindexing());
}
Also used : 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) Test(org.junit.Test)

Example 48 with EditorHook

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

the class NodeTypeIndexTest method nodeType.

@Test
public void nodeType() throws Exception {
    NodeBuilder root = store.getRoot().builder();
    // remove "rep:security" as it interferes with tests
    root.getChildNode("rep:security").remove();
    // set "entryCount", so the node type index counts the nodes
    // and the approximation is not used
    root.getChildNode("oak:index").getChildNode("nodetype").setProperty("entryCount", -1);
    addFolder(root, "folder-1");
    addFolder(root, "folder-2");
    addFile(root, "file-1");
    store.merge(root, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider())), CommitInfo.EMPTY);
    NodeState rootState = store.getRoot();
    NodeTypeIndex index = new NodeTypeIndex(Mounts.defaultMountInfoProvider());
    FilterImpl filter;
    filter = createFilter(rootState, JcrConstants.NT_FOLDER);
    assertEquals(6.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2");
    filter = createFilter(rootState, JcrConstants.NT_FILE);
    assertEquals(5.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/file-1");
    filter = createFilter(rootState, JcrConstants.NT_HIERARCHYNODE);
    assertEquals(7.0, index.getCost(filter, rootState), 0.0);
    checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2", "/file-1");
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 49 with EditorHook

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

the class ReferenceIndexTest method referenceHandlingWithMounts.

@Test
public void referenceHandlingWithMounts() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").child("x").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    builder.child("c").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE));
    builder.child("d").setProperty(createProperty("foo", "u2", Type.WEAKREFERENCE));
    builder.child("a").child("y").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE));
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a").build();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider().with(mip)));
    ReferenceIndex referenceIndex = new ReferenceIndex(mip);
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    f.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.REFERENCE);
    // System.out.println(NodeStateUtils.toString(NodeStateUtils.getNode(indexed, "/oak:index/reference")));
    assertFilter(f, referenceIndex, indexed, of("/a/x", "/b"));
    FilterImpl f2 = createFilter(indexed, NT_BASE);
    f2.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.WEAKREFERENCE);
    assertFilter(f2, referenceIndex, indexed, of("/c", "/a/y"));
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) 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)

Example 50 with EditorHook

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

the class ReferenceIndexTest method removeWeaklyReferencedNode.

@Test
public void removeWeaklyReferencedNode() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(createProperty(JCR_UUID, "u1", Type.STRING));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE));
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = indexed.builder();
    builder.getChildNode("a").remove();
    hook.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)69 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)46 Test (org.junit.Test)44 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)43 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)11 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)11 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)11 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)11 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)8 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)7 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)7 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)7 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)6 Before (org.junit.Before)6