You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/04/12 16:15:27 UTC

svn commit: r161056 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: SearchManager.java search/AbstractQueryHandler.java search/QueryHandler.java search/QueryHandlerContext.java search/lucene/QueryImpl.java search/lucene/SearchIndex.java

Author: mreutegg
Date: Tue Apr 12 07:15:24 2005
New Revision: 161056

URL: http://svn.apache.org/viewcvs?view=rev&rev=161056
Log:
JCR-105: QueryHandler.init() should take a context argument

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java   (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/AbstractQueryHandler.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandler.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java?view=diff&r1=161055&r2=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java Tue Apr 12 07:15:24 2005
@@ -24,7 +24,7 @@
 import org.apache.jackrabbit.core.observation.SynchronousEventListener;
 import org.apache.jackrabbit.core.search.QueryHandler;
 import org.apache.jackrabbit.core.search.QueryImpl;
-import org.apache.jackrabbit.core.search.PropertyTypeRegistry;
+import org.apache.jackrabbit.core.search.QueryHandlerContext;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.ItemStateManager;
@@ -124,13 +124,13 @@
             nsReg.registerNamespace(NS_JCRFN_PREFIX, NS_JCRFN_URI);
         }
 
-        PropertyTypeRegistry propRegistry = new PropertyTypeRegistry(ntReg);
-        ntReg.addListener(propRegistry);
         // initialize query handler
         try {
             handler = (QueryHandler) config.newInstance();
             NodeId rootId = (NodeId) session.getHierarchyManager().resolvePath(Path.ROOT);
-            handler.init(fs, session.getItemStateManager(), rootId.getUUID(), propRegistry);
+            QueryHandlerContext context
+                    = new QueryHandlerContext(fs, itemMgr, rootId.getUUID(), ntReg);
+            handler.init(context);
         } catch (Exception e) {
             throw new RepositoryException(e.getMessage(), e);
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/AbstractQueryHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/AbstractQueryHandler.java?view=diff&r1=161055&r2=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/AbstractQueryHandler.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/AbstractQueryHandler.java Tue Apr 12 07:15:24 2005
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.core.search;
 
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.state.ItemStateManager;
-
 import java.io.IOException;
 
 /**
@@ -27,44 +24,18 @@
 public abstract class AbstractQueryHandler implements QueryHandler {
 
     /**
-     * A <code>FileSystem</code> to store the search index
-     */
-    private FileSystem fs;
-
-    /**
-     * The persistent <code>ItemStateManager</code>
+     * The context for this query handler.
      */
-    private ItemStateManager stateProvider;
-
-    /**
-     * PropertyType registry to look up the type of a property with a given name.
-     */ 
-    private PropertyTypeRegistry propRegistry;
-
-    /**
-     * The UUID of the root node.
-     */
-    private String rootUUID;
+    private QueryHandlerContext context;
 
     /**
      * Initializes this query handler by setting all properties in this class
      * with appropriate parameter values.
      *
-     * @param fs            a {@link FileSystem} this
-     *                      <code>QueryHandler</code> may use to store its index.
-     * @param stateProvider provides persistent item states.
-     * @param rootUUID the uuid of the root node.
-     * @param registry the property type registry.
+     * @param context the context for this query handler.
      */
-    public final void init(FileSystem fs, 
-                           ItemStateManager stateProvider, 
-                           String rootUUID,
-                           PropertyTypeRegistry registry)
-            throws IOException {
-        this.fs = fs;
-        this.stateProvider = stateProvider;
-        this.rootUUID = rootUUID;
-        this.propRegistry = registry;
+    public final void init(QueryHandlerContext context) throws IOException {
+        this.context = context;
         doInit();
     }
 
@@ -75,40 +46,12 @@
     protected abstract void doInit() throws IOException;
 
     /**
-     * Returns the persistent {@link ItemStateManager}
-     * of the workspace this <code>QueryHandler</code> is based on.
-     *
-     * @return the persistent <code>ItemStateProvider</code> of the current
-     *         workspace.
-     */
-    public ItemStateManager getItemStateProvider() {
-        return stateProvider;
-    }
-
-    /**
-     * Returns the {@link org.apache.jackrabbit.core.fs.FileSystem} instance
-     * this <code>QueryHandler</code> may use to store its index.
+     * Returns the context for this query handler.
      *
-     * @return the <code>FileSystem</code> instance for this
+     * @return the <code>QueryHandlerContext</code> instance for this
      *         <code>QueryHandler</code>.
      */
-    protected FileSystem getFileSystem() {
-        return fs;
-    }
-
-    /**
-     * Returns the UUID of the root node.
-     * @return the UUID of the root node.
-     */
-    protected String getRootUUID() {
-        return rootUUID;
-    }
-
-    /**
-     * Returns the PropertyTypeRegistry for this repository.
-     * @return the PropertyTypeRegistry for this repository.
-     */
-    protected PropertyTypeRegistry getPropertyTypeRegistry() {
-        return propRegistry;
+    public QueryHandlerContext getContext() {
+        return context;
     }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandler.java?view=diff&r1=161055&r2=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandler.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandler.java Tue Apr 12 07:15:24 2005
@@ -17,10 +17,8 @@
 package org.apache.jackrabbit.core.search;
 
 import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.fs.FileSystem;
 
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.RepositoryException;
@@ -38,17 +36,10 @@
      * Initializes this query handler. This method is called after the
      * <code>QueryHandler</code> is instantiated.
      *
-     * @param fs a {@link FileSystem} this
-     *  <code>QueryHandler</code> may use to store its index.
-     * @param stateProvider provides persistent item states.
-     * @param rootUUID the UUID of the root node.
-     * @param registry the property type registry.
+     * @param context the context for this query handler.
      * @throws IOException if an error occurs during initialization.
      */
-    public void init(FileSystem fs,
-                     ItemStateManager stateProvider,
-                     String rootUUID,
-                     PropertyTypeRegistry registry) throws IOException;
+    public void init(QueryHandlerContext context) throws IOException;
 
     /**
      * Adds a <code>Node</code> to the search index.

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java?view=auto&rev=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java Tue Apr 12 07:15:24 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.search;
+
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+
+/**
+ * Acts as an argument for the {@link QueryHandler} to keep the interface
+ * stable. This class provides access to the environment where the query
+ * handler is running in.
+ */
+public class QueryHandlerContext {
+    
+    /**
+     * A <code>FileSystem</code> to store the search index
+     */
+    private final FileSystem fs;
+
+    /**
+     * The persistent <code>ItemStateManager</code>
+     */
+    private final ItemStateManager stateMgr;
+
+    /**
+     * The node type registry of the repository
+     */ 
+    private final NodeTypeRegistry ntRegistry;
+
+    /**
+     * The UUID of the root node.
+     */
+    private String rootUUID;
+
+    /**
+     * PropertyType registry to look up the type of a property with a given name.
+     */ 
+    private final PropertyTypeRegistry propRegistry;
+
+    /**
+     * Creates a new context instance.
+     *
+     * @param fs         a {@link FileSystem} this <code>QueryHandler</code> may
+     *                   use to store its index.
+     * @param stateMgr   provides persistent item states.
+     * @param rootUUID   the uuid of the root node.
+     * @param ntRegistry the node type registry.
+     */
+    public QueryHandlerContext(FileSystem fs,
+                               ItemStateManager stateMgr,
+                               String rootUUID,
+                               NodeTypeRegistry ntRegistry) {
+        this.fs = fs;
+        this.stateMgr = stateMgr;
+        this.rootUUID = rootUUID;
+        this.ntRegistry = ntRegistry;
+        propRegistry = new PropertyTypeRegistry(ntRegistry);
+        ntRegistry.addListener(propRegistry);
+    }
+
+    /**
+     * Returns the persistent {@link ItemStateManager}
+     * of the workspace this <code>QueryHandler</code> is based on.
+     *
+     * @return the persistent <code>ItemStateManager</code> of the current
+     *         workspace.
+     */
+    public ItemStateManager getItemStateManager() {
+        return stateMgr;
+    }
+
+    /**
+     * Returns the {@link org.apache.jackrabbit.core.fs.FileSystem} instance
+     * this <code>QueryHandler</code> may use to store its index.
+     *
+     * @return the <code>FileSystem</code> instance for this
+     *         <code>QueryHandler</code>.
+     */
+    public FileSystem getFileSystem() {
+        return fs;
+    }
+
+    /**
+     * Returns the UUID of the root node.
+     * @return the UUID of the root node.
+     */
+    public String getRootUUID() {
+        return rootUUID;
+    }
+
+    /**
+     * Returns the PropertyTypeRegistry for this repository.
+     * @return the PropertyTypeRegistry for this repository.
+     */
+    public PropertyTypeRegistry getPropertyTypeRegistry() {
+        return propRegistry;
+    }
+
+    /**
+     * Returns the NodeTypeRegistry for this repository.
+     * @return the NodeTypeRegistry for this repository.
+     */
+    public NodeTypeRegistry getNodeTypeRegistry() {
+        return ntRegistry;
+    }
+
+    /**
+     * Destroys this context and releases resources.
+     */
+    public void destroy() {
+        ntRegistry.removeListener(propRegistry);
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryHandlerContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java?view=diff&r1=161055&r2=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/QueryImpl.java Tue Apr 12 07:15:24 2005
@@ -119,7 +119,7 @@
         }
         // build lucene query
         Query query = LuceneQueryBuilder.createQuery(root, session,
-                index.getItemStateProvider(), index.getNamespaceMappings(),
+                index.getContext().getItemStateManager(), index.getNamespaceMappings(),
                 index.getAnalyzer(), propReg);
 
         OrderQueryNode orderNode = root.getOrderNode();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java?view=diff&r1=161055&r2=161056
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java Tue Apr 12 07:15:24 2005
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.core.search.AbstractQueryHandler;
 import org.apache.jackrabbit.core.search.QueryConstants;
 import org.apache.jackrabbit.core.search.ExecutableQuery;
+import org.apache.jackrabbit.core.search.QueryHandlerContext;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.ItemManager;
@@ -78,8 +79,9 @@
      */
     protected void doInit() throws IOException {
         try {
-            index = new MultiIndex(getFileSystem(),
-                    this, getItemStateProvider(), getRootUUID());
+            QueryHandlerContext context = getContext();
+            index = new MultiIndex(context.getFileSystem(), this,
+                    context.getItemStateManager(), context.getRootUUID());
         } catch (FileSystemException e) {
             throw new IOException(e.getMessage());
         }
@@ -148,7 +150,8 @@
                                              String statement,
                                              String language)
             throws InvalidQueryException {
-        return new QueryImpl(session, itemMgr, this, getPropertyTypeRegistry(), statement, language);
+        return new QueryImpl(session, itemMgr, this,
+                getContext().getPropertyTypeRegistry(), statement, language);
     }
 
     /**
@@ -158,6 +161,7 @@
     public void close() {
         log.info("Closing search index.");
         index.close();
+        getContext().destroy();
     }
 
     /**
@@ -240,7 +244,8 @@
      */
     protected Document createDocument(NodeState node, NamespaceMappings nsMappings)
             throws RepositoryException {
-        return NodeIndexer.createDocument(node, getItemStateProvider(), nsMappings);
+        return NodeIndexer.createDocument(node, getContext().getItemStateManager(),
+                nsMappings);
     }
     
     //--------------------------< properties >----------------------------------