From 1e538244af5e6869bd571ecd77557f70930d80e5 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 28 Jan 2012 15:13:36 +0000 Subject: [PATCH] LUCENE-3661: make Lucene3x codec really completely readonly git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1237070 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/codecs/lucene3x/Lucene3xCodec.java | 17 ++++++++++-- .../codecs/preflexrw/PreFlexRWCodec.java | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java b/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java index beaf19481ca..78aac059053 100644 --- a/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java +++ b/lucene/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xCodec.java @@ -30,6 +30,7 @@ import org.apache.lucene.codecs.PerDocProducer; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.SegmentInfosFormat; import org.apache.lucene.codecs.StoredFieldsFormat; +import org.apache.lucene.codecs.StoredFieldsWriter; import org.apache.lucene.codecs.TermVectorsFormat; import org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat; import org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsFormat; @@ -37,6 +38,8 @@ import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.util.MutableBits; /** * Supports the Lucene 3.x index format (readonly) @@ -49,7 +52,12 @@ public class Lucene3xCodec extends Codec { private final PostingsFormat postingsFormat = new Lucene3xPostingsFormat(); // TODO: this should really be a different impl - private final StoredFieldsFormat fieldsFormat = new Lucene40StoredFieldsFormat(); + private final StoredFieldsFormat fieldsFormat = new Lucene40StoredFieldsFormat() { + @Override + public StoredFieldsWriter fieldsWriter(Directory directory, String segment, IOContext context) throws IOException { + throw new UnsupportedOperationException("this codec can only be used for reading"); + } + }; private final TermVectorsFormat vectorsFormat = new Lucene3xTermVectorsFormat(); @@ -60,7 +68,12 @@ public class Lucene3xCodec extends Codec { private final NormsFormat normsFormat = new Lucene3xNormsFormat(); // TODO: this should really be a different impl - private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat(); + private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat() { + @Override + public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException { + throw new UnsupportedOperationException("this codec can only be used for reading"); + } + }; // 3.x doesn't support docvalues private final DocValuesFormat docValuesFormat = new DocValuesFormat() { diff --git a/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java b/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java index 9d784b12ee5..aface166018 100644 --- a/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java +++ b/lucene/src/test-framework/java/org/apache/lucene/codecs/preflexrw/PreFlexRWCodec.java @@ -18,11 +18,15 @@ package org.apache.lucene.codecs.preflexrw; */ import org.apache.lucene.codecs.FieldInfosFormat; +import org.apache.lucene.codecs.LiveDocsFormat; import org.apache.lucene.codecs.NormsFormat; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.SegmentInfosFormat; +import org.apache.lucene.codecs.StoredFieldsFormat; import org.apache.lucene.codecs.TermVectorsFormat; import org.apache.lucene.codecs.lucene3x.Lucene3xCodec; +import org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat; +import org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsFormat; import org.apache.lucene.util.LuceneTestCase; /** @@ -35,6 +39,10 @@ public class PreFlexRWCodec extends Lucene3xCodec { private final FieldInfosFormat fieldInfos = new PreFlexRWFieldInfosFormat(); private final TermVectorsFormat termVectors = new PreFlexRWTermVectorsFormat(); private final SegmentInfosFormat segmentInfos = new PreFlexRWSegmentInfosFormat(); + // TODO: this should really be a different impl + private final LiveDocsFormat liveDocs = new Lucene40LiveDocsFormat(); + // TODO: this should really be a different impl + private final StoredFieldsFormat storedFields = new Lucene40StoredFieldsFormat(); @Override public PostingsFormat postingsFormat() { @@ -80,4 +88,22 @@ public class PreFlexRWCodec extends Lucene3xCodec { return super.termVectorsFormat(); } } + + @Override + public LiveDocsFormat liveDocsFormat() { + if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) { + return liveDocs; + } else { + return super.liveDocsFormat(); + } + } + + @Override + public StoredFieldsFormat storedFieldsFormat() { + if (LuceneTestCase.PREFLEX_IMPERSONATION_IS_ACTIVE) { + return storedFields; + } else { + return super.storedFieldsFormat(); + } + } }