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/05/16 12:08:43 UTC

svn commit: r1483285 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property: PropertyIndexEditor.java PropertyIndexUpdate.java

Author: alexparvulescu
Date: Thu May 16 10:08:42 2013
New Revision: 1483285

URL: http://svn.apache.org/r1483285
Log:
OAK-734 Refactor indexing code to use Editors

Modified:
    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/PropertyIndexUpdate.java

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=1483285&r1=1483284&r2=1483285&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 Thu May 16 10:08:42 2013
@@ -30,6 +30,8 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.OAK_MIXIN_SUBTYPES;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.OAK_PRIMARY_SUBTYPES;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.isIndexNodeType;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getChildOrNull;
 
 import java.io.Closeable;
 import java.io.IOException;
@@ -43,7 +45,6 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
-import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 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.memory.EmptyNodeState;
@@ -52,7 +53,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 
 /**
  * {@link IndexEditor} implementation that is responsible for keeping the
@@ -88,7 +88,7 @@ class PropertyIndexEditor implements Ind
      */
     private String path;
 
-    private final List<PropertyIndexUpdate> updates = Lists.newArrayList();
+    private final boolean isRoot;
 
     /**
      * The map of known indexes. Key: the property name. Value: the list of
@@ -103,19 +103,20 @@ class PropertyIndexEditor implements Ind
     private final NodeState types;
 
     public PropertyIndexEditor(NodeBuilder builder) {
-        this(null, builder, null, "/");
+        this(null, builder, null, "/", true);
     }
 
     private PropertyIndexEditor(PropertyIndexEditor parent, String nodeName) {
-        this(parent, IndexUtils.getChildOrNull(parent.node, nodeName), nodeName, null);
+        this(parent, getChildOrNull(parent.node, nodeName), nodeName, null, false);
     }
 
     private PropertyIndexEditor(PropertyIndexEditor parent, NodeBuilder node,
-            String nodeName, String path) {
+            String nodeName, String path, boolean root) {
         this.parent = parent;
         this.node = node;
         this.nodeName = nodeName;
         this.path = path;
+        this.isRoot = root;
 
         if (parent == null) {
             this.indexMap = new HashMap<String, List<PropertyIndexUpdate>>();
@@ -206,7 +207,6 @@ class PropertyIndexEditor implements Ind
                         getPath(), node.child(INDEX_DEFINITIONS_NAME).child(indexName),
                         store, primaryTypes, mixinTypes);
                 list.add(update);
-                updates.add(update);
             }
         }
     }
@@ -218,7 +218,7 @@ class PropertyIndexEditor implements Ind
             NodeState index = after.getChildNode(INDEX_DEFINITIONS_NAME);
             for (String indexName : index.getChildNodeNames()) {
                 NodeState child = index.getChildNode(indexName);
-                if (IndexUtils.isIndexNodeType(child, TYPE)) {
+                if (isIndexNodeType(child, TYPE)) {
                     addIndexes(child, indexName);
                 }
             }
@@ -228,8 +228,12 @@ class PropertyIndexEditor implements Ind
     @Override
     public void leave(NodeState before, NodeState after)
             throws CommitFailedException {
-        for (PropertyIndexUpdate update : updates) {
-            update.checkUniqueKeys();
+        if (isRoot) {
+            for (List<PropertyIndexUpdate> updates : indexMap.values()) {
+                for (PropertyIndexUpdate update : updates) {
+                    update.checkUniqueKeys();
+                }
+            }
         }
     }
 

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=1483285&r1=1483284&r2=1483285&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 Thu May 16 10:08:42 2013
@@ -64,11 +64,6 @@ class PropertyIndexUpdate {
     private final Set<String> mixinTypes;
 
     /**
-     * The node where the index definition is stored.
-     */
-    private final NodeBuilder node;
-
-    /**
      * The node where the index content is stored.
      */
     private final NodeBuilder index;
@@ -81,7 +76,6 @@ class PropertyIndexUpdate {
             String path, NodeBuilder node, IndexStoreStrategy store,
             Set<String> primaryTypes, Set<String> mixinTypes) {
         this.path = path;
-        this.node = node;
         this.store = store;
 
         if (primaryTypes.isEmpty() && mixinTypes.isEmpty()) {
@@ -92,7 +86,7 @@ class PropertyIndexUpdate {
             this.mixinTypes = mixinTypes;
         }
 
-        index = this.node.child(INDEX_CONTENT_NODE_NAME);
+        index = node.child(INDEX_CONTENT_NODE_NAME);
         unique = getBoolean(node, UNIQUE_PROPERTY_NAME);
     }