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);
}
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());
}
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");
}
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"));
}
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);
}
Aggregations