use of org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy in project jackrabbit-oak by apache.
the class ReferenceEditor method update.
private void update(Set<IndexStoreStrategy> refStores, NodeBuilder definition, String name, String key, Set<String> add, Set<String> rm) throws CommitFailedException {
for (IndexStoreStrategy store : refStores) {
Set<String> empty = of();
for (String p : rm) {
Supplier<NodeBuilder> index = memoize(() -> definition.child(store.getIndexNodeName()));
store.update(index, p, name, definition, of(key), empty);
}
for (String p : add) {
// TODO do we still need to encode the values?
Supplier<NodeBuilder> index = memoize(() -> definition.child(store.getIndexNodeName()));
store.update(index, p, name, definition, empty, of(key));
}
}
}
use of org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy in project jackrabbit-oak by apache.
the class PropertyIndexEditor method updateIndex.
private void updateIndex(NodeState before, NodeState after) throws CommitFailedException {
// if any changes were detected, update the index accordingly
if (beforeKeys != null || afterKeys != null) {
// first make sure that both the before and after sets are non-null
if (beforeKeys == null || (typePredicate != null && !typePredicate.apply(before))) {
beforeKeys = newHashSet();
} else if (afterKeys == null) {
afterKeys = newHashSet();
} else {
// both before and after matches found, remove duplicates
Set<String> sharedKeys = newHashSet(beforeKeys);
sharedKeys.retainAll(afterKeys);
beforeKeys.removeAll(sharedKeys);
afterKeys.removeAll(sharedKeys);
}
if (!beforeKeys.isEmpty() || !afterKeys.isEmpty()) {
updateCallback.indexUpdate();
String properties = definition.getString(PROPERTY_NAMES);
boolean uniqueIndex = keysToCheckForUniqueness != null;
for (IndexStoreStrategy strategy : getStrategies(uniqueIndex)) {
Supplier<NodeBuilder> index = memoize(() -> definition.child(strategy.getIndexNodeName()));
if (uniqueIndex) {
keysToCheckForUniqueness.addAll(getExistingKeys(afterKeys, index, strategy));
}
strategy.update(index, getPath(), properties, definition, beforeKeys, afterKeys);
}
}
}
checkUniquenessConstraints();
}
use of org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy in project jackrabbit-oak by apache.
the class PropertyIndexPlan method execute.
Cursor execute() {
QueryLimits settings = filter.getQueryLimits();
List<Iterable<String>> iterables = Lists.newArrayList();
for (IndexStoreStrategy s : strategies) {
iterables.add(s.query(filter, name, definition, values));
}
Cursor cursor = Cursors.newPathCursor(Iterables.concat(iterables), settings);
if (depth > 1) {
cursor = Cursors.newAncestorCursor(cursor, depth - 1, settings);
}
return cursor;
}
use of org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy in project jackrabbit-oak by apache.
the class PropertyIndexLookup method query.
public Iterable<String> query(Filter filter, String propertyName, PropertyValue value) {
NodeState indexMeta = getIndexNode(root, propertyName, filter);
if (indexMeta == null) {
throw new IllegalArgumentException("No index for " + propertyName);
}
List<Iterable<String>> iterables = Lists.newArrayList();
ValuePattern pattern = new ValuePattern(indexMeta);
for (IndexStoreStrategy s : getStrategies(indexMeta)) {
iterables.add(s.query(filter, propertyName, indexMeta, encode(value, pattern)));
}
return Iterables.concat(iterables);
}
use of org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy in project jackrabbit-oak by apache.
the class PropertyIndexLookup method getCost.
public double getCost(Filter filter, String propertyName, PropertyValue value) {
NodeState indexMeta = getIndexNode(root, propertyName, filter);
if (indexMeta == null) {
return Double.POSITIVE_INFINITY;
}
Set<IndexStoreStrategy> strategies = getStrategies(indexMeta);
ValuePattern pattern = new ValuePattern(indexMeta);
double cost = strategies.isEmpty() ? MAX_COST : COST_OVERHEAD;
for (IndexStoreStrategy s : strategies) {
cost += s.count(filter, root, indexMeta, encode(value, pattern), MAX_COST);
}
return cost;
}
Aggregations