001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: INDupDeleteInfo.java,v 1.12.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.DatabaseException;
014: import com.sleepycat.je.dbi.DatabaseId;
015: import com.sleepycat.je.dbi.DatabaseImpl;
016: import com.sleepycat.je.log.LogEntryType;
017: import com.sleepycat.je.log.LogException;
018: import com.sleepycat.je.log.LogManager;
019: import com.sleepycat.je.log.LogUtils;
020: import com.sleepycat.je.log.Loggable;
021: import com.sleepycat.je.log.entry.SingleItemEntry;
022:
023: /**
024: * INDupDeleteInfo encapsulates the information logged about the removal of a
025: * child from a duplicate IN during IN compression.
026: */
027: public class INDupDeleteInfo implements Loggable {
028:
029: private long deletedNodeId;
030: private byte[] deletedMainKey;
031: private byte[] deletedDupKey;
032: private DatabaseId dbId;
033:
034: /**
035: * Create a new delete info entry.
036: */
037: public INDupDeleteInfo(long deletedNodeId, byte[] deletedMainKey,
038: byte[] deletedDupKey, DatabaseId dbId) {
039: this .deletedNodeId = deletedNodeId;
040: this .deletedMainKey = deletedMainKey;
041: this .deletedDupKey = deletedDupKey;
042: this .dbId = dbId;
043: }
044:
045: /**
046: * Used by logging system only.
047: */
048: public INDupDeleteInfo() {
049: dbId = new DatabaseId();
050: }
051:
052: /*
053: * Accessors.
054: */
055: public long getDeletedNodeId() {
056: return deletedNodeId;
057: }
058:
059: public byte[] getDeletedMainKey() {
060: return deletedMainKey;
061: }
062:
063: public byte[] getDeletedDupKey() {
064: return deletedDupKey;
065: }
066:
067: public DatabaseId getDatabaseId() {
068: return dbId;
069: }
070:
071: /*
072: * Logging support for writing.
073: */
074:
075: /*
076: * Logging support for writing.
077: */
078: public void optionalLog(LogManager logManager, DatabaseImpl dbImpl)
079: throws DatabaseException {
080:
081: if (!dbImpl.isDeferredWrite()) {
082: logManager.log(new SingleItemEntry(
083: LogEntryType.LOG_IN_DUPDELETE_INFO, this ));
084: }
085: }
086:
087: /**
088: * @see Loggable#getLogSize
089: */
090: public int getLogSize() {
091: return LogUtils.LONG_BYTES
092: + LogUtils.getByteArrayLogSize(deletedMainKey)
093: + LogUtils.getByteArrayLogSize(deletedDupKey)
094: + dbId.getLogSize();
095: }
096:
097: /**
098: * @see Loggable#writeToLog
099: */
100: public void writeToLog(ByteBuffer logBuffer) {
101:
102: LogUtils.writeLong(logBuffer, deletedNodeId);
103: LogUtils.writeByteArray(logBuffer, deletedMainKey);
104: LogUtils.writeByteArray(logBuffer, deletedDupKey);
105: dbId.writeToLog(logBuffer);
106: }
107:
108: /**
109: * @see Loggable#readFromLog
110: */
111: public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
112: throws LogException {
113:
114: deletedNodeId = LogUtils.readLong(itemBuffer);
115: deletedMainKey = LogUtils.readByteArray(itemBuffer);
116: deletedDupKey = LogUtils.readByteArray(itemBuffer);
117: dbId.readFromLog(itemBuffer, entryTypeVersion);
118: }
119:
120: /**
121: * @see Loggable#dumpLog
122: */
123: public void dumpLog(StringBuffer sb, boolean verbose) {
124: sb.append("<INDupDeleteEntry node=\"").append(deletedNodeId);
125: sb.append("\">");
126: sb.append(Key.dumpString(deletedMainKey, 0));
127: sb.append(Key.dumpString(deletedDupKey, 0));
128: dbId.dumpLog(sb, verbose);
129: sb.append("</INDupDeleteEntry>");
130: }
131:
132: /**
133: * @see Loggable#getTransactionId
134: */
135: public long getTransactionId() {
136: return 0;
137: }
138: }
|