jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1349882 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/index/ test/java/org/apache/jackrabbit/mk/index/
Date Wed, 13 Jun 2012 14:42:23 GMT
Author: thomasm
Date: Wed Jun 13 14:42:22 2012
New Revision: 1349882

URL: http://svn.apache.org/viewvc?rev=1349882&view=rev
Log:
OAK-137 Query: content index (simplify the API a bit)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1349882&r1=1349881&r2=1349882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
Wed Jun 13 14:42:22 2012
@@ -39,7 +39,7 @@ public class IndexWrapper extends MicroK
 
     public IndexWrapper(MicroKernel mk) {
         this.mk = MicroKernelWrapperBase.wrap(mk);
-        this.indexer = new Indexer(this, mk, Indexer.INDEX_CONFIG_ROOT);
+        this.indexer = new Indexer(mk);
         indexer.init();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1349882&r1=1349881&r2=1349882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Wed Jun 13 14:42:22 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk.index;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -30,7 +31,6 @@ import org.apache.jackrabbit.oak.spi.Que
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -63,9 +63,8 @@ public class Indexer implements QueryInd
     private static final boolean DISABLED = Boolean.getBoolean("mk.indexDisabled");
 
     private MicroKernel mk;
-    private MicroKernel mkWrapper;
     private String revision;
-    private String indexRootNode;
+    private String indexRootNode = INDEX_CONFIG_ROOT;
     private int indexRootNodeDepth;
     private StringBuilder buffer;
     private ArrayList<QueryIndex> queryIndexList;
@@ -89,18 +88,25 @@ public class Indexer implements QueryInd
      */
     private final HashMap<String, PropertyIndex> propertyIndexes = new HashMap<String,
PropertyIndex>();
 
-    public Indexer(MicroKernel mkWrapper, MicroKernel mk, String indexRootNode) {
-        this.mkWrapper = mkWrapper;
-        if (mkWrapper instanceof IndexWrapper) {
-            this.mk = ((IndexWrapper) mkWrapper).getBaseKernel();
-        } else {
-            this.mk = mk;
-        }
-        this.indexRootNode = indexRootNode;
+    Indexer(MicroKernel mk) {
+        this.mk = mk;
     }
 
-    public Indexer(MicroKernel mk) {
-        this(mk, mk, INDEX_CONFIG_ROOT);
+    /**
+     * Get the indexer for the given MicroKernel. This will either create a new instance,
+     * or (if the MicroKernel is an IndexWrapper), return the existing indexer.
+     *
+     * @param mk the MicroKernel instance
+     * @return an indexer
+     */
+    public static Indexer getInstance(MicroKernel mk) {
+        if (mk instanceof IndexWrapper) {
+            Indexer indexer = ((IndexWrapper) mk).getIndexer();
+            if (indexer != null) {
+                return indexer;
+            }
+        }
+        return new Indexer(mk);
     }
 
     public String getIndexRootNode() {
@@ -371,7 +377,18 @@ public class Indexer implements QueryInd
         JsopBuilder jsop = new JsopBuilder();
         jsop.tag('^').key("rev").value(readRevision);
         buffer(jsop.toString());
-        commitChanges();
+        try {
+            commitChanges();
+        } catch (MicroKernelException e) {
+            if (!mk.nodeExists(indexRootNode, revision)) {
+                // the index node itself was removed, which is
+                // unexpected but possible - re-create it
+                init = false;
+                init();
+            } else {
+                throw e;
+            }
+        }
         return revision;
     }
 
@@ -619,15 +636,12 @@ public class Indexer implements QueryInd
     @Override
     public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
         init();
-        if (mk != this.mkWrapper) {
-            return Collections.emptyList();
-        }
         if (queryIndexList == null) {
             queryIndexList = new ArrayList<QueryIndex>();
             for (Index index : indexes.values()) {
                 QueryIndex qi = null;
                 if (index instanceof PropertyIndex) {
-                    qi = new PropertyContentIndex(mk, (PropertyIndex) index);
+                    qi = new PropertyContentIndex((PropertyIndex) index);
                 } else if (index instanceof PrefixIndex) {
                     // TODO support prefix indexes?
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java?rev=1349882&r1=1349881&r2=1349882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Wed Jun 13 14:42:22 2012
@@ -30,11 +30,14 @@ import org.junit.Test;
 public class IndexTest {
 
     private final MicroKernel mk = new MicroKernelImpl();
+    private final Indexer indexer = Indexer.getInstance(mk);
+
+    {
+        indexer.init();
+    }
 
     @Test
     public void createIndexAfterAddingData() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         PropertyIndex indexOld = indexer.createPropertyIndex("x", false);
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 1 }, \"id\": 1 }", mk.getHeadRevision(),
"");
         mk.commit("/", "+ \"test3\": { \"test2\": { \"id\": 2 }, \"id\": 2 }", mk.getHeadRevision(),
"");
@@ -50,8 +53,6 @@ public class IndexTest {
 
     @Test
     public void nonUnique() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", false);
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 1 }, \"id\": 1 }", mk.getHeadRevision(),
"");
         mk.commit("/", "+ \"test3\": { \"test2\": { \"id\": 2 }, \"id\": 2 }", mk.getHeadRevision(),
"");
@@ -65,8 +66,6 @@ public class IndexTest {
 
     @Test
     public void nestedAddNode() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", true);
 
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
@@ -76,8 +75,6 @@ public class IndexTest {
 
     @Test
     public void move() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", true);
 
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
@@ -91,8 +88,6 @@ public class IndexTest {
 
     @Test
     public void copy() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", false);
 
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
@@ -116,8 +111,6 @@ public class IndexTest {
 
     @Test
     public void ascending() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         BTree tree = new BTree(indexer, "test", true);
         tree.setMinSize(2);
         print(mk, tree);
@@ -159,8 +152,6 @@ public class IndexTest {
     }
 
     private void duplicateKey(boolean unique) {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         BTree tree = new BTree(indexer, "test", unique);
         tree.setMinSize(2);
 
@@ -203,8 +194,6 @@ public class IndexTest {
 
     @Test
     public void random() {
-        Indexer indexer = new Indexer(mk);
-        indexer.init();
         BTree tree = new BTree(indexer, "test", true);
         tree.setMinSize(2);
         Random r = new Random(1);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java?rev=1349882&r1=1349881&r2=1349882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
Wed Jun 13 14:42:22 2012
@@ -30,14 +30,14 @@ public class PrefixIndexTest {
     @Test
     public void test() {
         MicroKernel mk = new MicroKernelImpl();
-        Indexer indexer = new Indexer(mk, mk, "index");
+        Indexer indexer = Indexer.getInstance(mk);
         indexer.init();
         PrefixIndex index = indexer.createPrefixIndex("d:");
 
         String head = mk.getHeadRevision();
 
         // meta data
-        String meta = mk.getNodes("/index", head, 1, 0, -1, null);
+        String meta = mk.getNodes(Indexer.INDEX_CONFIG_ROOT, head, 1, 0, -1, null);
         Assert.assertEquals("{\":childNodeCount\":1,\"prefix@d:\":{\":childNodeCount\":0}}",
meta);
 
         Assert.assertEquals("", getPathList(index, "d:1", head));

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java?rev=1349882&r1=1349881&r2=1349882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
Wed Jun 13 14:42:22 2012
@@ -29,14 +29,14 @@ public class PropertyIndexTest {
     @Test
     public void test() {
         MicroKernel mk = new MicroKernelImpl();
-        Indexer indexer = new Indexer(mk, mk, "index");
+        Indexer indexer = Indexer.getInstance(mk);
         indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", true);
 
         String head = mk.getHeadRevision();
 
         // meta data
-        String meta = mk.getNodes("/index", head, 1, 0, -1, null);
+        String meta = mk.getNodes(Indexer.INDEX_CONFIG_ROOT, head, 1, 0, -1, null);
         Assert.assertEquals("{\":childNodeCount\":1,\"property@id,unique\":{\":childNodeCount\":0}}",
meta);
 
         String oldHead = head;
@@ -61,7 +61,7 @@ public class PropertyIndexTest {
         Assert.assertEquals("/test/test", index.getPath("3", head));
 
         // Recreate the indexer
-        indexer = new Indexer(mk);
+        indexer = Indexer.getInstance(mk);
         indexer.init();
         index = indexer.createPropertyIndex("id", true);
         head = mk.getHeadRevision();



Mime
View raw message