jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1381217 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/plugins/index/ main/java/org/apache/jackrabbit/oak/spi/query/ test/java/org/apache/jackrabbit/oak/plugins/lucene...
Date Wed, 05 Sep 2012 15:09:55 GMT
Author: alexparvulescu
Date: Wed Sep  5 15:09:54 2012
New Revision: 1381217

URL: http://svn.apache.org/viewvc?rev=1381217&view=rev
Log:
OAK-269 Query: IndexManager to manage existing indexes

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
  (with props)
Modified:
    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/plugins/index/PropertyIndexFactory.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java

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=1381217&r1=1381216&r2=1381217&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
Wed Sep  5 15:09:54 2012
@@ -29,7 +29,6 @@ import org.apache.jackrabbit.mk.core.Mic
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
-import org.apache.jackrabbit.oak.plugins.index.Indexer;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.security.authentication.LoginContextProviderImpl;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
@@ -37,6 +36,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.authentication.LoginContextProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
@@ -65,10 +65,9 @@ public class ContentRepositoryImpl imple
      * test cases only.
      */
     public ContentRepositoryImpl() {
-        this(new MicroKernelImpl(), null, new ValidatingHook(
-                new CompositeValidatorProvider(
+        this(new MicroKernelImpl(), new CompositeQueryIndexProvider(),
+                new ValidatingHook(new CompositeValidatorProvider(
                         Collections.<ValidatorProvider> emptyList())));
-        // this(new IndexWrapper(new MicroKernelImpl()), null, null);
     }
 
     /**
@@ -112,7 +111,8 @@ public class ContentRepositoryImpl imple
         nodeStore = new KernelNodeStore(microKernel);
         nodeStore.setHook(commitHook);
 
-        QueryIndexProvider qip = (indexProvider == null) ? getDefaultIndexProvider(microKernel)
: indexProvider;
+        QueryIndexProvider qip = indexProvider != null ? indexProvider
+                : new CompositeQueryIndexProvider();
         queryEngine = new QueryEngineImpl(nodeStore, microKernel, qip);
 
         // TODO: use configurable context provider
@@ -135,10 +135,6 @@ public class ContentRepositoryImpl imple
         }
     }
 
-    private static QueryIndexProvider getDefaultIndexProvider(MicroKernel mk) {
-        return Indexer.getInstance(mk);
-    }
-
     @Nonnull
     @Override
     public ContentSession login(Credentials credentials, String workspaceName)

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java?rev=1381217&r1=1381216&r2=1381217&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexFactory.java
Wed Sep  5 15:09:54 2012
@@ -45,7 +45,7 @@ public class PropertyIndexFactory implem
 
     @Override
     public void init(MicroKernel mk) {
-        this.indexer = new Indexer(mk);
+        this.indexer = Indexer.getInstance(mk);
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java?rev=1381217&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
Wed Sep  5 15:09:54 2012
@@ -0,0 +1,61 @@
+/*
+ * 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.spi.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.spi.QueryIndex;
+import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
+
+/**
+ * This {@code QueryIndexProvider} aggregates a list of query index providers
+ * into a single query index provider.
+ */
+public class CompositeQueryIndexProvider implements QueryIndexProvider {
+
+    private final Collection<QueryIndexProvider> providers = new CopyOnWriteArrayList<QueryIndexProvider>();
+
+    public CompositeQueryIndexProvider(QueryIndexProvider... providers) {
+        add(providers);
+    }
+
+    public void add(QueryIndexProvider... provider) {
+        if (provider == null) {
+            return;
+        }
+        for (QueryIndexProvider qip : provider) {
+            providers.add(qip);
+        }
+    }
+
+    @Override
+    public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
+        List<QueryIndex> indexes = new ArrayList<QueryIndex>();
+        for (QueryIndexProvider qip : providers) {
+            List<QueryIndex> t = qip.getQueryIndexes(mk);
+            if (t != null) {
+                indexes.addAll(t);
+            }
+        }
+        return indexes;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java?rev=1381217&r1=1381216&r2=1381217&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
Wed Sep  5 15:09:54 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.lucene;
 
+import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.DEFAULT_INDEX_NAME;
+import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.createIndexNode;
+import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
+
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
@@ -39,20 +43,18 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.type.DefaultTypeEditor;
 import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.value.ConflictValidatorProvider;
+import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.IndexManager;
 import org.apache.jackrabbit.oak.spi.query.IndexManagerImpl;
 import org.apache.jackrabbit.oak.spi.query.IndexUtils;
 import org.junit.Before;
 
-import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.DEFAULT_INDEX_NAME;
-import static org.apache.jackrabbit.oak.plugins.lucene.LuceneIndexUtils.createIndexNode;
-import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
-
 /**
  * base class for lucene search tests
  */
@@ -83,8 +85,9 @@ public abstract class AbstractLuceneQuer
     @Override
     protected ContentRepository createRepository() {
         mk = new MicroKernelImpl();
-        return new ContentRepositoryImpl(mk, new LuceneIndexProvider(
-                DEFAULT_INDEX_HOME), buildDefaultCommitHook());
+        QueryIndexProvider indexer = new LuceneIndexProvider(DEFAULT_INDEX_HOME);
+        QueryIndexProvider qip = new CompositeQueryIndexProvider(indexer);
+        return new ContentRepositoryImpl(mk, qip, buildDefaultCommitHook());
     }
 
     private CommitHook buildDefaultCommitHook() {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1381217&r1=1381216&r2=1381217&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
Wed Sep  5 15:09:54 2012
@@ -18,35 +18,46 @@ package org.apache.jackrabbit.oak.query;
 
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.index.IndexWrapper;
+import org.apache.jackrabbit.oak.AbstractOakTest;
+import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
-import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
-
-import javax.jcr.GuestCredentials;
+import org.apache.jackrabbit.oak.plugins.index.PropertyIndexFactory;
+import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.query.IndexManager;
+import org.apache.jackrabbit.oak.spi.query.IndexManagerImpl;
+import org.apache.jackrabbit.oak.spi.query.IndexUtils;
+import org.junit.Before;
 
 /**
  * AbstractQueryTest...
  */
-public abstract class AbstractQueryTest {
+public abstract class AbstractQueryTest extends AbstractOakTest {
 
-    protected final IndexWrapper mk;
-    protected final ContentRepositoryImpl rep;
-    protected final CoreValueFactory vf;
-    protected final SessionQueryEngine qe;
-    protected final ContentSession session;
+    protected IndexWrapper mk;
+    protected CoreValueFactory vf;
+    protected SessionQueryEngine qe;
+    protected ContentSession session;
 
-    {
+    @Override
+    protected ContentRepository createRepository() {
         mk = new IndexWrapper(new MicroKernelImpl());
-        rep = new ContentRepositoryImpl(mk, null, (ValidatorProvider) null);
-        try {
-            session = rep.login(new GuestCredentials(), "default");
-            vf = session.getCoreValueFactory();
-            qe = session.getQueryEngine();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        QueryIndexProvider indexer = mk.getIndexer();
+        QueryIndexProvider qip = new CompositeQueryIndexProvider(indexer);
+        IndexManager im = new IndexManagerImpl(IndexUtils.DEFAULT_INDEX_HOME,
+                mk, new PropertyIndexFactory());
+        return new ContentRepositoryImpl(mk, qip, im);
+    }
+
+    @Before
+    public void before() throws Exception {
+        super.before();
+        session = createAdminSession();
+        vf = session.getCoreValueFactory();
+        qe = session.getQueryEngine();
     }
 
 }
\ No newline at end of file



Mime
View raw message