jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r900314 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/lucene/ test/resources/org/apache/jackrabbit/core/query/lucene/
Date Mon, 18 Jan 2010 09:17:47 GMT
Author: mreutegg
Date: Mon Jan 18 09:17:46 2010
New Revision: 900314

URL: http://svn.apache.org/viewvc?rev=900314&view=rev
Log:
JCR-2468: Indexing configuration not refreshed after node type registration

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java?rev=900314&r1=900313&r2=900314&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
Mon Jan 18 09:17:46 2010
@@ -33,6 +33,7 @@
 import org.apache.jackrabbit.core.HierarchyManagerImpl;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistryListener;
 import org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
@@ -67,7 +68,8 @@
  * <code>IndexingConfigurationImpl</code> implements a concrete indexing
  * configuration.
  */
-public class IndexingConfigurationImpl implements IndexingConfiguration {
+public class IndexingConfigurationImpl
+        implements IndexingConfiguration, NodeTypeRegistryListener {
 
     /**
      * The logger instance for this class
@@ -80,6 +82,11 @@
     private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
 
     /**
+     * The indexing configuration.
+     */
+    private Element configuration;
+
+    /**
      * A namespace resolver for parsing QNames in the configuration.
      */
     private NameResolver resolver;
@@ -95,6 +102,11 @@
     private HierarchyManager hmgr;
 
     /**
+     * The node type registry.
+     */
+    private NodeTypeRegistry ntReg;
+
+    /**
      * The {@link IndexingRule}s inside this configuration.
      */
     private Map<Name, List<IndexingRule>> configElements = new HashMap<Name,
List<IndexingRule>>();
@@ -112,35 +124,23 @@
     /**
      * {@inheritDoc}
      */
-    public void init(Element config, QueryHandlerContext context, NamespaceMappings nsMappings)
throws Exception {
+    public void init(Element config,
+                     QueryHandlerContext context,
+                     NamespaceMappings nsMappings) throws Exception {
+        configuration = config;
         ism = context.getItemStateManager();
         hmgr = new HierarchyManagerImpl(context.getRootId(), ism);
-
         NamespaceResolver nsResolver = new AdditionalNamespaceResolver(getNamespaces(config));
         resolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), nsResolver);
+        ntReg = context.getNodeTypeRegistry();
+        ntReg.addListener(this);
 
-        NodeTypeRegistry ntReg = context.getNodeTypeRegistry();
-        Name[] ntNames = ntReg.getRegisteredNodeTypes();
+        refreshIndexRules();
         List<AggregateRule> idxAggregates = new ArrayList<AggregateRule>();
         NodeList indexingConfigs = config.getChildNodes();
         for (int i = 0; i < indexingConfigs.getLength(); i++) {
             Node configNode = indexingConfigs.item(i);
-            if (configNode.getNodeName().equals("index-rule")) {
-                IndexingRule element = new IndexingRule(configNode);
-                // register under node type and all its sub types
-                log.debug("Found rule '{}' for NodeType '{}'", element, element.getNodeTypeName());
-                for (Name ntName : ntNames) {
-                    if (ntReg.getEffectiveNodeType(ntName).includesNodeType(element.getNodeTypeName()))
{
-                        List<IndexingRule> perNtConfig = configElements.get(ntName);
-                        if (perNtConfig == null) {
-                            perNtConfig = new ArrayList<IndexingRule>();
-                            configElements.put(ntName, perNtConfig);
-                        }
-                        log.debug("Registering it for name '{}'", ntName);
-                        perNtConfig.add(new IndexingRule(element, ntName));
-                    }
-                }
-            } else if (configNode.getNodeName().equals("aggregate")) {
+            if (configNode.getNodeName().equals("aggregate")) {
                 idxAggregates.add(new AggregateRuleImpl(
                         configNode, resolver, ism, hmgr));
             } else if (configNode.getNodeName().equals("analyzers")) {
@@ -307,9 +307,61 @@
         }
         return null;
     }
+
+    //--------------------------< NodeTypeRegistryListener >--------------------
+
+    public void nodeTypeRegistered(Name ntName) {
+        try {
+            refreshIndexRules();
+        } catch (Exception e) {
+            log.warn("Unable to refresh index rules", e);
+        }
+    }
+
+    public void nodeTypeReRegistered(Name ntName) {
+        // not interested
+    }
+
+    public void nodeTypeUnregistered(Name ntName) {
+        // not interested
+    }
+
     //---------------------------------< internal >-----------------------------
 
     /**
+     * Refreshes the index rules in {@link #configElements} based on the current
+     * node types available in the node type registry.
+     *
+     * @throws Exception if an error occurs while refreshing the rules.
+     */
+    private void refreshIndexRules() throws Exception {
+        Map<Name, List<IndexingRule>> nt2rules = new HashMap<Name, List<IndexingRule>>();
+        Name[] ntNames = ntReg.getRegisteredNodeTypes();
+        NodeList indexingConfigs = configuration.getChildNodes();
+        for (int i = 0; i < indexingConfigs.getLength(); i++) {
+            Node configNode = indexingConfigs.item(i);
+            if (configNode.getNodeName().equals("index-rule")) {
+                IndexingRule element = new IndexingRule(configNode);
+                // register under node type and all its sub types
+                log.debug("Found rule '{}' for NodeType '{}'", element, element.getNodeTypeName());
+                for (Name ntName : ntNames) {
+                    if (ntReg.getEffectiveNodeType(ntName).includesNodeType(element.getNodeTypeName()))
{
+                        List<IndexingRule> perNtConfig = nt2rules.get(ntName);
+                        if (perNtConfig == null) {
+                            perNtConfig = new ArrayList<IndexingRule>();
+                            nt2rules.put(ntName, perNtConfig);
+                        }
+                        log.debug("Registering it for name '{}'", ntName);
+                        perNtConfig.add(new IndexingRule(element, ntName));
+                    }
+                }
+            }
+        }
+        configElements = nt2rules;
+    }
+
+
+    /**
      * Returns the first indexing rule that applies to the given node
      * <code>state</code>.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java?rev=900314&r1=900313&r2=900314&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
Mon Jan 18 09:17:46 2010
@@ -20,6 +20,8 @@
 import java.io.InputStream;
 
 import javax.jcr.Node;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -70,6 +72,30 @@
         assertFalse(config.isIndexed(nState, FOO));
     }
 
+    public void testAddNodeTypeToRegistry() throws Exception {
+        IndexingConfiguration config = createConfig("config4");
+        // add node type
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        String baseName = "indexingTextNodeType";
+        int i = 0;
+        String nt;
+        do {
+            nt = baseName + "_" + i++;
+        } while (ntMgr.hasNodeType(nt));
+        // register node type
+        NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
+        ntTemplate.setName(nt);
+        ntTemplate.setDeclaredSuperTypeNames(new String[]{ntUnstructured});
+        ntMgr.registerNodeType(ntTemplate, false);
+        // create node
+        Node n = testRootNode.addNode(nodeName2, nt);
+        superuser.save();
+        // get state
+        NodeState state = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(
+                new NodeId(n.getIdentifier()));
+        assertTrue(config.isIndexed(state, FOO));
+        assertFalse(config.isIncludedInNodeScopeIndex(state, FOO));
+    }
 
     //----------------------------< internal >----------------------------------
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml?rev=900314&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
Mon Jan 18 09:17:46 2010
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+   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.
+-->
+<!DOCTYPE configuration SYSTEM "http://jackrabbit.apache.org/dtd/indexing-configuration-1.2.dtd">
+<configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
+               xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+
+    <index-rule nodeType="nt:base">
+        <property nodeScopeIndex="false">foo</property>
+        <property isRegexp="true">.*:.*</property>
+    </index-rule>
+
+</configuration>
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message