jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1389256 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/lucene/ main/java/org/apache/jackrabbit/oak/spi/query/ test/java/org/apache/jackrabbit/oak/plugins/lucene/
Date Mon, 24 Sep 2012 09:24:40 GMT
Author: alexparvulescu
Date: Mon Sep 24 09:24:40 2012
New Revision: 1389256

URL: http://svn.apache.org/viewvc?rev=1389256&view=rev
Log:
OAK-334 Add read-only lucene directory

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadOnlyOakDirectory.java
      - copied, changed from r1388383, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java
  (with props)
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
Mon Sep 24 09:24:40 2012
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -40,6 +41,7 @@ import org.apache.lucene.analysis.standa
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Version;
 import org.apache.tika.Tika;
 import org.apache.tika.exception.TikaException;
@@ -78,9 +80,15 @@ class LuceneEditor implements CommitHook
     @Override
     public NodeState processCommit(NodeStore store, NodeState before,
             NodeState after) throws CommitFailedException {
-        try {
-            OakDirectory directory = new OakDirectory(store, after, path);
+        NodeBuilder rootBuilder = store.getBuilder(after);
+        NodeBuilder builder = rootBuilder;
+        for (String name : path) {
+            builder = builder.getChildBuilder(name);
+        }
+        Directory directory = new ReadWriteOakDirectory(builder,
+                store.getValueFactory());
 
+        try {
             IndexWriter writer = new IndexWriter(directory, config);
             try {
                 LuceneDiff diff = new LuceneDiff(writer, "");
@@ -90,8 +98,7 @@ class LuceneEditor implements CommitHook
             } finally {
                 writer.close();
             }
-
-            return directory.getRoot();
+            return rootBuilder.getNodeState();
         } catch (IOException e) {
             e.printStackTrace();
             throw new CommitFailedException(

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
Mon Sep 24 09:24:40 2012
@@ -31,12 +31,13 @@ import java.util.List;
 import org.apache.jackrabbit.oak.query.index.IndexRowImpl;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction;
 import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.query.IndexRow;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
-import org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
@@ -50,20 +51,22 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This index uses internally runs a query against a Lucene index.
  */
 public class LuceneIndex implements QueryIndex, LuceneIndexConstants {
 
-    private final NodeStore store;
+    private static final Logger LOG = LoggerFactory
+            .getLogger(LuceneIndex.class);
 
     private final IndexDefinition index;
 
     private final String[] indexDataPath;
 
-    public LuceneIndex(NodeStore store, IndexDefinition indexDefinition) {
-        this.store = store;
+    public LuceneIndex(IndexDefinition indexDefinition) {
         this.index = indexDefinition;
         this.indexDataPath = split(indexDefinition.getPath(),
                 INDEX_DATA_CHILD_NAME);
@@ -86,8 +89,15 @@ public class LuceneIndex implements Quer
 
     @Override
     public Cursor query(Filter filter, String revisionId, NodeState root) {
+
+        NodeBuilder builder = new ReadOnlyBuilder(root);
+        for (String name : indexDataPath) {
+            builder = builder.getChildBuilder(name);
+        }
+        Directory directory = new ReadOnlyOakDirectory(builder);
+        long s = System.currentTimeMillis();
+
         try {
-            Directory directory = new OakDirectory(store, root, indexDataPath);
             try {
                 IndexReader reader = DirectoryReader.open(directory);
                 try {
@@ -108,7 +118,8 @@ public class LuceneIndex implements Quer
                             }
                         }
                     }
-
+                    LOG.debug("query via {} took {} ms.", this,
+                            System.currentTimeMillis() - s);
                     return new PathCursor(paths);
                 } finally {
                     reader.close();
@@ -216,4 +227,9 @@ public class LuceneIndex implements Quer
 
     }
 
+    @Override
+    public String toString() {
+        return "LuceneIndex [index=" + index + "]";
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
Mon Sep 24 09:24:40 2012
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.IndexUtils;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,14 +50,11 @@ public class LuceneIndexProvider impleme
             LOG.warn("index path is not valid {}", indexPath);
             return Collections.<QueryIndex> emptyList();
         }
-        NodeBuilder builder = IndexUtils.getChildBuilder(store, indexPath);
         List<QueryIndex> tempIndexes = new ArrayList<QueryIndex>();
         for (IndexDefinition child : IndexUtils.buildIndexDefinitions(
                 store.getRoot(), indexPath, TYPE)) {
-            // add :data node
-            builder.getChildBuilder(child.getName()).getChildBuilder(
-                    INDEX_DATA_CHILD_NAME);
-            tempIndexes.add(new LuceneIndex(store, child));
+            LOG.debug("found a lucene index definition {}", child);
+            tempIndexes.add(new LuceneIndex(child));
         }
         return tempIndexes;
     }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadOnlyOakDirectory.java
(from r1388383, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadOnlyOakDirectory.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadOnlyOakDirectory.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java&r1=1388383&r2=1389256&rev=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadOnlyOakDirectory.java
Mon Sep 24 09:24:40 2012
@@ -16,19 +16,15 @@
  */
 package org.apache.jackrabbit.oak.plugins.lucene;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 
-import javax.annotation.Nonnull;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
@@ -38,32 +34,17 @@ import org.apache.lucene.store.NoLockFac
 import com.google.common.collect.Iterables;
 
 /**
- * An implementation of the Lucene directory (a flat list of files) that allows
- * to store Lucene index content in an Oak repository.
+ * A read-only implementation of the Lucene {@link Directory} (a flat list of
+ * files) that only allows reading of the Lucene index content stored in an Oak
+ * repository.
  */
-class OakDirectory extends Directory {
+class ReadOnlyOakDirectory extends Directory {
 
-    private final CoreValueFactory factory;
+    protected final NodeBuilder directoryBuilder;
 
-    private final NodeBuilder rootBuilder;
-
-    private final NodeBuilder directoryBuilder;
-
-    public OakDirectory(NodeStore store, NodeState root, String... path) {
+    public ReadOnlyOakDirectory(NodeBuilder directoryBuilder) {
         this.lockFactory = NoLockFactory.getNoLockFactory();
-        this.factory = store.getValueFactory();
-        this.rootBuilder = store.getBuilder(root);
-
-        NodeBuilder builder = rootBuilder;
-        for (String name : path) {
-            builder = builder.getChildBuilder(name);
-        }
-        this.directoryBuilder = builder;
-    }
-
-    @Nonnull
-    NodeState getRoot() {
-        return rootBuilder.getNodeState();
+        this.directoryBuilder = directoryBuilder;
     }
 
     @Override
@@ -96,12 +77,11 @@ class OakDirectory extends Directory {
 
         return property.getValue().length();
     }
-    
 
     @Override
     public IndexOutput createOutput(String name, IOContext context)
             throws IOException {
-        return new OakIndexOutput(name);
+        throw new IOException(new UnsupportedRepositoryOperationException());
     }
 
     @Override
@@ -120,7 +100,7 @@ class OakDirectory extends Directory {
         // do nothing
     }
 
-    private byte[] readFile(String name) throws IOException {
+    protected byte[] readFile(String name) throws IOException {
         if (!fileExists(name)) {
             return new byte[0];
         }
@@ -152,86 +132,6 @@ class OakDirectory extends Directory {
         }
     }
 
-    private final class OakIndexOutput extends IndexOutput {
-
-        private final String name;
-
-        private byte[] buffer;
-
-        private int size;
-
-        private int position;
-
-        public OakIndexOutput(String name) throws IOException {
-            this.name = name;
-            this.buffer = readFile(name);
-            this.size = buffer.length;
-            this.position = 0;
-        }
-
-        @Override
-        public long length() {
-            return size;
-        }
-
-        @Override
-        public long getFilePointer() {
-            return position;
-        }
-
-        @Override
-        public void seek(long pos) throws IOException {
-            if (pos < 0 || pos > Integer.MAX_VALUE) {
-                throw new IOException("Invalid file position: " + pos);
-            }
-            this.position = (int) pos;
-        }
-
-        @Override
-        public void writeBytes(byte[] b, int offset, int length) {
-            while (position + length > buffer.length) {
-                byte[] tmp = new byte[Math.max(4096, buffer.length * 2)];
-                System.arraycopy(buffer, 0, tmp, 0, size);
-                buffer = tmp;
-            }
-
-            System.arraycopy(b, offset, buffer, position, length);
-
-            position += length;
-            if (position > size) {
-                size = position;
-            }
-        }
-
-        @Override
-        public void writeByte(byte b) {
-            writeBytes(new byte[] { b }, 0, 1);
-        }
-
-        @Override
-        public void flush() throws IOException {
-            byte[] data = buffer;
-            if (data.length > size) {
-                data = new byte[size];
-                System.arraycopy(buffer, 0, data, 0, size);
-            }
-
-            NodeBuilder fileBuilder =
-                    directoryBuilder.getChildBuilder(name);
-            fileBuilder.setProperty(
-                    "jcr:lastModified",
-                    factory.createValue(System.currentTimeMillis()));
-            fileBuilder.setProperty(
-                    "jcr:data",
-                    factory.createValue(new ByteArrayInputStream(data)));
-        }
-
-        @Override
-        public void close() throws IOException {
-            flush();
-        }
-    }
-
     private final class OakIndexInput extends IndexInput {
 
         private final byte[] data;

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java?rev=1389256&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java
Mon Sep 24 09:24:40 2012
@@ -0,0 +1,125 @@
+/*
+ * 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.oak.plugins.lucene;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexOutput;
+
+/**
+ * A red-write implementation of the Lucene {@link Directory} (a flat list of
+ * files) that allows to store Lucene index content in an Oak repository.
+ */
+public class ReadWriteOakDirectory extends ReadOnlyOakDirectory {
+
+    private final CoreValueFactory factory;
+
+    public ReadWriteOakDirectory(NodeBuilder directoryBuilder,
+            CoreValueFactory vf) {
+        super(directoryBuilder);
+        this.factory = vf;
+    }
+
+    @Override
+    public IndexOutput createOutput(String name, IOContext context)
+            throws IOException {
+        return new OakIndexOutput(name);
+    }
+
+    private final class OakIndexOutput extends IndexOutput {
+
+        private final String name;
+
+        private byte[] buffer;
+
+        private int size;
+
+        private int position;
+
+        public OakIndexOutput(String name) throws IOException {
+            this.name = name;
+            this.buffer = readFile(name);
+            this.size = buffer.length;
+            this.position = 0;
+        }
+
+        @Override
+        public long length() {
+            return size;
+        }
+
+        @Override
+        public long getFilePointer() {
+            return position;
+        }
+
+        @Override
+        public void seek(long pos) throws IOException {
+            if (pos < 0 || pos > Integer.MAX_VALUE) {
+                throw new IOException("Invalid file position: " + pos);
+            }
+            this.position = (int) pos;
+        }
+
+        @Override
+        public void writeBytes(byte[] b, int offset, int length) {
+            while (position + length > buffer.length) {
+                byte[] tmp = new byte[Math.max(4096, buffer.length * 2)];
+                System.arraycopy(buffer, 0, tmp, 0, size);
+                buffer = tmp;
+            }
+
+            System.arraycopy(b, offset, buffer, position, length);
+
+            position += length;
+            if (position > size) {
+                size = position;
+            }
+        }
+
+        @Override
+        public void writeByte(byte b) {
+            writeBytes(new byte[] { b }, 0, 1);
+        }
+
+        @Override
+        public void flush() throws IOException {
+            byte[] data = buffer;
+            if (data.length > size) {
+                data = new byte[size];
+                System.arraycopy(buffer, 0, data, 0, size);
+            }
+
+            NodeBuilder fileBuilder = directoryBuilder.getChildBuilder(name);
+            fileBuilder.setProperty("jcr:lastModified",
+                    factory.createValue(System.currentTimeMillis()));
+            fileBuilder.setProperty("jcr:data",
+                    factory.createValue(new ByteArrayInputStream(data)));
+        }
+
+        @Override
+        public void close() throws IOException {
+            flush();
+        }
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/ReadWriteOakDirectory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
Mon Sep 24 09:24:40 2012
@@ -120,7 +120,7 @@ public class IndexUtils {
 
         List<IndexDefinition> defs = new ArrayList<IndexDefinition>();
         for (ChildNodeEntry c : definitions.getChildNodeEntries()) {
-            IndexDefinition def = IndexUtils.getDefinition(indexConfigPath, c);
+            IndexDefinition def = getDefinition(indexConfigPath, c);
             if (def == null
                     || (typeFilter != null && !typeFilter.equals(def.getType())))
{
                 continue;

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
Mon Sep 24 09:24:40 2012
@@ -19,10 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import static org.apache.jackrabbit.oak.spi.query.IndexUtils.DEFAULT_INDEX_HOME;
 
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.AbstractOakTest;
 import org.apache.jackrabbit.oak.api.ContentRepository;
@@ -31,17 +28,10 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
-import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.type.DefaultTypeEditor;
-import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.value.ConflictValidatorProvider;
-import org.apache.jackrabbit.oak.spi.commit.CommitHook;
-import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
-import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
-import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
-import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.junit.Before;
@@ -54,7 +44,6 @@ public abstract class AbstractLuceneQuer
 
     protected static final String SQL2 = "JCR-SQL2";
 
-    protected MicroKernel mk;
     protected ContentSession session;
     protected CoreValueFactory vf;
     protected SessionQueryEngine qe;
@@ -68,34 +57,33 @@ public abstract class AbstractLuceneQuer
         root = session.getLatestRoot();
         vf = session.getCoreValueFactory();
         qe = session.getQueryEngine();
+        createIndexNode();
     }
 
     @Override
     protected ContentRepository createRepository() {
-        mk = new MicroKernelImpl();
         QueryIndexProvider indexer = new LuceneIndexProvider(DEFAULT_INDEX_HOME);
         QueryIndexProvider qip = new CompositeQueryIndexProvider(indexer);
-        return new ContentRepositoryImpl(mk, qip, buildDefaultCommitHook());
+        return new ContentRepositoryImpl(new MicroKernelImpl(), qip,
+                new LuceneHook(DEFAULT_INDEX_HOME));
     }
 
-    private CommitHook buildDefaultCommitHook() {
-        List<CommitHook> hooks = new ArrayList<CommitHook>();
-        hooks.add(new DefaultTypeEditor());
-        hooks.add(new ValidatingHook(createDefaultValidatorProvider()));
-        hooks.add(new LuceneHook(DEFAULT_INDEX_HOME));
-        return new CompositeHook(hooks);
-    }
-
-    private static ValidatorProvider createDefaultValidatorProvider() {
-        List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
-        providers.add(new NameValidatorProvider());
-        providers.add(new NamespaceValidatorProvider());
-        providers.add(new TypeValidatorProvider());
-        providers.add(new ConflictValidatorProvider());
-        return new CompositeValidatorProvider(providers);
+    private void createIndexNode() throws Exception {
+        Tree index = root.getTree("/");
+        for (String p : PathUtils.elements(DEFAULT_INDEX_HOME)) {
+            if (index.hasChild(p)) {
+                index = index.getChild(p);
+            } else {
+                index = index.addChild(p);
+            }
+        }
+        index.addChild("test-lucene").setProperty("type",
+                vf.createValue("lucene"));
+        root.commit(DefaultConflictHandler.OURS);
     }
 
     protected Result executeQuery(String statement) throws ParseException {
-        return qe.executeQuery(statement, SQL2, Long.MAX_VALUE, 0, null, session.getLatestRoot(),
null);
+        return qe.executeQuery(statement, SQL2, Long.MAX_VALUE, 0, null,
+                session.getLatestRoot(), null);
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java?rev=1389256&r1=1389255&r2=1389256&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
Mon Sep 24 09:24:40 2012
@@ -54,7 +54,7 @@ public class LuceneEditorTest implements
         tree.setProperty("foo", MemoryValueFactory.INSTANCE.createValue("bar"));
         root.commit(DefaultConflictHandler.OURS);
 
-        QueryIndex index = new LuceneIndex(store, testID);
+        QueryIndex index = new LuceneIndex(testID);
         FilterImpl filter = new FilterImpl(null);
         filter.restrictPath("/", Filter.PathRestriction.EXACT);
         filter.restrictProperty("foo", Operator.EQUAL,



Mime
View raw message