jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r900317 - in /jackrabbit/branches/2.0: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/test/resources/org/apache/jackrabbit...
Date Mon, 18 Jan 2010 09:40:45 GMT
Author: mreutegg
Date: Mon Jan 18 09:40:45 2010
New Revision: 900317

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

Added:
    jackrabbit/branches/2.0/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
      - copied unchanged from r900314, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config4.xml
Modified:
    jackrabbit/branches/2.0/   (props changed)
    jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
    jackrabbit/branches/2.0/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java

Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jan 18 09:40:45 2010
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,899181
+/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,899181,900314

Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java?rev=900317&r1=900316&r2=900317&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
Mon Jan 18 09:40:45 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/branches/2.0/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java?rev=900317&r1=900316&r2=900317&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
Mon Jan 18 09:40:45 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 >----------------------------------
 



Mime
View raw message