jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1373305 - in /jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance: DescendantSearchTest.java IndexManager.java SimpleSearchTest.java
Date Wed, 15 Aug 2012 10:11:11 GMT
Author: thomasm
Date: Wed Aug 15 10:11:11 2012
New Revision: 1373305

URL: http://svn.apache.org/viewvc?rev=1373305&view=rev
Log:
OAK-178 Query: index definition documentation and tooling

Added:
    jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
Modified:
    jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/DescendantSearchTest.java
    jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/SimpleSearchTest.java

Modified: jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/DescendantSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/DescendantSearchTest.java?rev=1373305&r1=1373304&r2=1373305&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/DescendantSearchTest.java
(original)
+++ jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/DescendantSearchTest.java
Wed Aug 15 10:11:11 2012
@@ -36,7 +36,9 @@ public class DescendantSearchTest extend
 
     protected Query createQuery(QueryManager manager, int i)
             throws RepositoryException {
-        return manager.createQuery("/jcr:root/testroot//element(*,nt:base)[@testcount=" +
i + "]", Query.XPATH);
+        @SuppressWarnings("deprecation")
+        String xpath = Query.XPATH;
+        return manager.createQuery("/jcr:root/testroot//element(*,nt:base)[@testcount=" +
i + "]", xpath);
     }
 
     @Override
@@ -52,6 +54,9 @@ public class DescendantSearchTest extend
             }
             session.save();
         }
+
+        IndexManager.createPropertyIndex(session, "testcount");
+
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java?rev=1373305&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
(added)
+++ jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/IndexManager.java
Wed Aug 15 10:11:11 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.performance;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import org.apache.jackrabbit.mk.index.Indexer;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+/**
+ * A utility class to manage indexes in Oak.
+ */
+public class IndexManager {
+
+    /**
+     * The root node of the index definition (configuration) nodes.
+     */
+    public static final String INDEX_CONFIG_PATH = Indexer.INDEX_CONFIG_PATH;
+
+    /**
+     * Creates a property index for the given property if such an index doesn't
+     * exist yet, and if the repository supports property indexes. The session
+     * may not have pending changes.
+     * 
+     * @param session the session
+     * @param propertyName the property name
+     * @return true if the index was created or already existed
+     */
+    public static boolean createPropertyIndex(Session session,
+            String propertyName) throws RepositoryException {
+        return createIndex(session, "property@" + propertyName);
+    }
+
+    private static Node getIndexNode(Session session)
+            throws RepositoryException {
+        Node n = session.getRootNode();
+        for (String e : PathUtils.elements(INDEX_CONFIG_PATH)) {
+            if (!n.hasNode(e)) {
+                return null;
+            }
+            n = n.getNode(e);
+        }
+        return n;
+    }
+
+    private static boolean createIndex(Session session, String indexNodeName)
+            throws RepositoryException {
+        if (session.hasPendingChanges()) {
+            throw new RepositoryException("The session has pending changes");
+        }
+        Node indexes = getIndexNode(session);
+        if (indexes == null) {
+            return false;
+        }
+        if (!indexes.hasNode(indexNodeName)) {
+            indexes.addNode(indexNodeName);
+            session.save();
+        }
+        return true;
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/SimpleSearchTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/SimpleSearchTest.java?rev=1373305&r1=1373304&r2=1373305&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/SimpleSearchTest.java
(original)
+++ jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/SimpleSearchTest.java
Wed Aug 15 10:11:11 2012
@@ -23,6 +23,9 @@ import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 
+/**
+ * Run a simple query of the form "//*[@testcount=...]".
+ */
 public class SimpleSearchTest extends AbstractTest {
 
     private static final int NODE_COUNT = 100;
@@ -33,7 +36,9 @@ public class SimpleSearchTest extends Ab
 
     protected Query createQuery(QueryManager manager, int i)
             throws RepositoryException {
-        return manager.createQuery("//*[@testcount=" + i + "]", Query.XPATH);
+        @SuppressWarnings("deprecation")
+        String xpath = Query.XPATH;
+        return manager.createQuery("//*[@testcount=" + i + "]", xpath);
     }
 
     @Override
@@ -49,6 +54,9 @@ public class SimpleSearchTest extends Ab
             }
             session.save();
         }
+
+        IndexManager.createPropertyIndex(session, "testcount");
+
     }
 
     @Override



Mime
View raw message