KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > entry > DeletedDupLNLogEntry


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

8
9 package com.sleepycat.je.log.entry;
10
11 import java.nio.ByteBuffer JavaDoc;
12
13 import com.sleepycat.je.DatabaseException;
14 import com.sleepycat.je.dbi.DatabaseId;
15 import com.sleepycat.je.log.LogEntryType;
16 import com.sleepycat.je.log.LogUtils;
17 import com.sleepycat.je.tree.Key;
18 import com.sleepycat.je.tree.LN;
19 import com.sleepycat.je.txn.Txn;
20
21 /**
22  * DupDeletedLNEntry encapsulates a deleted dupe LN entry. This contains all
23  * the regular transactional LN log entry fields and an extra key, which is the
24  * nulled out data field of the LN (which becomes the key in the duplicate
25  * tree.
26  */

27 public class DeletedDupLNLogEntry extends LNLogEntry {
28
29     /*
30      * Deleted duplicate LN must log an entra key in their log entries,
31      * because the data field that is the "key" in a dup tree has been
32      * nulled out because the LN is deleted.
33      */

34     private byte[] dataAsKey;
35
36     /**
37      * Constructor to read an entry.
38      */

39     public DeletedDupLNLogEntry(boolean isTransactional) {
40         super(com.sleepycat.je.tree.LN.class, isTransactional);
41     }
42
43     /**
44      * Constructor to make an object that can write this entry.
45      */

46     public DeletedDupLNLogEntry(LogEntryType entryType,
47                                 LN ln,
48                                 DatabaseId dbId,
49                                 byte[] key,
50                                 byte[] dataAsKey,
51                                 long abortLsn,
52                                 boolean abortKnownDeleted,
53                                 Txn txn) {
54         super(entryType, ln, dbId, key, abortLsn, abortKnownDeleted, txn);
55         this.dataAsKey = dataAsKey;
56     }
57
58     /**
59      * Extends its super class to read in the extra dup key.
60      * @see LNLogEntry#readEntry
61      */

62     public void readEntry(ByteBuffer JavaDoc entryBuffer,
63               int entrySize,
64                           byte entryTypeVersion,
65               boolean readFullItem)
66         throws DatabaseException {
67
68         super.readEntry(entryBuffer, entrySize,
69                         entryTypeVersion, readFullItem);
70
71         /* Key */
72         if (readFullItem) {
73             dataAsKey = LogUtils.readByteArray(entryBuffer);
74         } else {
75             /* The LNLogEntry base class has already positioned to the end. */
76             dataAsKey = null;
77         }
78     }
79
80     /**
81      * Extends super class to dump out extra key.
82      * @see LNLogEntry#dumpEntry
83      */

84     public StringBuffer JavaDoc dumpEntry(StringBuffer JavaDoc sb, boolean verbose) {
85         super.dumpEntry(sb, verbose);
86         sb.append(Key.dumpString(dataAsKey, 0));
87         return sb;
88     }
89     
90     /*
91      * Writing support
92      */

93
94     /**
95      * Extend super class to add in extra key.
96      * @see LNLogEntry#getLogSize
97      */

98     public int getLogSize() {
99         return super.getLogSize() +
100         LogUtils.getByteArrayLogSize(dataAsKey);
101     }
102
103     /**
104      * @see LNLogEntry#writeToLog
105      */

106     public void writeToLog(ByteBuffer JavaDoc destBuffer) {
107         super.writeToLog(destBuffer);
108         LogUtils.writeByteArray(destBuffer, dataAsKey);
109     }
110
111     /*
112      * Accessors
113      */

114
115     /**
116      * Get the data-as-key out of the entry.
117      */

118     public byte[] getDupKey() {
119         return dataAsKey;
120     }
121 }
122
Popular Tags