jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1437984 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins: index/IndexUtils.java nodetype/write/InitialContent.java
Date Thu, 24 Jan 2013 12:57:48 GMT
Author: angela
Date: Thu Jan 24 12:57:48 2013
New Revision: 1437984

URL: http://svn.apache.org/viewvc?rev=1437984&view=rev
Log:
simplify property index setup

Modified:
    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/nodetype/write/InitialContent.java

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=1437984&r1=1437983&r2=1437984&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
Thu Jan 24 12:57:48 2013
@@ -21,10 +21,15 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 
@@ -33,6 +38,48 @@ import static org.apache.jackrabbit.oak.
  */
 public class IndexUtils implements IndexConstants {
 
+    public static NodeBuilder getOrCreateOakIndex(NodeBuilder root) {
+        NodeBuilder index;
+        if (!root.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
+            index = root.child(IndexConstants.INDEX_DEFINITIONS_NAME);
+            // TODO: use property node type name
+            index.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
+        } else {
+            index = root.child(IndexConstants.INDEX_DEFINITIONS_NAME);
+        }
+        return index;
+    }
+
+    /**
+     * Create a new property2 index definition below the given {@code indexNode}.
+     *
+     * @param index The oak:index node builder
+     * @param indexDefName The name of the new property index.
+     * @param reindex {@code true} if the the reindex flag should be turned on.
+     * @param unique {@code true} if the index is expected the assert property
+     * uniqueness.
+     * @param propertyNames The property names that should be indexed.
+     */
+    public static void createIndexDefinition(NodeBuilder index,
+                                             String indexDefName,
+                                             boolean reindex,
+                                             boolean unique,
+                                             List<String> propertyNames) {
+        NodeBuilder entry = index.child(indexDefName)
+                .setProperty(JCR_PRIMARYTYPE, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE,
Type.NAME)
+                .setProperty(IndexConstants.TYPE_PROPERTY_NAME, "p2")
+                .setProperty(IndexConstants.REINDEX_PROPERTY_NAME, reindex);
+        if (unique) {
+            entry.setProperty(IndexConstants.UNIQUE_PROPERTY_NAME, unique);
+        }
+        // FIXME OAK-583
+        if (propertyNames.size() == 1) {
+            entry.setProperty(IndexConstants.PROPERTY_NAMES, propertyNames.get(0));
+        } else {
+            entry.setProperty(PropertyStates.createProperty(IndexConstants.PROPERTY_NAMES,
propertyNames, Type.STRINGS));
+        }
+    }
+
     /**
      * Create a new property2 index definition below the given {@code indexNode}.
      *

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java?rev=1437984&r1=1437983&r2=1437984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
Thu Jan 24 12:57:48 2013
@@ -21,7 +21,8 @@ import org.apache.felix.scr.annotations.
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.core.RootImpl;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -32,8 +33,8 @@ import com.google.common.collect.Immutab
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
 import static org.apache.jackrabbit.JcrConstants.JCR_VERSIONSTORAGE;
-import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 
 /**
  * {@code InitialContent} implements a {@link RepositoryInitializer} and
@@ -62,23 +63,12 @@ public class InitialContent implements R
                 .setProperty(JCR_PRIMARYTYPE, "rep:Activities", Type.NAME);
         }
 
-        if (!root.hasChildNode("oak:index")) {
-            NodeBuilder index = root.child("oak:index");
-            index.setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME); // TODO: use
proper node type
-            index.child("uuid")
-                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
-                .setProperty("type", "p2")
-                .setProperty("propertyNames", "jcr:uuid")
-                .setProperty("reindex", true)
-                .setProperty("unique", true);
-            index.child("nodetype")
-                .setProperty(JCR_PRIMARYTYPE, "oak:queryIndexDefinition", Type.NAME)
-                .setProperty("type", "p2")
-                .setProperty("reindex", true)
-                .setProperty(PropertyStates.createProperty(
-                        "propertyNames",
-                        ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES),
-                        Type.STRINGS));
+        if (!root.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
+            NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
+
+            IndexUtils.createIndexDefinition(index, "uuid", true, true, ImmutableList.<String>of(JCR_UUID));
+            IndexUtils.createIndexDefinition(index, "nodetype", true, false,
+                    ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES));
         }
         try {
             branch.setRoot(root.getNodeState());



Mime
View raw message