You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by al...@apache.org on 2013/04/26 09:29:56 UTC
svn commit: r1476085 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index:
./ p2/ property/
Author: alexparvulescu
Date: Fri Apr 26 07:29:56 2013
New Revision: 1476085
URL: http://svn.apache.org/r1476085
Log:
OAK-734 Refactor indexing code to use Editors - rename index type to 'property'
Removed:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexConstants.java Fri Apr 26 07:29:56 2013
@@ -49,4 +49,6 @@ public interface IndexConstants {
* allows to restrict a given index definition to specific node types.
*/
String DECLARING_NODE_TYPES = "declaringNodeTypes";
+
+ String INDEX_CONTENT_NODE_NAME = ":index";
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java Fri Apr 26 07:29:56 2013
@@ -19,12 +19,12 @@ package org.apache.jackrabbit.oak.plugin
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newArrayListWithCapacity;
-import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
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.IndexUtils.getBoolean;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getString;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
import java.util.HashMap;
@@ -72,22 +72,6 @@ class IndexUpdate implements Editor {
this.builder = parent.builder.child(checkNotNull(name));
}
- private static String getString(NodeBuilder builder, String name) {
- PropertyState property = builder.getProperty(name);
- if (property != null && property.getType() == STRING) {
- return property.getValue(STRING);
- } else {
- return null;
- }
- }
-
- private static boolean getBoolean(NodeBuilder builder, String name) {
- PropertyState property = builder.getProperty(name);
- return property != null
- && property.getType() == BOOLEAN
- && property.getValue(BOOLEAN);
- }
-
@Override
public void enter(NodeState before, NodeState after)
throws CommitFailedException {
@@ -112,7 +96,11 @@ class IndexUpdate implements Editor {
definition.setProperty(REINDEX_PROPERTY_NAME, true);
} else if (getBoolean(definition, REINDEX_PROPERTY_NAME)) {
definition.setProperty(REINDEX_PROPERTY_NAME, false);
- definition.removeChildNode(":index");
+ // as we don't know the index content node name
+ // beforehand, we'll remove all child nodes
+ for (String rm : definition.getChildNodeNames()) {
+ definition.removeChildNode(rm);
+ }
reindex.add(editor);
} else {
editors.add(VisibleEditor.wrap(editor));
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java Fri Apr 26 07:29:56 2013
@@ -181,13 +181,20 @@ public class IndexUtils {
&& ps.getValue(STRING).equals(INDEX_DEFINITIONS_NODE_TYPE);
}
- public static boolean getBoolean(NodeState state, String property, boolean def) {
- PropertyState ps = state.getProperty(property);
- if (ps == null) {
- return def;
+ public static String getString(NodeBuilder builder, String name) {
+ PropertyState property = builder.getProperty(name);
+ if (property != null && property.getType() == STRING) {
+ return property.getValue(STRING);
} else {
- return ps.getValue(BOOLEAN);
+ return null;
}
}
+ public static boolean getBoolean(NodeBuilder builder, String name) {
+ PropertyState property = builder.getProperty(name);
+ return property != null
+ && property.getType() == BOOLEAN
+ && property.getValue(BOOLEAN);
+ }
+
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java Fri Apr 26 07:29:56 2013
@@ -42,7 +42,7 @@ import com.google.common.base.Charsets;
* Next (as a child node) follows the index definition node that:
* <ul>
* <li>must be of type <code>oak:queryIndexDefinition</code></li>
- * <li>must have the <code>type</code> property set to <b><code>p2</code></b></li>
+ * <li>must have the <code>type</code> property set to <b><code>property</code></b></li>
* <li>contains the <code>propertyNames</code> property that indicates what property will be stored in the index</li>
* </ul>
* </p>
@@ -67,7 +67,7 @@ import com.google.common.base.Charsets;
* NodeBuilder index = root.child("oak:index");
* index.child("uuid")
* .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME)
- * .setProperty("type", "p2")
+ * .setProperty("type", "property")
* .setProperty("propertyNames", "jcr:uuid")
* .setProperty("declaringNodeTypes", "mix:referenceable")
* .setProperty("unique", true)
@@ -104,7 +104,7 @@ class PropertyIndex implements QueryInde
@Override
public String getIndexName() {
- return "p2";
+ return "property";
}
@Override
@@ -166,7 +166,7 @@ class PropertyIndex implements QueryInde
@Override
public String getPlan(Filter filter, NodeState root) {
- StringBuilder buff = new StringBuilder("p2");
+ StringBuilder buff = new StringBuilder("property");
PropertyIndexLookup lookup = new PropertyIndexLookup(root);
for (PropertyRestriction pr : filter.getPropertyRestrictions()) {
String propertyName = PathUtils.getName(pr.propertyName);
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java Fri Apr 26 07:29:56 2013
@@ -23,8 +23,10 @@ import static org.apache.jackrabbit.JcrC
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+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.TYPE_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider.TYPE;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
@@ -66,10 +68,6 @@ import com.google.common.collect.Lists;
*/
class PropertyIndexEditor implements IndexEditor, Closeable {
- protected static String propertyNames = "propertyNames";
-
- protected static String declaringNodeTypes = "declaringNodeTypes";
-
private final IndexStoreStrategy store = new ContentMirrorStoreStrategy();
/**
@@ -185,7 +183,7 @@ class PropertyIndexEditor implements Ind
private void addIndexes(NodeState state, String indexName) {
Set<String> primaryTypes = newHashSet();
Set<String> mixinTypes = newHashSet();
- for (String typeName : state.getNames(declaringNodeTypes)) {
+ for (String typeName : state.getNames(DECLARING_NODE_TYPES)) {
NodeState type = types.getChildNode(typeName);
if (type.getBoolean(JCR_ISMIXIN)) {
mixinTypes.add(typeName);
@@ -196,7 +194,7 @@ class PropertyIndexEditor implements Ind
addAll(mixinTypes, type.getNames(OAK_MIXIN_SUBTYPES));
}
- PropertyState ps = state.getProperty(propertyNames);
+ PropertyState ps = state.getProperty(PROPERTY_NAMES);
Iterable<String> propertyNames = ps != null ? ps.getValue(Type.NAMES)
: ImmutableList.of(indexName);
for (String pname : propertyNames) {
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditorProvider.java Fri Apr 26 07:29:56 2013
@@ -33,7 +33,7 @@ import org.apache.jackrabbit.oak.spi.sta
@Service(IndexEditorProvider.class)
public class PropertyIndexEditorProvider implements IndexEditorProvider {
- public static final String TYPE = "p2";
+ public static final String TYPE = "property";
@Override
public Editor getIndexEditor(String type, NodeBuilder builder) {
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java Fri Apr 26 07:29:56 2013
@@ -21,6 +21,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider.TYPE;
import java.util.Iterator;
@@ -150,7 +151,7 @@ public class PropertyIndexLookup {
continue;
}
if (contains(ns.getNames(PROPERTY_NAMES), propertyName)) {
- NodeState index = ns.getChildNode(":index");
+ NodeState index = ns.getChildNode(INDEX_CONTENT_NODE_NAME);
if (ns.hasProperty(DECLARING_NODE_TYPES)) {
if (supertypes != null) {
for (String typeName : ns.getNames(DECLARING_NODE_TYPES)) {
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java?rev=1476085&r1=1476084&r2=1476085&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java Fri Apr 26 07:29:56 2013
@@ -18,6 +18,9 @@ package org.apache.jackrabbit.oak.plugin
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.UNIQUE_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getBoolean;
import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndex.encode;
import java.util.Collections;
@@ -27,7 +30,6 @@ import javax.jcr.PropertyType;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy;
import org.apache.jackrabbit.oak.spi.query.PropertyValues;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -90,10 +92,8 @@ class PropertyIndexUpdate {
this.mixinTypes = mixinTypes;
}
- index = this.node.child(":index");
- PropertyState uniquePS = node.getProperty("unique");
- unique = uniquePS != null && !uniquePS.isArray()
- && uniquePS.getValue(Type.BOOLEAN);
+ index = this.node.child(INDEX_CONTENT_NODE_NAME);
+ unique = getBoolean(node, UNIQUE_PROPERTY_NAME);
}
String getPath() {