2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 namespace Mono.Lucene.Net.Index
23 /// <summary> This class keeps track of closing the underlying directory. It is used to wrap
24 /// DirectoryReaders, that are created using a String/File parameter
25 /// in IndexReader.open() with FSDirectory.getDirectory().
27 /// <deprecated> This helper class is removed with all String/File
28 /// IndexReader.open() methods in Lucene 3.0
30 [Obsolete("This helper class is removed with all String/File IndexReader.open() methods in Lucene 3.0")]
31 sealed class DirectoryOwningReader:FilterIndexReader, System.ICloneable
34 internal DirectoryOwningReader(IndexReader in_Renamed):base(in_Renamed)
36 this.ref_Renamed = new SegmentReader.Ref();
37 System.Diagnostics.Debug.Assert(this.ref_Renamed.RefCount() == 1);
40 private DirectoryOwningReader(IndexReader in_Renamed, SegmentReader.Ref ref_Renamed):base(in_Renamed)
42 this.ref_Renamed = ref_Renamed;
46 public override IndexReader Reopen()
49 IndexReader r = in_Renamed.Reopen();
51 return new DirectoryOwningReader(r, ref_Renamed);
55 public override IndexReader Reopen(bool openReadOnly)
58 IndexReader r = in_Renamed.Reopen(openReadOnly);
60 return new DirectoryOwningReader(r, ref_Renamed);
64 public override IndexReader Reopen(IndexCommit commit)
67 IndexReader r = in_Renamed.Reopen(commit);
69 return new DirectoryOwningReader(r, ref_Renamed);
73 public override System.Object Clone()
76 return new DirectoryOwningReader((IndexReader) in_Renamed.Clone(), ref_Renamed);
79 public override IndexReader Clone(bool openReadOnly)
82 return new DirectoryOwningReader(in_Renamed.Clone(openReadOnly), ref_Renamed);
85 protected internal override void DoClose()
87 System.IO.IOException ioe = null;
88 // close the reader, record exception
93 catch (System.IO.IOException e)
97 // close the directory, record exception
98 if (ref_Renamed.DecRef() == 0)
102 in_Renamed.Directory().Close();
104 catch (System.IO.IOException e)
110 // throw the first exception
115 /// <summary> This member contains the ref counter, that is passed to each instance after cloning/reopening,
116 /// and is global to all DirectoryOwningReader derived from the original one.
117 /// This reuses the class {@link SegmentReader.Ref}
119 private SegmentReader.Ref ref_Renamed;