001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.lucene.store.jdbc;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import org.apache.lucene.store.jdbc.handler.ActualDeleteFileEntryHandler;
023: import org.apache.lucene.store.jdbc.handler.NoOpFileEntryHandler;
024: import org.apache.lucene.store.jdbc.index.FetchOnOpenJdbcIndexInput;
025: import org.apache.lucene.store.jdbc.index.RAMJdbcIndexOutput;
026: import org.apache.lucene.store.jdbc.lock.PhantomReadLock;
027:
028: /**
029: * General directory level settings.
030: * <p />
031: * The settings also holds {@link JdbcFileEntrySettings}, that can be registered with
032: * the directory settings. Note, that when registering them, they are registered under
033: * both the complete name and the 3 charecters name suffix.
034: * <p />
035: * When creating the settings, it already holds sensible settings, they are:
036: * The default {@link JdbcFileEntrySettings} uses the file entry settings defaults.
037: * The "deletable", ""deleteable.new", and "deletable.new" uses the {@link NoOpFileEntryHandler}.
038: * The "segments" and "segments.new" uses the {@link ActualDeleteFileEntryHandler}, {@link FetchOnOpenJdbcIndexInput},
039: * and {@link RAMJdbcIndexOutput}.
040: * The file suffix "fnm" uses the {@link FetchOnOpenJdbcIndexInput}, and {@link RAMJdbcIndexOutput}.
041: * The file suffix "del" and "tmp" uses the {@link ActualDeleteFileEntryHandler}.
042: *
043: * @author kimchy
044: */
045: public class JdbcDirectorySettings {
046:
047: /**
048: * The default file entry settings name that are registered under.
049: */
050: public static String DEFAULT_FILE_ENTRY = "__default__";
051:
052: /**
053: * A simple constant having the millisecond value of an hour.
054: */
055: public static final long HOUR = 60 * 60 * 1000;
056:
057: private int nameColumnLength = 50;
058:
059: private int valueColumnLengthInK = 500 * 1000;
060:
061: private String nameColumnName = "name_";
062:
063: private String valueColumnName = "value_";
064:
065: private String sizeColumnName = "size_";
066:
067: private String lastModifiedColumnName = "lf_";
068:
069: private String deletedColumnName = "deleted_";
070:
071: private HashMap fileEntrySettings = new HashMap();
072:
073: private long deleteMarkDeletedDelta = HOUR;
074:
075: private int queryTimeout = 10;
076:
077: private Class lockClass = PhantomReadLock.class;
078:
079: /**
080: * Creates a new instance of the Jdbc directory settings with it's default values initialized.
081: */
082: public JdbcDirectorySettings() {
083: JdbcFileEntrySettings defaultSettings = new JdbcFileEntrySettings();
084: registerFileEntrySettings(DEFAULT_FILE_ENTRY, defaultSettings);
085:
086: JdbcFileEntrySettings deletableSettings = new JdbcFileEntrySettings();
087: deletableSettings.setClassSetting(
088: JdbcFileEntrySettings.FILE_ENTRY_HANDLER_TYPE,
089: NoOpFileEntryHandler.class);
090: registerFileEntrySettings("deletable", deletableSettings);
091: registerFileEntrySettings("deleteable.new", deletableSettings);
092: // in case lucene fix the spelling mistake
093: registerFileEntrySettings("deletable.new", deletableSettings);
094:
095: JdbcFileEntrySettings segmentsSettings = new JdbcFileEntrySettings();
096: segmentsSettings.setClassSetting(
097: JdbcFileEntrySettings.FILE_ENTRY_HANDLER_TYPE,
098: ActualDeleteFileEntryHandler.class);
099: segmentsSettings.setClassSetting(
100: JdbcFileEntrySettings.INDEX_INPUT_TYPE_SETTING,
101: FetchOnOpenJdbcIndexInput.class);
102: segmentsSettings.setClassSetting(
103: JdbcFileEntrySettings.INDEX_OUTPUT_TYPE_SETTING,
104: RAMJdbcIndexOutput.class);
105: registerFileEntrySettings("segments", segmentsSettings);
106: registerFileEntrySettings("segments.new", segmentsSettings);
107:
108: JdbcFileEntrySettings dotDelSettings = new JdbcFileEntrySettings();
109: dotDelSettings.setClassSetting(
110: JdbcFileEntrySettings.FILE_ENTRY_HANDLER_TYPE,
111: ActualDeleteFileEntryHandler.class);
112: registerFileEntrySettings("del", dotDelSettings);
113:
114: JdbcFileEntrySettings tmpSettings = new JdbcFileEntrySettings();
115: tmpSettings.setClassSetting(
116: JdbcFileEntrySettings.FILE_ENTRY_HANDLER_TYPE,
117: ActualDeleteFileEntryHandler.class);
118: registerFileEntrySettings("tmp", dotDelSettings);
119:
120: JdbcFileEntrySettings fnmSettings = new JdbcFileEntrySettings();
121: fnmSettings.setClassSetting(
122: JdbcFileEntrySettings.INDEX_INPUT_TYPE_SETTING,
123: FetchOnOpenJdbcIndexInput.class);
124: fnmSettings.setClassSetting(
125: JdbcFileEntrySettings.INDEX_OUTPUT_TYPE_SETTING,
126: RAMJdbcIndexOutput.class);
127: registerFileEntrySettings("fnm", fnmSettings);
128: }
129:
130: /**
131: * Returns the name column length.
132: */
133: public int getNameColumnLength() {
134: return nameColumnLength;
135: }
136:
137: /**
138: * Sets the name column length.
139: */
140: public void setNameColumnLength(int nameColumnLength) {
141: this .nameColumnLength = nameColumnLength;
142: }
143:
144: /**
145: * Returns the value column length (In K).
146: */
147: public int getValueColumnLengthInK() {
148: return valueColumnLengthInK;
149: }
150:
151: /**
152: * Sets the value coumn length (In K).
153: */
154: public void setValueColumnLengthInK(int valueColumnLengthInK) {
155: this .valueColumnLengthInK = valueColumnLengthInK;
156: }
157:
158: /**
159: * Returns the name column name (defaults to name_).
160: */
161: public String getNameColumnName() {
162: return nameColumnName;
163: }
164:
165: /**
166: * Sets the name column name.
167: */
168: public void setNameColumnName(String nameColumnName) {
169: this .nameColumnName = nameColumnName;
170: }
171:
172: /**
173: * Returns the value column name (defaults to value_).
174: */
175: public String getValueColumnName() {
176: return valueColumnName;
177: }
178:
179: /**
180: * Sets the value column name.
181: */
182: public void setValueColumnName(String valueColumnName) {
183: this .valueColumnName = valueColumnName;
184: }
185:
186: /**
187: * Returns the size column name (default to size_).
188: */
189: public String getSizeColumnName() {
190: return sizeColumnName;
191: }
192:
193: /**
194: * Sets the size column name.
195: */
196: public void setSizeColumnName(String sizeColumnName) {
197: this .sizeColumnName = sizeColumnName;
198: }
199:
200: /**
201: * Returns the last modified column name (defaults to lf_).
202: */
203: public String getLastModifiedColumnName() {
204: return lastModifiedColumnName;
205: }
206:
207: /**
208: * Sets the last modified column name.
209: */
210: public void setLastModifiedColumnName(String lastModifiedColumnName) {
211: this .lastModifiedColumnName = lastModifiedColumnName;
212: }
213:
214: /**
215: * Returns the deleted column name (defaults to deleted_).
216: */
217: public String getDeletedColumnName() {
218: return deletedColumnName;
219: }
220:
221: /**
222: * Sets the deleted column name.
223: */
224: public void setDeletedColumnName(String deletedColumnName) {
225: this .deletedColumnName = deletedColumnName;
226: }
227:
228: /**
229: * Registers a {@link JdbcFileEntrySettings} against the given name.
230: * The name can be the full name of the file, or it's 3 charecters suffix.
231: */
232: public void registerFileEntrySettings(String name,
233: JdbcFileEntrySettings fileEntrySettings) {
234: this .fileEntrySettings.put(name, fileEntrySettings);
235: }
236:
237: /**
238: * Returns the file entries map. Please don't change it during runtime.
239: */
240: public Map getFileEntrySettings() {
241: return this .fileEntrySettings;
242: }
243:
244: /**
245: * Returns the file entries according to the name. If a direct match is found, it's registered
246: * {@link JdbcFileEntrySettings} is returned. If one is registered
247: * against the last 3 charecters, then it is returned. If none is found, the default file entry
248: * handler is returned.
249: */
250: public JdbcFileEntrySettings getFileEntrySettings(String name) {
251: JdbcFileEntrySettings settings = getFileEntrySettingsWithoutDefault(name);
252: if (settings != null) {
253: return settings;
254: }
255: return getDefaultFileEntrySettings();
256: }
257:
258: /**
259: * Same as {@link #getFileEntrySettings(String)}, only returns <code>null</code> if no match is found
260: * (instead of the default file entry handler settings).
261: */
262: public JdbcFileEntrySettings getFileEntrySettingsWithoutDefault(
263: String name) {
264: JdbcFileEntrySettings settings = (JdbcFileEntrySettings) fileEntrySettings
265: .get(name.substring(name.length() - 3));
266: if (settings != null) {
267: return settings;
268: }
269: return (JdbcFileEntrySettings) fileEntrySettings.get(name);
270: }
271:
272: /**
273: * Returns the default file entry handler settings.
274: */
275: public JdbcFileEntrySettings getDefaultFileEntrySettings() {
276: return (JdbcFileEntrySettings) fileEntrySettings
277: .get(DEFAULT_FILE_ENTRY);
278: }
279:
280: /**
281: * Returns the delta (in millis) for the delete mark deleted. File entries marked as being deleted will
282: * be deleted from the system (using {@link org.apache.lucene.store.jdbc.JdbcDirectory#deleteMarkDeleted()}
283: * if: current_time - deletelMarkDeletedDelta < Time File Entry Marked as Deleted.
284: */
285: public long getDeleteMarkDeletedDelta() {
286: return deleteMarkDeletedDelta;
287: }
288:
289: /**
290: * Sets the delta (in millis) for the delete mark deleted. File entries marked as being deleted will
291: * be deleted from the system (using {@link org.apache.lucene.store.jdbc.JdbcDirectory#deleteMarkDeleted()}
292: * if: current_time - deletelMarkDeletedDelta < Time File Entry Marked as Deleted.
293: */
294: public void setDeleteMarkDeletedDelta(long deleteMarkDeletedDelta) {
295: this .deleteMarkDeletedDelta = deleteMarkDeletedDelta;
296: }
297:
298: /**
299: * Query timeout applies to Jdbc queries.
300: */
301: public int getQueryTimeout() {
302: return queryTimeout;
303: }
304:
305: /**
306: * Query timeout applies to Jdbc queries.
307: */
308: public void setQueryTimeout(int queryTimeout) {
309: this .queryTimeout = queryTimeout;
310: }
311:
312: /**
313: * Returns the lock class that will be used for locking. Defaults to {@link PhantomReadLock}.
314: */
315: public Class getLockClass() {
316: return lockClass;
317: }
318:
319: /**
320: * Sets the lock class that will be used for locking. Defaults to {@link PhantomReadLock}.
321: */
322: public void setLockClass(Class lockClass) {
323: this.lockClass = lockClass;
324: }
325: }
|