You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2008/04/22 16:37:58 UTC

svn commit: r650536 - in /jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: MultiIndex.java SearchIndex.java

Author: jukka
Date: Tue Apr 22 07:37:52 2008
New Revision: 650536

URL: http://svn.apache.org/viewvc?rev=650536&view=rev
Log:
1.4: Merged revision 643369 (JCR-1326)

Modified:
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=650536&r1=650535&r2=650536&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Tue Apr 22 07:37:52 2008
@@ -26,6 +26,11 @@
 import org.apache.jackrabbit.uuid.Constants;
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.util.Timer;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.lucene.document.Document;
@@ -80,6 +85,11 @@
     private static final Logger log = LoggerFactory.getLogger(MultiIndex.class);
 
     /**
+     * A path factory.
+     */
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
+
+    /**
      * Default name of the redo log file
      */
     private static final String REDO_LOG = "redo.log";
@@ -368,7 +378,7 @@
      *                               workspace.
      * @throws IllegalStateException if this index is not empty.
      */
-    void createInitialIndex(ItemStateManager stateMgr, NodeId rootId)
+    void createInitialIndex(ItemStateManager stateMgr, NodeId rootId, Path rootPath)
             throws IOException {
         // only do an initial index if there are no indexes at all
         if (indexNames.size() == 0) {
@@ -377,7 +387,7 @@
                 // traverse and index workspace
                 executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
                 NodeState rootState = (NodeState) stateMgr.getItemState(rootId);
-                createIndex(rootState, stateMgr);
+                createIndex(rootState, rootPath, stateMgr);
                 executeAndLog(new Commit(getTransactionId()));
                 scheduleFlushTask();
             } catch (Exception e) {
@@ -1020,7 +1030,7 @@
      * @throws ItemStateException  if an node state cannot be found.
      * @throws RepositoryException if any other error occurs
      */
-    private void createIndex(NodeState node, ItemStateManager stateMgr)
+    private void createIndex(NodeState node, Path path, ItemStateManager stateMgr)
             throws IOException, ItemStateException, RepositoryException {
         NodeId id = node.getNodeId();
         if (excludedIDs.contains(id)) {
@@ -1031,8 +1041,26 @@
         List children = node.getChildNodeEntries();
         for (Iterator it = children.iterator(); it.hasNext();) {
             NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry) it.next();
-            NodeState childState = (NodeState) stateMgr.getItemState(child.getId());
-            createIndex(childState, stateMgr);
+            Path childPath = PATH_FACTORY.create(path, child.getName(),
+                    child.getIndex(), false);
+            NodeState childState;
+            try {
+                childState = (NodeState) stateMgr.getItemState(child.getId());
+            } catch (NoSuchItemStateException e) {
+                NamePathResolver resolver = new DefaultNamePathResolver(
+                        handler.getContext().getNamespaceRegistry());
+                log.error("Node {} ({}) has missing child '{}' ({})",
+                        new Object[]{
+                            resolver.getJCRPath(path),
+                            node.getNodeId().getUUID().toString(),
+                            resolver.getJCRName(child.getName()),
+                            child.getId().getUUID().toString()
+                        });
+                throw e;
+            }
+            if (childState != null) {
+                createIndex(childState, childPath, stateMgr);
+            }
         }
     }
 

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=650536&r1=650535&r2=650536&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Tue Apr 22 07:37:52 2008
@@ -38,7 +38,10 @@
 import org.apache.jackrabbit.extractor.TextExtractor;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -149,6 +152,27 @@
     public static final long DEFAULT_EXTRACTOR_TIMEOUT = 100;
 
     /**
+     * The path of the root node.
+     */
+    private static final Path ROOT_PATH;
+
+    /**
+     * The path <code>/jcr:system</code>.
+     */
+    private static final Path JCR_SYSTEM_PATH;
+
+    static {
+        PathFactory factory = PathFactoryImpl.getInstance();
+        ROOT_PATH = factory.create(NameConstants.ROOT);
+        try {
+            JCR_SYSTEM_PATH = factory.create(ROOT_PATH, NameConstants.JCR_SYSTEM, false);
+        } catch (RepositoryException e) {
+            // should never happen, path is always valid
+            throw new InternalError(e.getMessage());
+        }
+    }
+
+    /**
      * The actual index
      */
     private MultiIndex index;
@@ -422,8 +446,15 @@
         
         index = new MultiIndex(indexDir, this, excludedIDs, nsMappings);
         if (index.numDocs() == 0) {
-            index.createInitialIndex(
-                    context.getItemStateManager(), context.getRootId());
+            Path rootPath;
+            if (excludedIDs.isEmpty()) {
+                // this is the index for jcr:system
+                rootPath = JCR_SYSTEM_PATH;
+            } else {
+                rootPath = ROOT_PATH;
+            }
+            index.createInitialIndex(context.getItemStateManager(),
+                    context.getRootId(), rootPath);
         }
         if (consistencyCheckEnabled
                 && (index.getRedoLogApplied() || forceConsistencyCheck)) {