001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: NameLN.java,v 1.19.2.3 2008/01/07 15:14:16 cwl Exp $
007: */
008:
009: package com.sleepycat.je.tree;
010:
011: import java.nio.ByteBuffer;
012:
013: import com.sleepycat.je.dbi.DatabaseId;
014: import com.sleepycat.je.log.LogEntryType;
015: import com.sleepycat.je.log.LogException;
016: import com.sleepycat.je.log.LogUtils;
017:
018: /**
019: * A NameLN represents a Leaf Node in the name->database id mapping tree.
020: */
021: public final class NameLN extends LN {
022:
023: private static final String BEGIN_TAG = "<nameLN>";
024: private static final String END_TAG = "</nameLN>";
025:
026: private DatabaseId id;
027: private boolean deleted;
028:
029: /**
030: * In the ideal world, we'd have a base LN class so that this NameLN
031: * doesn't have a superfluous data field, but we want to optimize the LN
032: * class for size and speed right now.
033: */
034: public NameLN(DatabaseId id) {
035: super (new byte[0]);
036: this .id = id;
037: deleted = false;
038: }
039:
040: /**
041: * Create an empty NameLN, to be filled in from the log.
042: */
043: public NameLN() {
044: super ();
045: id = new DatabaseId();
046: }
047:
048: public boolean isDeleted() {
049: return deleted;
050: }
051:
052: void makeDeleted() {
053: deleted = true;
054: }
055:
056: public DatabaseId getId() {
057: return id;
058: }
059:
060: public void setId(DatabaseId id) {
061: this .id = id;
062: }
063:
064: /*
065: * Dumping
066: */
067:
068: public String toString() {
069: return dumpString(0, true);
070: }
071:
072: public String beginTag() {
073: return BEGIN_TAG;
074: }
075:
076: public String endTag() {
077: return END_TAG;
078: }
079:
080: public String dumpString(int nSpaces, boolean dumpTags) {
081: StringBuffer sb = new StringBuffer();
082: sb.append(super .dumpString(nSpaces, dumpTags));
083: sb.append('\n');
084: sb.append(TreeUtils.indent(nSpaces));
085: sb.append("<deleted val=\"").append(Boolean.toString(deleted));
086: sb.append("\">");
087: sb.append('\n');
088: sb.append(TreeUtils.indent(nSpaces));
089: sb.append("<id val=\"").append(id);
090: sb.append("\">");
091: sb.append('\n');
092: return sb.toString();
093: }
094:
095: /*
096: * Logging
097: */
098:
099: /**
100: * Log type for transactional entries.
101: */
102: protected LogEntryType getTransactionalLogType() {
103: return LogEntryType.LOG_NAMELN_TRANSACTIONAL;
104: }
105:
106: /**
107: * @see Node#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 super .getLogSize() + // superclass
118: id.getLogSize() + // id
119: LogUtils.getBooleanLogSize(); // deleted flag
120: }
121:
122: /**
123: * @see LN#writeToLog
124: */
125: public void writeToLog(ByteBuffer logBuffer) {
126: /* Ask ancestors to write to log. */
127: super .writeToLog(logBuffer); // super class
128: id.writeToLog(logBuffer); // id
129: LogUtils.writeBoolean(logBuffer, deleted); // deleted flag
130: }
131:
132: /**
133: * @see LN#readFromLog
134: */
135: public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
136: throws LogException {
137:
138: super .readFromLog(itemBuffer, entryTypeVersion); // super class
139: id.readFromLog(itemBuffer, entryTypeVersion); // id
140: deleted = LogUtils.readBoolean(itemBuffer); // deleted flag
141: }
142:
143: /**
144: * Dump additional fields. Done this way so the additional info can be
145: * within the XML tags defining the dumped log entry.
146: */
147: protected void dumpLogAdditional(StringBuffer sb, boolean verbose) {
148: id.dumpLog(sb, true);
149: }
150: }
|