KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > PrintFileReader


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: PrintFileReader.java,v 1.11 2006/10/30 21:14:20 bostic Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.io.IOException JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
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,
27                int readBufferSize,
28                long startLsn,
29                long finishLsn,
30                String JavaDoc entryTypes,
31                String JavaDoc txnIds,
32                boolean verbose)
33     throws IOException JavaDoc, DatabaseException {
34
35         super(env,
36               readBufferSize,
37               startLsn,
38               finishLsn,
39               entryTypes,
40               txnIds,
41               verbose);
42     }
43
44     /**
45      * This reader prints the log entry item.
46      */

47     protected boolean processEntry(ByteBuffer JavaDoc entryBuffer)
48         throws DatabaseException {
49
50         /* Figure out what kind of log entry this is */
51         LogEntryType lastEntryType =
52             LogEntryType.findType(currentEntryTypeNum,
53                   currentEntryTypeVersion);
54
55         /* Print out a common header for each log item */
56         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
57         sb.append("<entry lsn=\"0x").append
58             (Long.toHexString(readBufferFileNum));
59         sb.append("/0x").append
60             (Long.toHexString(currentEntryOffset));
61         sb.append("\" type=\"").append(lastEntryType);
62         if (LogEntryType.isProvisional(currentEntryTypeVersion)) {
63             sb.append("\" isProvisional=\"true");
64         }
65         sb.append("\" prev=\"0x");
66         sb.append(Long.toHexString(currentEntryPrevOffset));
67         if (verbose) {
68             sb.append("\" size=\"").append(currentEntrySize);
69             sb.append("\" cksum=\"").append(currentEntryChecksum);
70         }
71         sb.append("\">");
72
73         /* Read the entry and dump it into a string buffer. */
74     LogEntry entry = lastEntryType.getSharedLogEntry();
75         entry.readEntry(entryBuffer, currentEntrySize,
76                         currentEntryTypeVersion, true);
77     boolean dumpIt = true;
78     if (targetTxnIds.size() > 0) {
79         if (entry.isTransactional()) {
80         if (!targetTxnIds.contains
81             (new Long JavaDoc(entry.getTransactionId()))) {
82             /* Not in the list of txn ids. */
83             dumpIt = false;
84         }
85         } else {
86         /* If -tx spec'd and not a transactional entry, don't dump. */
87         dumpIt = false;
88         }
89     }
90
91     if (dumpIt) {
92         entry.dumpEntry(sb, verbose);
93         sb.append("</entry>");
94         System.out.println(sb.toString());
95     }
96         
97         return true;
98     }
99 }
100
Popular Tags