01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: SearchFileReader.java,v 1.39.2.4 2008/01/07 15:14:13 cwl Exp $
07: */
08:
09: package com.sleepycat.je.log;
10:
11: import java.io.IOException;
12: import java.nio.ByteBuffer;
13:
14: import com.sleepycat.je.DatabaseException;
15: import com.sleepycat.je.dbi.EnvironmentImpl;
16: import com.sleepycat.je.log.entry.LogEntry;
17: import com.sleepycat.je.utilint.DbLsn;
18:
19: /**
20: * SearchFileReader searches for the a given entry type.
21: */
22: public class SearchFileReader extends FileReader {
23:
24: private LogEntryType targetType;
25: private LogEntry logEntry;
26:
27: /**
28: * Create this reader to start at a given LSN.
29: */
30: public SearchFileReader(EnvironmentImpl env, int readBufferSize,
31: boolean forward, long startLsn, long endOfFileLsn,
32: LogEntryType targetType) throws IOException,
33: DatabaseException {
34:
35: super (env, readBufferSize, forward, startLsn, null,
36: endOfFileLsn, DbLsn.NULL_LSN);
37:
38: this .targetType = targetType;
39: logEntry = targetType.getNewLogEntry();
40: }
41:
42: /**
43: * @return true if this is a targetted entry.
44: */
45: protected boolean isTargetEntry(byte logEntryTypeNumber,
46: byte logEntryTypeVersion) {
47: return (targetType.equalsType(logEntryTypeNumber,
48: logEntryTypeVersion));
49: }
50:
51: /**
52: * This reader instantiate the first object of a given log entry.
53: */
54: protected boolean processEntry(ByteBuffer entryBuffer)
55: throws DatabaseException {
56:
57: readEntry(logEntry, entryBuffer, true); // readFullItem
58: return true;
59: }
60:
61: /**
62: * @return the last object read.
63: */
64: public Object getLastObject() {
65: return logEntry.getMainItem();
66: }
67: }
|