jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r816678 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/config/ main/java/org/apache/jackrabbit/core/query/ main/java/org/apache/jackrabbit/core/query/lucene/ test/java/...
Date Fri, 18 Sep 2009 15:43:58 GMT
Author: jukka
Date: Fri Sep 18 15:43:57 2009
New Revision: 816678

URL: http://svn.apache.org/viewvc?rev=816678&view=rev
Log:
JCR-1438: Replace Config classes with factories

Replace SearchConfig with a QueryHandlerFactory.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Fri Sep 18 15:43:57 2009
@@ -665,9 +665,9 @@
     private SearchManager getSystemSearchManager(String wspName)
             throws RepositoryException {
         if (systemSearchMgr == null) {
-            if (repConfig.getSearchConfig() != null) {
+            if (repConfig.isSearchEnabled()) {
                 systemSearchMgr = new SearchManager(
-                        repConfig.getSearchConfig(), nsReg, ntReg,
+                        repConfig, nsReg, ntReg,
                         getWorkspaceInfo(wspName).itemStateMgr,
                         vMgr.getPersistenceManager(), SYSTEM_ROOT_NODE_ID,
                         null, null, executor);
@@ -1833,13 +1833,9 @@
 
             synchronized (this) {
                 if (searchMgr == null) {
-                    if (config.getSearchConfig() == null) {
-                        // no search index configured
-                        return null;
-                    }
                     // search manager is lazily instantiated in order to avoid
                     // 'chicken & egg' bootstrap problems
-                    searchMgr = new SearchManager(config.getSearchConfig(),
+                    searchMgr = new SearchManager(config,
                             nsReg, ntReg, itemStateMgr, persistMgr, rootNodeId,
                             getSystemSearchManager(getName()),
                             SYSTEM_ROOT_NODE_ID, executor);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Fri Sep 18 15:43:57 2009
@@ -37,7 +37,6 @@
 
 import org.apache.jackrabbit.core.config.SearchConfig;
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.observation.EventImpl;
@@ -46,6 +45,7 @@
 import org.apache.jackrabbit.core.query.AbstractQueryImpl;
 import org.apache.jackrabbit.core.query.QueryHandler;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
+import org.apache.jackrabbit.core.query.QueryHandlerFactory;
 import org.apache.jackrabbit.core.query.QueryObjectModelImpl;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
@@ -85,36 +85,11 @@
     public static final String NS_XS_URI = "http://www.w3.org/2001/XMLSchema";
 
     /**
-     * The search configuration.
-     */
-    private final SearchConfig config;
-
-    /**
-     * The node type registry.
-     */
-    private final NodeTypeRegistry ntReg;
-
-    /**
      * The shared item state manager instance for the workspace.
      */
     private final SharedItemStateManager itemMgr;
 
     /**
-     * The underlying persistence manager.
-     */
-    private final PersistenceManager pm;
-
-    /**
-     * Storage for search index
-     */
-    private final FileSystem fs;
-
-    /**
-     * The root node for this search manager.
-     */
-    private final NodeId rootNodeId;
-
-    /**
      * QueryHandler where query execution is delegated to
      */
     private QueryHandler handler;
@@ -131,22 +106,11 @@
     private final NamespaceRegistryImpl nsReg;
 
     /**
-     * ID of the node that should be excluded from indexing or <code>null</code>
-     * if no node should be excluded.
-     */
-    private final NodeId excludedNodeId;
-
-    /**
      * Path that will be excluded from indexing.
      */
     private Path excludePath;
 
     /**
-     * Background task executor.
-     */
-    private final Executor executor;
-
-    /**
      * Creates a new <code>SearchManager</code>.
      *
      * @param config         the search configuration.
@@ -162,7 +126,7 @@
      *                       excluded from indexing.
      * @throws RepositoryException if the search manager cannot be initialized
      */
-    public SearchManager(SearchConfig config,
+    public SearchManager(QueryHandlerFactory qhf,
                          final NamespaceRegistryImpl nsReg,
                          NodeTypeRegistry ntReg,
                          SharedItemStateManager itemMgr,
@@ -171,16 +135,9 @@
                          SearchManager parentMgr,
                          NodeId excludedNodeId,
                          Executor executor) throws RepositoryException {
-        this.fs = config.getFileSystem();
-        this.config = config;
-        this.ntReg = ntReg;
         this.nsReg = nsReg;
         this.itemMgr = itemMgr;
-        this.pm = pm;
-        this.rootNodeId = rootNodeId;
         this.parentHandler = (parentMgr != null) ? parentMgr.handler : null;
-        this.excludedNodeId = excludedNodeId;
-        this.executor = executor;
 
         // register namespaces
         safeRegisterNamespace(NS_XS_PREFIX, NS_XS_URI);
@@ -213,7 +170,9 @@
         }
 
         // initialize query handler
-        initializeQueryHandler();
+        this.handler = qhf.getQueryHandler(new QueryHandlerContext(
+                itemMgr, pm, rootNodeId, ntReg, nsReg,
+                parentHandler, excludedNodeId, executor));
     }
 
     /**
@@ -260,14 +219,8 @@
     public void close() {
         try {
             shutdownQueryHandler();
-
-            if (fs != null) {
-                fs.close();
-            }
         } catch (IOException e) {
             log.error("Exception closing QueryHandler.", e);
-        } catch (FileSystemException e) {
-            log.error("Exception closing FileSystem.", e);
         }
     }
 
@@ -505,24 +458,6 @@
     //------------------------< internal >--------------------------------------
 
     /**
-     * Initializes the query handler.
-     *
-     * @throws RepositoryException if the query handler cannot be initialized.
-     */
-    private void initializeQueryHandler() throws RepositoryException {
-        // initialize query handler
-        try {
-            handler = (QueryHandler) config.newInstance();
-            QueryHandlerContext context = new QueryHandlerContext(
-                    fs, itemMgr, pm, rootNodeId, ntReg, nsReg,
-                    parentHandler, excludedNodeId, executor);
-            handler.init(context);
-        } catch (Exception e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-    }
-
-    /**
      * Shuts down the query handler. If the query handler is already shut down
      * this method does nothing.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Fri Sep 18 15:43:57 2009
@@ -24,6 +24,9 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
 import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
+import org.apache.jackrabbit.core.query.QueryHandler;
+import org.apache.jackrabbit.core.query.QueryHandlerContext;
+import org.apache.jackrabbit.core.query.QueryHandlerFactory;
 import org.apache.jackrabbit.core.util.RepositoryLockMechanism;
 import org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory;
 import org.slf4j.Logger;
@@ -69,7 +72,8 @@
  * addition the workspace configuration object keeps track of all configured
  * workspaces.
  */
-public class RepositoryConfig implements FileSystemFactory, DataStoreFactory {
+public class RepositoryConfig
+        implements FileSystemFactory, DataStoreFactory, QueryHandlerFactory {
 
     /** the default logger */
     private static Logger log = LoggerFactory.getLogger(RepositoryConfig.class);
@@ -325,9 +329,9 @@
     private final VersioningConfig vc;
 
     /**
-     * Optional search configuration for system search manager.
+     * Query handler factory, or <code>null</code> if not configured.
      */
-    private final SearchConfig sc;
+    private final QueryHandlerFactory qhf;
 
     /**
      * Optional cluster configuration.
@@ -356,7 +360,7 @@
      * @param workspaceMaxIdleTime maximum workspace idle time in seconds
      * @param template workspace configuration template
      * @param vc versioning configuration
-     * @param sc search configuration for system search manager.
+     * @param qhf query handler factory for the system search manager
      * @param cc optional cluster configuration
      * @param dsf data store factory
      * @param parser configuration parser
@@ -365,7 +369,7 @@
             String home, SecurityConfig sec, FileSystemFactory fsf,
             String workspaceDirectory, String workspaceConfigDirectory,
             String defaultWorkspace, int workspaceMaxIdleTime,
-            Element template, VersioningConfig vc, SearchConfig sc,
+            Element template, VersioningConfig vc, QueryHandlerFactory qhf,
             ClusterConfig cc, DataStoreFactory dsf,
             RepositoryLockMechanismFactory rlf,
             RepositoryConfigurationParser parser) {
@@ -379,7 +383,7 @@
         this.defaultWorkspace = defaultWorkspace;
         this.template = template;
         this.vc = vc;
-        this.sc = sc;
+        this.qhf = qhf;
         this.cc = cc;
         this.dsf = dsf;
         this.rlf = rlf;
@@ -878,13 +882,28 @@
     }
 
     /**
-     * Returns the system search index configuration. Returns
-     * <code>null</code> if no search index has been configured.
+     * Checks whether search configuration is present.
      *
-     * @return search index configuration, or <code>null</code>
+     * @return <code>true</code> if search is configured,
+     *         <code>false</code> otherwise
      */
-    public SearchConfig getSearchConfig() {
-        return sc;
+    public boolean isSearchEnabled() {
+        return qhf != null;
+    }
+
+    /**
+     * Returns the initialized query handler, or <code>null</code> if one
+     * has not been configured.
+     *
+     * @return initialized query handler, or <code>null</code>
+     */
+    public QueryHandler getQueryHandler(QueryHandlerContext context)
+            throws RepositoryException {
+        if (qhf != null) {
+            return qhf.getQueryHandler(context);
+        } else {
+            return null;
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
Fri Sep 18 15:43:57 2009
@@ -27,6 +27,9 @@
 import org.apache.jackrabbit.core.journal.Journal;
 import org.apache.jackrabbit.core.journal.JournalException;
 import org.apache.jackrabbit.core.journal.JournalFactory;
+import org.apache.jackrabbit.core.query.QueryHandler;
+import org.apache.jackrabbit.core.query.QueryHandlerContext;
+import org.apache.jackrabbit.core.query.QueryHandlerFactory;
 import org.apache.jackrabbit.core.state.DefaultISMLocking;
 import org.apache.jackrabbit.core.state.ISMLocking;
 import org.apache.jackrabbit.core.state.ISMLockingFactory;
@@ -275,8 +278,8 @@
         // Versioning configuration
         VersioningConfig vc = parseVersioningConfig(root);
 
-        // Optional search configuration
-        SearchConfig sc = parseSearchConfig(root);
+        // Query handler implementation
+        QueryHandlerFactory qhf = getQueryHandlerFactory(root);
 
         // Optional journal configuration
         ClusterConfig cc = parseClusterConfig(root, new File(home));
@@ -288,7 +291,7 @@
 
         return new RepositoryConfig(home, securityConfig, fsf,
                 workspaceDirectory, workspaceConfigDirectory, defaultWorkspace,
-                maxIdleTime, template, vc, sc, cc, dsf, rlf, this);
+                maxIdleTime, template, vc, qhf, cc, dsf, rlf, this);
     }
 
     /**
@@ -483,8 +486,8 @@
         // Persistence manager implementation
         PersistenceManagerConfig pmc = tmpParser.parsePersistenceManagerConfig(root);
 
-        // Search implementation (optional)
-        SearchConfig sc = tmpParser.parseSearchConfig(root);
+        // Query handler implementation
+        QueryHandlerFactory qhf = tmpParser.getQueryHandlerFactory(root);
 
         // Item state manager locking configuration (optional)
         ISMLockingFactory ismLockingFactory =
@@ -494,7 +497,7 @@
         WorkspaceSecurityConfig workspaceSecurityConfig = tmpParser.parseWorkspaceSecurityConfig(root);
 
         return new WorkspaceConfig(
-                home, name, clustered, fsf, pmc, sc,
+                home, name, clustered, fsf, pmc, qhf,
                 ismLockingFactory, workspaceSecurityConfig);
     }
 
@@ -522,32 +525,43 @@
      * However some implementations may require a FileSystem.
      *
      * @param parent parent of the <code>SearchIndex</code> element
-     * @return search configuration, or <code>null</code>
-     * @throws ConfigurationException if the configuration is broken
+     * @return query handler factory
      */
-    protected SearchConfig parseSearchConfig(Element parent)
-            throws ConfigurationException {
+    protected QueryHandlerFactory getQueryHandlerFactory(final Element parent) {
         NodeList children = parent.getChildNodes();
         for (int i = 0; i < children.getLength(); i++) {
-            Node child = children.item(i);
+            final Node child = children.item(i);
             if (child.getNodeType() == Node.ELEMENT_NODE
                     && SEARCH_INDEX_ELEMENT.equals(child.getNodeName())) {
-                Element element = (Element) child;
-
-                // Search implementation class
-                String className = getAttribute(
-                        element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
-
-                // Search parameters
-                Properties parameters = parseParameters(element);
-
-                // Optional file system implementation
-                FileSystemFactory fsf = null;
-                if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) {
-                    fsf = getFileSystemFactory(element, FILE_SYSTEM_ELEMENT);
-                }
+                return new QueryHandlerFactory() {
+                    public QueryHandler getQueryHandler(QueryHandlerContext context)
+                            throws RepositoryException {
+                        Element element = (Element) child;
+
+                        // Optional file system implementation
+                        FileSystem fs = null;
+                        if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) {
+                            fs = getFileSystemFactory(
+                                    element, FILE_SYSTEM_ELEMENT).getFileSystem();
+                        }
 
-                return new SearchConfig(className, parameters, fsf);
+                        // Search implementation class
+                        String className = getAttribute(
+                                element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
+                        BeanConfig config = new BeanConfig(
+                                className, parseParameters(element));
+
+                        QueryHandler handler =
+                            (QueryHandler) config.newInstance();
+                        try {
+                            handler.init(fs, context);
+                            return handler;
+                        } catch (IOException e) {
+                            throw new RepositoryException(
+                                    "Unable to initialize query handler: " + handler, e);
+                        }
+                    }
+                };
             }
         }
         return null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
Fri Sep 18 15:43:57 2009
@@ -20,6 +20,9 @@
 
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
+import org.apache.jackrabbit.core.query.QueryHandler;
+import org.apache.jackrabbit.core.query.QueryHandlerContext;
+import org.apache.jackrabbit.core.query.QueryHandlerFactory;
 import org.apache.jackrabbit.core.state.ISMLocking;
 import org.apache.jackrabbit.core.state.ISMLockingFactory;
 
@@ -32,7 +35,8 @@
  * the item state manager locking configuration. The search index and the item
  * state manager locking and the security config are optional parts.
  */
-public class WorkspaceConfig implements FileSystemFactory, ISMLockingFactory {
+public class WorkspaceConfig
+        implements FileSystemFactory, ISMLockingFactory, QueryHandlerFactory {
 
     /**
      * Workspace home directory.
@@ -60,9 +64,9 @@
     private PersistenceManagerConfig pmc;
 
     /**
-     * Workspace search index configuration. Can be <code>null</code>.
+     * Query handler factory, or <code>null</code> if search is not configured.
      */
-    private SearchConfig sc;
+    private QueryHandlerFactory qhf;
 
     /**
      * The item state manager locking factory.
@@ -82,20 +86,21 @@
      * @param clustered
      * @param fsf file system factory
      * @param pmc persistence manager configuration
-     * @param sc search index configuration
+     * @param qhf query handler factory, or <code>null</code> if not configured
      * @param ismLockingFactory the item state manager locking factory
      * @param workspaceSecurityConfig the workspace specific security configuration.
      */
     public WorkspaceConfig(String home, String name, boolean clustered,
                            FileSystemFactory fsf, PersistenceManagerConfig pmc,
-                           SearchConfig sc, ISMLockingFactory ismLockingFactory,
+                           QueryHandlerFactory qhf,
+                           ISMLockingFactory ismLockingFactory,
                            WorkspaceSecurityConfig workspaceSecurityConfig) {
         this.home = home;
         this.name = name;
         this.clustered = clustered;
         this.fsf = fsf;
         this.pmc = pmc;
-        this.sc = sc;
+        this.qhf = qhf;
         this.ismLockingFactory = ismLockingFactory;
         this.workspaceSecurityConfig = workspaceSecurityConfig;
     }
@@ -158,13 +163,28 @@
     }
 
     /**
-     * Returns the workspace search index configuration. Returns
-     * <code>null</code> if a search index has not been configured.
+     * Checks whether search configuration is present.
      *
-     * @return search index configuration, or <code>null</code>
+     * @return <code>true</code> if search is configured,
+     *         <code>false</code> otherwise
+     */
+    public boolean isSearchEnabled() {
+        return qhf != null;
+    }
+
+    /**
+     * Returns an initialized query handler, or <code>null</code> if one
+     * was not configured.
+     *
+     * @return initialized query handler, or <code>null</code>
      */
-    public SearchConfig getSearchConfig() {
-        return sc;
+    public QueryHandler getQueryHandler(QueryHandlerContext context)
+            throws RepositoryException {
+        if (qhf != null) {
+            return qhf.getQueryHandler(context);
+        } else {
+            return null;
+        }
     }
     /**
      * @return workspace-specific security settings.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
Fri Sep 18 15:43:57 2009
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import org.apache.commons.io.IOExceptionWithCause;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.slf4j.Logger;
@@ -36,6 +39,11 @@
     private static final Logger log = LoggerFactory.getLogger(AbstractQueryHandler.class);
 
     /**
+     * Search index file system, or <code>null</code>
+     */
+    protected FileSystem fs;
+
+    /**
      * The context for this query handler.
      */
     private QueryHandlerContext context;
@@ -60,13 +68,27 @@
      * Initializes this query handler by setting all properties in this class
      * with appropriate parameter values.
      *
+     * @param fs search index file system, or <code>null</code>
      * @param context the context for this query handler.
      */
-    public final void init(QueryHandlerContext context) throws IOException {
+    public final void init(FileSystem fs, QueryHandlerContext context)
+            throws IOException {
+        this.fs = fs;
         this.context = context;
         doInit();
     }
 
+    public void close() throws IOException {
+        if (fs != null) {
+            try {
+                fs.close();
+            } catch (FileSystemException e) {
+                throw new IOExceptionWithCause(
+                        "Unable to close search index file system: " + fs, e);
+            }
+        }
+    }
+
     /**
      * This method must be implemented by concrete sub classes and will be
      * called from {@link #init}.
@@ -172,5 +194,5 @@
     public String getIdleTime() {
         return idleTime;
     }
-        
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
Fri Sep 18 15:43:57 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
@@ -39,11 +40,16 @@
     /**
      * Initializes this query handler. This method is called after the
      * <code>QueryHandler</code> is instantiated.
+     * <p>
+     * If a file system has been configured (i.e. the fs argument is not
+     * <code>null</code>), then the query handler is expected to close
+     * the given file system when the {@link #close()} method is called.
      *
+     * @param fs the configured search index file system, or <code>null</code>
      * @param context the context for this query handler.
      * @throws IOException if an error occurs during initialization.
      */
-    void init(QueryHandlerContext context) throws IOException;
+    void init(FileSystem fs, QueryHandlerContext context) throws IOException;
 
     /**
      * Returns the query handler context that passed in {@link

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
Fri Sep 18 15:43:57 2009
@@ -18,15 +18,14 @@
 
 import java.util.concurrent.Executor;
 
-import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.CachingHierarchyManager;
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.NamespaceRegistryImpl;
+import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.NamespaceRegistryImpl;
-import org.apache.jackrabbit.core.HierarchyManager;
-import org.apache.jackrabbit.core.CachingHierarchyManager;
-import org.apache.jackrabbit.core.persistence.PersistenceManager;
 
 /**
  * Acts as an argument for the {@link QueryHandler} to keep the interface
@@ -36,11 +35,6 @@
 public class QueryHandlerContext {
 
     /**
-     * A <code>FileSystem</code> to store the search index
-     */
-    private final FileSystem fs;
-
-    /**
      * The persistent <code>ItemStateManager</code>
      */
     private final SharedItemStateManager stateMgr;
@@ -93,10 +87,6 @@
     /**
      * Creates a new context instance.
      *
-     * @param fs               a {@link FileSystem} this <code>QueryHandler</code>
-     *                         may use to store its index. If no
-     *                         <code>FileSystem</code> has been configured
-     *                         <code>fs</code> is <code>null</code>.
      * @param stateMgr         provides persistent item states.
      * @param pm               the underlying persistence manager.
      * @param rootId           the id of the root node.
@@ -109,8 +99,7 @@
      *                         excluded from indexing.
      * @param executor         background task executor
      */
-    public QueryHandlerContext(FileSystem fs,
-                               SharedItemStateManager stateMgr,
+    public QueryHandlerContext(SharedItemStateManager stateMgr,
                                PersistenceManager pm,
                                NodeId rootId,
                                NodeTypeRegistry ntRegistry,
@@ -118,7 +107,6 @@
                                QueryHandler parentHandler,
                                NodeId excludedNodeId,
                                Executor executor) {
-        this.fs = fs;
         this.stateMgr = stateMgr;
         this.hmgr = new CachingHierarchyManager(rootId, stateMgr);
         this.stateMgr.addListener(hmgr);
@@ -162,18 +150,6 @@
     }
 
     /**
-     * Returns the {@link FileSystem} instance this <code>QueryHandler</code>
-     * may use to store its index. If no <code>FileSystem</code> has been
-     * configured this method returns <code>null</code>.
-     *
-     * @return the <code>FileSystem</code> instance for this
-     *         <code>QueryHandler</code>.
-     */
-    public FileSystem getFileSystem() {
-        return fs;
-    }
-
-    /**
      * Returns the id of the root node.
      * @return the idof the root node.
      */

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java?rev=816678&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java
Fri Sep 18 15:43:57 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.core.query;
+
+import javax.jcr.RepositoryException;
+
+public interface QueryHandlerFactory {
+
+    QueryHandler getQueryHandler(QueryHandlerContext context)
+        throws RepositoryException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Fri Sep 18 15:43:57 2009
@@ -768,7 +768,7 @@
      * Closes this <code>QueryHandler</code> and frees resources attached
      * to this handler.
      */
-    public void close() {
+    public void close() throws IOException {
         if (synonymProviderConfigFs != null) {
             try {
                 synonymProviderConfigFs.close();
@@ -781,6 +781,7 @@
         }
         index.close();
         getContext().destroy();
+        super.close();
         closed = true;
         log.info("Index closed: " + path);
     }
@@ -1229,7 +1230,6 @@
                         "Invalid synonymProviderConfigPath: "
                         + synonymProviderConfigPath);
             }
-            FileSystem fs = getContext().getFileSystem();
             if (fs == null) {
                 fs = new LocalFileSystem();
                 int lastSeparator = synonymProviderConfigPath.lastIndexOf(

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java?rev=816678&r1=816677&r2=816678&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
Fri Sep 18 15:43:57 2009
@@ -58,15 +58,7 @@
                 pmc.getClassName());
         assertTrue(pmc.getParameters().isEmpty());
 
-        SearchConfig sc = config.getSearchConfig();
-        assertEquals(
-                "org.apache.jackrabbit.core.query.lucene.SearchIndex",
-                sc.getClassName());
-        assertEquals(4, sc.getParameters().size());
-        assertEquals("true", sc.getParameters().getProperty("useCompoundFile"));
-        assertEquals("1000", sc.getParameters().getProperty("minMergeDocs"));
-        assertEquals("10000", sc.getParameters().getProperty("maxMergeDocs"));
-        assertEquals("10", sc.getParameters().getProperty("mergeFactor"));
+        assertTrue(config.isSearchEnabled());
 
         WorkspaceSecurityConfig ws = config.getSecurityConfig();
         if (ws != null) {



Mime
View raw message