Search in sources :

Example 1 with IndexStoreStrategy

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));
        }
    }
}
Also used : IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 2 with IndexStoreStrategy

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();
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Set(java.util.Set) IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 3 with IndexStoreStrategy

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;
}
Also used : QueryLimits(org.apache.jackrabbit.oak.spi.query.QueryLimits) IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 4 with IndexStoreStrategy

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);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy)

Example 5 with IndexStoreStrategy

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;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy)

Aggregations

IndexStoreStrategy (org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 FilteringIndexStoreStrategy (org.apache.jackrabbit.oak.plugins.index.property.strategy.FilteringIndexStoreStrategy)1 Mount (org.apache.jackrabbit.oak.spi.mount.Mount)1 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)1 QueryLimits (org.apache.jackrabbit.oak.spi.query.QueryLimits)1