Index: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/package-info.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/package-info.java (revision 1831769) +++ oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/package-info.java (revision ) @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@Version("1.0.0") +@Version("1.1.0") package org.apache.jackrabbit.oak.spi.query; import org.osgi.annotation.versioning.Version; \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexService.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/IndexService.java (revision ) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexService.java (revision ) @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.oak.plugins.index; + +import javax.annotation.Nonnull; + +import org.apache.jackrabbit.oak.spi.query.QueryIndexCreator; +import org.apache.jackrabbit.oak.spi.query.QueryIndexFactory; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.osgi.service.component.annotations.Component; + +@Component(service = {QueryIndexFactory.class}) +public class IndexService implements QueryIndexFactory { + + @Override + public QueryIndexCreator getQueryIndexCreator(@Nonnull final NodeBuilder root) { + return (indexDefName, indexDescription, reindex, unique, propertyNames, declaringNodeTypeNames) -> { + NodeBuilder index = IndexUtils.getOrCreateOakIndex(root); + if (!index.hasChildNode(indexDefName)) { + IndexUtils.createIndexDefinition(index, indexDefName, indexDescription, reindex, unique, propertyNames, declaringNodeTypeNames); + } + }; + } +} \ No newline at end of file Index: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexFactory.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexFactory.java (revision ) +++ oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexFactory.java (revision ) @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.spi.query; + +import javax.annotation.Nonnull; + +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; + +public interface QueryIndexFactory { + + QueryIndexCreator getQueryIndexCreator(@Nonnull NodeBuilder builder); + +} Index: oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexCreator.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexCreator.java (revision ) +++ oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexCreator.java (revision ) @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.spi.query; + +import java.util.Collection; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface QueryIndexCreator { + + void ensureIndexDefinitionExists(@Nonnull String indexDefName, + @Nullable String indexDescription, + boolean reindex, + boolean unique, + @Nonnull Collection propertyNames, + @Nullable Collection declaringNodeTypeNames); +} Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.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/IndexUtils.java (revision 1831769) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java (revision ) @@ -16,24 +16,9 @@ */ package org.apache.jackrabbit.oak.plugins.index; -import static com.google.common.base.Preconditions.checkArgument; -import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; -import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED; -import static org.apache.jackrabbit.oak.api.Type.NAME; -import static org.apache.jackrabbit.oak.api.Type.NAMES; -import static org.apache.jackrabbit.oak.api.Type.STRING; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; -import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.UNIQUE_PROPERTY_NAME; - import java.util.Collection; import java.util.Map; import java.util.Set; - import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -48,10 +33,24 @@ import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; +import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; -import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; +import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED; +import static org.apache.jackrabbit.oak.api.Type.NAME; +import static org.apache.jackrabbit.oak.api.Type.NAMES; +import static org.apache.jackrabbit.oak.api.Type.STRING; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME; +import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.UNIQUE_PROPERTY_NAME; + /** * TODO document */ @@ -90,6 +89,16 @@ boolean unique, @Nonnull Collection propertyNames, @Nullable Collection declaringNodeTypeNames) { + return createIndexDefinition(index, indexDefName, null, reindex, unique, propertyNames, declaringNodeTypeNames); + } + + static NodeBuilder createIndexDefinition(@Nonnull NodeBuilder index, + @Nonnull String indexDefName, + @CheckForNull String indexDescription, + boolean reindex, + boolean unique, + @Nonnull Collection propertyNames, + @Nullable Collection declaringNodeTypeNames) { NodeBuilder entry = index.child(indexDefName) .setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME) .setProperty(TYPE_PROPERTY_NAME, PropertyIndexEditorProvider.TYPE) @@ -100,6 +109,9 @@ entry.setProperty(PropertyStates.createProperty(PROPERTY_NAMES, propertyNames, NAMES)); if (declaringNodeTypeNames != null && !declaringNodeTypeNames.isEmpty()) { entry.setProperty(PropertyStates.createProperty(DECLARING_NODE_TYPES, declaringNodeTypeNames, NAMES)); + } + if (indexDescription != null) { + entry.setProperty("info", indexDescription); } return entry; }