Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
SegmentsGenCommit.cs
Go to the documentation of this file.
1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 using Lucene.Net.Store;
24 
25 namespace Lucene.Net.Index
26 {
38  {
42  private Directory directory;
43 
47  private long generation = long.MinValue;
48 
54  {
55  this.directory = d;
56  this.ReadDirectory();
57  }
58 
64  public override string SegmentsFileName
65  {
66  get
67  {
68  return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, string.Empty, this.generation);
69  }
70  }
71 
72  public override long Generation
73  {
74  get
75  {
76  return this.generation;
77  }
78  }
79 
80  public override ICollection<string> FileNames
81  {
82  get
83  {
84  throw new NotImplementedException();
85  }
86  }
87 
88  public override Directory Directory
89  {
90  get
91  {
92  return this.directory;
93  }
94  }
95 
99  private void ReadDirectory()
100  {
101  IndexInput genInput = null;
102  try
103  {
104  genInput = directory.OpenInput(IndexFileNames.SEGMENTS_GEN);
105 
106  if (genInput != null)
107  {
108  int version = genInput.ReadInt();
109  if (version == Lucene.Net.Index.SegmentInfos.FORMAT_LOCKLESS)
110  {
111  long gen0 = genInput.ReadLong();
112  long gen1 = genInput.ReadLong();
113  if (gen0 == gen1)
114  {
115  // The file is consistent, use the generation
116  this.generation = gen0;
117  }
118  }
119  }
120  }
121  finally
122  {
123  genInput.Close();
124  }
125  }
126 
127  // TODO: implement these new API functions -thoward
128  public override void Delete()
129  {
130  throw new NotImplementedException();
131  }
132 
133  public override bool IsDeleted
134  {
135  get
136  {
137  throw new NotImplementedException();
138  }
139  }
140 
141  public override bool IsOptimized
142  {
143  get { throw new NotImplementedException(); }
144  }
145 
146  public override long Version
147  {
148  get
149  {
150  throw new NotImplementedException();
151  }
152  }
153 
154  public override IDictionary<string, string> UserData
155  {
156  get
157  {
158  throw new NotImplementedException();
159  }
160  }
161  }
162 }