KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: NameLN.java,v 1.18 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.dbi.DatabaseId;
14 import com.sleepycat.je.log.LogEntryType;
15 import com.sleepycat.je.log.LogException;
16 import com.sleepycat.je.log.LogUtils;
17
18 /**
19  * A NameLN represents a Leaf Node in the name->database id mapping tree.
20  */

21 public final class NameLN extends LN {
22
23     private static final String JavaDoc BEGIN_TAG = "<nameLN>";
24     private static final String JavaDoc END_TAG = "</nameLN>";
25
26     private DatabaseId id;
27     private boolean deleted;
28
29     /**
30      * In the ideal world, we'd have a base LN class so that this NameLN
31      * doesn't have a superfluous data field, but we want to optimize the LN
32      * class for size and speed right now.
33      */

34     public NameLN(DatabaseId id) {
35         super(new byte[0]);
36         this.id = id;
37         deleted = false;
38     }
39
40     /**
41      * Create an empty NameLN, to be filled in from the log.
42      */

43     public NameLN() {
44         super();
45         id = new DatabaseId();
46     }
47
48     public boolean isDeleted() {
49         return deleted;
50     }
51
52     void makeDeleted() {
53         deleted = true;
54     }
55
56     public DatabaseId getId() {
57         return id;
58     }
59
60     public void setId(DatabaseId id) {
61         this.id = id;
62     }
63
64     /*
65      * Dumping
66      */

67
68     public String JavaDoc toString() {
69         return dumpString(0, true);
70     }
71     
72     public String JavaDoc beginTag() {
73         return BEGIN_TAG;
74     }
75
76     public String JavaDoc endTag() {
77         return END_TAG;
78     }
79
80     public String JavaDoc dumpString(int nSpaces, boolean dumpTags) {
81         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
82         sb.append(super.dumpString(nSpaces, dumpTags));
83         sb.append('\n');
84         sb.append(TreeUtils.indent(nSpaces));
85         sb.append("<deleted val=\"").append(Boolean.toString(deleted));
86         sb.append("\">");
87         sb.append('\n');
88         sb.append(TreeUtils.indent(nSpaces));
89         sb.append("<id val=\"").append(id);
90         sb.append("\">");
91         sb.append('\n');
92         return sb.toString();
93     }
94
95     /*
96      * Logging
97      */

98
99     /**
100      * Log type for transactional entries.
101      */

102     protected LogEntryType getTransactionalLogType() {
103         return LogEntryType.LOG_NAMELN_TRANSACTIONAL;
104     }
105
106     /**
107      * @see LN#getLogType
108      */

109     public LogEntryType getLogType() {
110         return LogEntryType.LOG_NAMELN;
111     }
112
113     /**
114      * @see LN#getLogSize
115      */

116     public int getLogSize() {
117         return
118             super.getLogSize() + // superclass
119
id.getLogSize() + // id
120
LogUtils.getBooleanLogSize(); // deleted flag
121
}
122
123     /**
124      * @see LN#writeToLog
125      */

126     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
127         /* Ask ancestors to write to log. */
128         super.writeToLog(logBuffer); // super class
129
id.writeToLog(logBuffer); // id
130
LogUtils.writeBoolean(logBuffer, deleted); // deleted flag
131
}
132
133     /**
134      * @see LN#readFromLog
135      */

136     public void readFromLog(ByteBuffer JavaDoc itemBuffer, byte entryTypeVersion)
137         throws LogException {
138
139         super.readFromLog(itemBuffer, entryTypeVersion); // super class
140
id.readFromLog(itemBuffer, entryTypeVersion); // id
141
deleted = LogUtils.readBoolean(itemBuffer); // deleted flag
142
}
143
144     /**
145      * Dump additional fields. Done this way so the additional info can be
146      * within the XML tags defining the dumped log entry.
147      */

148     protected void dumpLogAdditional(StringBuffer JavaDoc sb, boolean verbose) {
149         id.dumpLog(sb, true);
150     }
151 }
152
Popular Tags