KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > tree > DeltaInfo


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

8
9 package com.sleepycat.je.tree;
10
11 import java.nio.ByteBuffer JavaDoc;
12
13 import com.sleepycat.je.log.LogException;
14 import com.sleepycat.je.log.LogReadable;
15 import com.sleepycat.je.log.LogUtils;
16 import com.sleepycat.je.log.LogWritable;
17 import com.sleepycat.je.utilint.DbLsn;
18
19 /**
20  * DeltaInfo holds the delta for one BIN entry in a partial BIN log entry.
21  * The data here is all that we need to update a BIN to its proper state.
22  */

23 public class DeltaInfo implements LogWritable, LogReadable {
24     private byte[] key;
25     private long lsn;
26     private byte state;
27           
28     DeltaInfo(byte[] key, long lsn, byte state) {
29         this.key = key;
30         this.lsn = lsn;
31         this.state = state;
32     }
33
34     /**
35      * For reading from the log only.
36      */

37     DeltaInfo() {
38         lsn = DbLsn.NULL_LSN;
39     }
40
41     /*
42      * @see com.sleepycat.je.log.LogWritable#getLogSize()
43      */

44     public int getLogSize() {
45         return
46             LogUtils.getByteArrayLogSize(key) +
47         LogUtils.getLongLogSize() + // LSN
48
1; // state
49
}
50
51     /*
52      * @see LogWritable#writeToLog(java.nio.ByteBuffer)
53      */

54     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
55         LogUtils.writeByteArray(logBuffer, key);
56     LogUtils.writeLong(logBuffer, lsn);
57         logBuffer.put(state);
58     }
59
60     /*
61      * @see com.sleepycat.je.log.LogReadable#readFromLog
62      * (java.nio.ByteBuffer)
63      */

64     public void readFromLog(ByteBuffer JavaDoc itemBuffer, byte entryTypeVersion)
65     throws LogException {
66
67         key = LogUtils.readByteArray(itemBuffer);
68     lsn = LogUtils.readLong(itemBuffer);
69         state = itemBuffer.get();
70     }
71
72     /*
73      * @see LogReadable#dumpLog(java.lang.StringBuffer)
74      */

75     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
76         sb.append(Key.dumpString(key, 0));
77     sb.append(DbLsn.toString(lsn));
78         IN.dumpDeletedState(sb, state);
79     }
80
81     /**
82      * @see LogReadable#logEntryIsTransactional
83      */

84     public boolean logEntryIsTransactional() {
85     return false;
86     }
87
88     /**
89      * @see LogReadable#getTransactionId
90      */

91     public long getTransactionId() {
92     return 0;
93     }
94
95     /**
96      * @return the Key.
97      */

98     byte[] getKey() {
99         return key;
100     }
101
102     /**
103      * @return the state flags.
104      */

105     byte getState() {
106         return state;
107     }
108
109     /**
110      * @return true if this is known to be deleted.
111      */

112     boolean isKnownDeleted() {
113         return IN.isStateKnownDeleted(state);
114     }
115
116     /**
117      * @return the LSN.
118      */

119     long getLsn() {
120         return lsn;
121     }
122 }
123
Popular Tags