01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: PrintFileReader.java,v 1.12.2.5 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:
18: /**
19: * The PrintFileReader prints out the target log entries.
20: */
21: public class PrintFileReader extends DumpFileReader {
22:
23: /**
24: * Create this reader to start at a given LSN.
25: */
26: public PrintFileReader(EnvironmentImpl env, int readBufferSize,
27: long startLsn, long finishLsn, String entryTypes,
28: String txnIds, boolean verbose) throws IOException,
29: DatabaseException {
30:
31: super (env, readBufferSize, startLsn, finishLsn, entryTypes,
32: txnIds, verbose);
33: }
34:
35: /**
36: * This reader prints the log entry item.
37: */
38: protected boolean processEntry(ByteBuffer entryBuffer)
39: throws DatabaseException {
40:
41: /* Figure out what kind of log entry this is */
42: byte curType = currentEntryHeader.getType();
43: byte curVer = LogEntryType.getVersionValue(currentEntryHeader
44: .getVersion());
45: byte ignore = 0;
46: LogEntryType lastEntryType = LogEntryType.findType(curType,
47: ignore /*curVer*/);
48:
49: /* Print out a common header for each log item */
50: StringBuffer sb = new StringBuffer();
51: sb.append("<entry lsn=\"0x").append(
52: Long.toHexString(readBufferFileNum));
53: sb.append("/0x").append(Long.toHexString(currentEntryOffset));
54: /* Version in the log not necessarily == lastEntryType.version. */
55: sb.append("\" type=\"").append(
56: lastEntryType.toStringNoVersion()).append("/").append(
57: curVer);
58: if (LogEntryType.isEntryProvisional(curType)) {
59: sb.append("\" isProvisional=\"true");
60: }
61: sb.append("\" prev=\"0x");
62: sb.append(Long.toHexString(currentEntryHeader.getPrevOffset()));
63: if (verbose) {
64: sb.append("\" size=\"").append(
65: currentEntryHeader.getItemSize());
66: sb.append("\" cksum=\"").append(
67: currentEntryHeader.getChecksum());
68: }
69: sb.append("\">");
70:
71: /* Read the entry and dump it into a string buffer. */
72: LogEntry entry = lastEntryType.getSharedLogEntry();
73: readEntry(entry, entryBuffer, true); // readFullItem
74: boolean dumpIt = true;
75: if (targetTxnIds.size() > 0) {
76: if (lastEntryType.isTransactional()) {
77: if (!targetTxnIds.contains(new Long(entry
78: .getTransactionId()))) {
79: /* Not in the list of txn ids. */
80: dumpIt = false;
81: }
82: } else {
83: /* If -tx spec'd and not a transactional entry, don't dump. */
84: dumpIt = false;
85: }
86: }
87:
88: if (dumpIt) {
89: entry.dumpEntry(sb, verbose);
90: sb.append("</entry>");
91: System.out.println(sb.toString());
92: }
93:
94: return true;
95: }
96: }
|