001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: DeletedDupLNLogEntry.java,v 1.26.2.3 2008/01/07 15:14:13 cwl Exp $
007: */
008:
009: package com.sleepycat.je.log.entry;
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.log.LogEntryHeader;
016: import com.sleepycat.je.log.LogEntryType;
017: import com.sleepycat.je.log.LogUtils;
018: import com.sleepycat.je.tree.Key;
019: import com.sleepycat.je.tree.LN;
020: import com.sleepycat.je.txn.Txn;
021:
022: /**
023: * DupDeletedLNEntry encapsulates a deleted dupe LN entry. This contains all
024: * the regular transactional LN log entry fields and an extra key, which is the
025: * nulled out data field of the LN (which becomes the key in the duplicate
026: * tree.
027: */
028: public class DeletedDupLNLogEntry extends LNLogEntry {
029:
030: /*
031: * Deleted duplicate LN must log an entra key in their log entries,
032: * because the data field that is the "key" in a dup tree has been
033: * nulled out because the LN is deleted.
034: */
035: private byte[] dataAsKey;
036:
037: /**
038: * Constructor to read an entry.
039: */
040: public DeletedDupLNLogEntry() {
041: super (com.sleepycat.je.tree.LN.class);
042: }
043:
044: /**
045: * Constructor to make an object that can write this entry.
046: */
047: public DeletedDupLNLogEntry(LogEntryType entryType, LN ln,
048: DatabaseId dbId, byte[] key, byte[] dataAsKey,
049: long abortLsn, boolean abortKnownDeleted, Txn txn) {
050: super (entryType, ln, dbId, key, abortLsn, abortKnownDeleted,
051: txn);
052: this .dataAsKey = dataAsKey;
053: }
054:
055: /**
056: * Extends its super class to read in the extra dup key.
057: * @see LNLogEntry#readEntry
058: */
059: public void readEntry(LogEntryHeader header,
060: ByteBuffer entryBuffer, boolean readFullItem)
061: throws DatabaseException {
062:
063: super .readEntry(header, entryBuffer, readFullItem);
064:
065: /* Key */
066: if (readFullItem) {
067: dataAsKey = LogUtils.readByteArray(entryBuffer);
068: } else {
069: /* The LNLogEntry base class has already positioned to the end. */
070: dataAsKey = null;
071: }
072: }
073:
074: /**
075: * Extends super class to dump out extra key.
076: * @see LNLogEntry#dumpEntry
077: */
078: public StringBuffer dumpEntry(StringBuffer sb, boolean verbose) {
079: super .dumpEntry(sb, verbose);
080: sb.append(Key.dumpString(dataAsKey, 0));
081: return sb;
082: }
083:
084: /*
085: * Writing support
086: */
087:
088: /**
089: * Extend super class to add in extra key.
090: * @see LNLogEntry#getSize
091: */
092: public int getSize() {
093: return super .getSize()
094: + LogUtils.getByteArrayLogSize(dataAsKey);
095: }
096:
097: /**
098: * @see LogEntry#writeToLog
099: */
100: public void writeEntry(LogEntryHeader header, ByteBuffer destBuffer) {
101: super .writeEntry(header, destBuffer);
102: LogUtils.writeByteArray(destBuffer, dataAsKey);
103: }
104:
105: /*
106: * Accessors
107: */
108:
109: /**
110: * Get the data-as-key out of the entry.
111: */
112: public byte[] getDupKey() {
113: return dataAsKey;
114: }
115: }
|