Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java (revision 5b49262a4030f903c927ff912a9d58e6d8b29ca2) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java (revision ) @@ -40,6 +40,7 @@ import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.IndexEditor; import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback; +import org.apache.jackrabbit.oak.plugins.index.PathFilter; import org.apache.jackrabbit.oak.plugins.index.property.strategy.ContentMirrorStoreStrategy; import org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy; import org.apache.jackrabbit.oak.plugins.index.property.strategy.UniqueEntryStoreStrategy; @@ -107,12 +108,18 @@ private final IndexUpdateCallback updateCallback; + private final PathFilter pathFilter; + + private final PathFilter.Result pathFilterResult; + public PropertyIndexEditor(NodeBuilder definition, NodeState root, IndexUpdateCallback updateCallback) { this.parent = null; this.name = null; this.path = "/"; this.definition = definition; + pathFilter = PathFilter.from(definition); + pathFilterResult = getPathFilterResult(); //initPropertyNames(definition); @@ -143,7 +150,7 @@ this.updateCallback = updateCallback; } - PropertyIndexEditor(PropertyIndexEditor parent, String name) { + PropertyIndexEditor(PropertyIndexEditor parent, String name, PathFilter.Result pathFilterResult) { this.parent = parent; this.name = name; this.path = null; @@ -152,6 +159,8 @@ this.typePredicate = parent.typePredicate; this.keysToCheckForUniqueness = parent.keysToCheckForUniqueness; this.updateCallback = parent.updateCallback; + this.pathFilter = parent.pathFilter; + this.pathFilterResult = pathFilterResult; } /** @@ -223,53 +232,56 @@ @Override public void leave(NodeState before, NodeState after) throws CommitFailedException { + + if (pathFilterResult == PathFilter.Result.INCLUDE) { - // apply the type restrictions - if (typePredicate != null) { - if (typeChanged) { - // possible type change, so ignore diff results and - // just load all matching values from both states - beforeKeys = getMatchingKeys(before, getPropertyNames()); - afterKeys = getMatchingKeys(after, getPropertyNames()); - } - if (beforeKeys != null && !typePredicate.apply(before)) { - // the before state doesn't match the type, so clear its values - beforeKeys = null; - } - if (afterKeys != null && !typePredicate.apply(after)) { - // the after state doesn't match the type, so clear its values - afterKeys = null; - } - } + // apply the type restrictions + if (typePredicate != null) { + if (typeChanged) { + // possible type change, so ignore diff results and + // just load all matching values from both states + beforeKeys = getMatchingKeys(before, getPropertyNames()); + afterKeys = getMatchingKeys(after, getPropertyNames()); + } + if (beforeKeys != null && !typePredicate.apply(before)) { + // the before state doesn't match the type, so clear its values + beforeKeys = null; + } + if (afterKeys != null && !typePredicate.apply(after)) { + // the after state doesn't match the type, so clear its values + afterKeys = null; + } + } - // 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 sharedKeys = newHashSet(beforeKeys); - sharedKeys.retainAll(afterKeys); - beforeKeys.removeAll(sharedKeys); - afterKeys.removeAll(sharedKeys); - } + // 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 sharedKeys = newHashSet(beforeKeys); + sharedKeys.retainAll(afterKeys); + beforeKeys.removeAll(sharedKeys); + afterKeys.removeAll(sharedKeys); + } - if (!beforeKeys.isEmpty() || !afterKeys.isEmpty()) { - updateCallback.indexUpdate(); - NodeBuilder index = definition.child(INDEX_CONTENT_NODE_NAME); - String properties = definition.getString(PROPERTY_NAMES); - boolean uniqueIndex = keysToCheckForUniqueness != null; - if (uniqueIndex) { - keysToCheckForUniqueness.addAll( - getExistingKeys(afterKeys, index)); - } - getStrategy(uniqueIndex).update( - index, getPath(), beforeKeys, afterKeys); - } - } + if (!beforeKeys.isEmpty() || !afterKeys.isEmpty()) { + updateCallback.indexUpdate(); + NodeBuilder index = definition.child(INDEX_CONTENT_NODE_NAME); + String properties = definition.getString(PROPERTY_NAMES); + boolean uniqueIndex = keysToCheckForUniqueness != null; + if (uniqueIndex) { + keysToCheckForUniqueness.addAll( + getExistingKeys(afterKeys, index)); + } + getStrategy(uniqueIndex).update( + index, getPath(), beforeKeys, afterKeys); + } + } + } if (parent == null) { // make sure that the index node exist, even with no content @@ -372,24 +384,43 @@ * @param name the name of the child node * @return an instance of the PropertyIndexEditor */ - PropertyIndexEditor getChildIndexEditor(@Nonnull PropertyIndexEditor parent, @Nonnull String name) { - return new PropertyIndexEditor(parent, name); + PropertyIndexEditor getChildIndexEditor(@Nonnull PropertyIndexEditor parent, @Nonnull String name, PathFilter.Result filterResult) { + return new PropertyIndexEditor(parent, name, filterResult); } @Override public Editor childNodeAdded(String name, NodeState after) { - return getChildIndexEditor(this, name); + PathFilter.Result filterResult = getPathFilterResult(name); + if (filterResult != PathFilter.Result.EXCLUDE) { + return getChildIndexEditor(this, name, filterResult); - } + } + return null; + } @Override public Editor childNodeChanged( String name, NodeState before, NodeState after) { - return getChildIndexEditor(this, name); + PathFilter.Result filterResult = getPathFilterResult(name); + if (filterResult != PathFilter.Result.EXCLUDE) { + return getChildIndexEditor(this, name, filterResult); - } + } + return null; + } @Override public Editor childNodeDeleted(String name, NodeState before) { - return getChildIndexEditor(this, name); + PathFilter.Result filterResult = getPathFilterResult(name); + if (filterResult == PathFilter.Result.EXCLUDE) { + return null; - } + } + return getChildIndexEditor(this, name, filterResult); + } + private PathFilter.Result getPathFilterResult() { + return pathFilter.doFiler(getPath()); + } + + private PathFilter.Result getPathFilterResult(String childNodeName) { + return pathFilter.doFiler(concat(getPath(), childNodeName)); + } } \ No newline at end of file