jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1330854 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit: mk/index/Indexer.java oak/api/QueryEngine.java oak/core/ContentRepositoryImpl.java oak/query/QueryEngineImpl.java oak/query/index/QueryIndexProvider.java
Date Thu, 26 Apr 2012 13:52:26 GMT
Author: thomasm
Date: Thu Apr 26 13:52:25 2012
New Revision: 1330854

URL: http://svn.apache.org/viewvc?rev=1330854&view=rev
Log:
OAK-28 Query implementation (simplify index provider)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndexProvider.java

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=1330854&r1=1330853&r2=1330854&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
Thu Apr 26 13:52:25 2012
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.query.i
 import org.apache.jackrabbit.oak.query.index.QueryIndexProvider;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -52,7 +53,6 @@ public class Indexer implements QueryInd
     private HashMap<String, BTreePage> modified = new HashMap<String, BTreePage>();
     private SimpleLRUCache<String, BTreePage> cache = SimpleLRUCache.newInstance(100);
     private String readRevision;
-    private ArrayList<QueryIndexListener> listeners = new ArrayList<QueryIndexListener>();
 
     public Indexer(MicroKernel mk, String indexRootNode) {
         this.mk = mk;
@@ -115,9 +115,6 @@ public class Indexer implements QueryInd
             return existing;
         }
         buildAndAddIndex(index);
-        for (QueryIndexListener l : listeners) {
-            l.added(new PropertyContentIndex(mk, index));
-        }
         return index;
     }
 
@@ -324,7 +321,7 @@ public class Indexer implements QueryInd
     public void updateIndex(String rootPath, JsopReader t, String lastRevision) {
         while (true) {
             int r = t.read();
-            if (r == JsopTokenizer.END) {
+            if (r == JsopReader.END) {
                 break;
             }
             String path = PathUtils.concat(rootPath, t.readString());
@@ -361,7 +358,7 @@ public class Indexer implements QueryInd
             case '^': {
                 removeProperty(path, lastRevision);
                 t.read(':');
-                if (t.matches(JsopTokenizer.NULL)) {
+                if (t.matches(JsopReader.NULL)) {
                     // ignore
                 } else {
                     String value = t.readRawValue().trim();
@@ -508,7 +505,11 @@ public class Indexer implements QueryInd
         }
     }
 
-    public List<QueryIndex> getQueryIndexes() {
+    @Override
+    public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
+        if (mk != this.mk) {
+            return Collections.emptyList();
+        }
         ArrayList<QueryIndex> list = new ArrayList<QueryIndex>();
         for (Index index : indexes.values()) {
             QueryIndex qi = null;
@@ -522,14 +523,4 @@ public class Indexer implements QueryInd
         return list;
     }
 
-    @Override
-    public void addListener(QueryIndexListener listener) {
-        listeners.add(listener);
-    }
-
-    @Override
-    public void removeListener(QueryIndexListener listener) {
-        listeners.remove(listener);
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java?rev=1330854&r1=1330853&r2=1330854&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
Thu Apr 26 13:52:25 2012
@@ -53,9 +53,4 @@ public interface QueryEngine {
      */
     Result executeQuery(String statement, String language, Map<String, CoreValue> bindings)
throws ParseException;
 
-    /**
-     * Close the query engine.
-     */
-    void close();
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1330854&r1=1330853&r2=1330854&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Thu Apr 26 13:52:25 2012
@@ -69,7 +69,7 @@ public class ContentRepositoryImpl imple
         // FIXME: workspace setup must be done elsewhere...
         queryEngine.init();
         NodeState root = nodeStore.getRoot();
-        
+
         NodeState wspNode = root.getChildNode(DEFAULT_WORKSPACE_NAME);
         if (wspNode == null) {
             microKernel.commit("/", "+\"" + DEFAULT_WORKSPACE_NAME + "\":{}" + "^\"" + DEFAULT_WORKSPACE_NAME
+ "/jcr:primaryType\":\"nt:unstructured\" ", null, null);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1330854&r1=1330853&r2=1330854&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Thu Apr 26 13:52:25 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.query;
 
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.index.Indexer;
 import org.apache.jackrabbit.oak.api.CoreValue;
@@ -23,18 +27,9 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.query.index.Filter;
 import org.apache.jackrabbit.oak.query.index.QueryIndex;
-import org.apache.jackrabbit.oak.query.index.QueryIndexProvider.QueryIndexListener;
 import org.apache.jackrabbit.oak.query.index.TraversingIndex;
 
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-public class QueryEngineImpl implements QueryEngine, QueryIndexListener {
+public class QueryEngineImpl implements QueryEngine {
 
     static final String SQL2 = "JCR-SQL2";
     private static final String XPATH = "xpath";
@@ -46,8 +41,6 @@ public class QueryEngineImpl implements 
     private final CoreValueFactory vf;
     private final SQL2Parser parserSQL2;
     private final Indexer indexer;
-    private final Map<String, QueryIndex> indexes =
-        Collections.synchronizedMap(new HashMap<String, QueryIndex>());
 
     public QueryEngineImpl(MicroKernel mk, CoreValueFactory valueFactory) {
         this.mk = mk;
@@ -60,11 +53,6 @@ public class QueryEngineImpl implements 
     public void init() {
         // TODO the list of index providers should be configurable as well
         indexer.init();
-        indexer.addListener(this);
-        List<QueryIndex> list = indexer.getQueryIndexes();
-        for (QueryIndex qi : list) {
-            indexes.put(qi.getIndexName(), qi);
-        }
     }
 
     /**
@@ -125,23 +113,7 @@ public class QueryEngineImpl implements 
     }
 
     private List<QueryIndex> getIndexes() {
-        // create a copy, so the underlying map can be modified
-        return new ArrayList<QueryIndex>(indexes.values());
-    }
-
-    @Override
-    public void added(QueryIndex index) {
-        indexes.put(index.getIndexName(), index);
-    }
-
-    @Override
-    public void removed(QueryIndex index) {
-        indexes.remove(index.getIndexName());
-    }
-
-    @Override
-    public void close() {
-        indexer.removeListener(this);
+        return indexer.getQueryIndexes(mk);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndexProvider.java?rev=1330854&r1=1330853&r2=1330854&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndexProvider.java
Thu Apr 26 13:52:25 2012
@@ -19,6 +19,7 @@
 package org.apache.jackrabbit.oak.query.index;
 
 import java.util.List;
+import org.apache.jackrabbit.mk.api.MicroKernel;
 
 /**
  * A mechanism to index data. Indexes might be added or removed at runtime,
@@ -34,45 +35,11 @@ public interface QueryIndexProvider {
     void init();
 
     /**
-     * Get the currently configured indexes.
+     * Get the currently configured indexes for the given MicroKernel instance.
      *
+     * @param mk the MicroKernel instance
      * @return the list of indexes
      */
-    List<QueryIndex> getQueryIndexes();
-
-    /**
-     * Add a listener that is notified about added and removed indexes.
-     *
-     * @param listener the listener
-     */
-    void addListener(QueryIndexListener listener);
-
-    /**
-     * Remove a listener.
-     *
-     * @param listener the listener
-     */
-    void removeListener(QueryIndexListener listener);
-
-    /**
-     * A query index listener
-     */
-    interface QueryIndexListener {
-
-        /**
-         * The given index was added.
-         *
-         * @param index the index
-         */
-        void added(QueryIndex index);
-
-        /**
-         * The given index was removed.
-         *
-         * @param index the index
-         */
-        void removed(QueryIndex index);
-
-    }
+    List<QueryIndex> getQueryIndexes(MicroKernel mk);
 
 }



Mime
View raw message