KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: INDupDeleteInfo.java,v 1.11 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.DatabaseException;
14 import com.sleepycat.je.dbi.DatabaseId;
15 import com.sleepycat.je.dbi.DatabaseImpl;
16 import com.sleepycat.je.log.LogEntryType;
17 import com.sleepycat.je.log.LogException;
18 import com.sleepycat.je.log.LogManager;
19 import com.sleepycat.je.log.LogReadable;
20 import com.sleepycat.je.log.LogUtils;
21 import com.sleepycat.je.log.LogWritable;
22 import com.sleepycat.je.log.LoggableObject;
23
24 /**
25  * INDupDeleteInfo encapsulates the information logged about the removal of a
26  * child from a duplicate IN during IN compression.
27  */

28 public class INDupDeleteInfo
29     implements LoggableObject, LogReadable, LogWritable {
30
31     private long deletedNodeId;
32     private byte[] deletedMainKey;
33     private byte[] deletedDupKey;
34     private DatabaseId dbId;
35
36     /**
37      * Create a new delete info entry.
38      */

39     public INDupDeleteInfo(long deletedNodeId,
40                byte[] deletedMainKey,
41                byte[] deletedDupKey,
42                DatabaseId dbId) {
43         this.deletedNodeId = deletedNodeId;
44         this.deletedMainKey = deletedMainKey;
45         this.deletedDupKey = deletedDupKey;
46         this.dbId = dbId;
47     }
48
49     /**
50      * Used by logging system only.
51      */

52     public INDupDeleteInfo() {
53         dbId = new DatabaseId();
54     }
55
56     /*
57      * Accessors.
58      */

59     public long getDeletedNodeId() {
60         return deletedNodeId;
61     }
62
63     public byte[] getDeletedMainKey() {
64         return deletedMainKey;
65     }
66     
67     public byte[] getDeletedDupKey() {
68         return deletedDupKey;
69     }
70     
71     public DatabaseId getDatabaseId() {
72         return dbId;
73     }
74
75     /*
76      * Logging support for writing.
77      */

78
79     /*
80      * Logging support for writing.
81      */

82     public void optionalLog(LogManager logManager,
83                             DatabaseImpl dbImpl)
84         throws DatabaseException {
85
86         if (!dbImpl.isDeferredWrite()) {
87             logManager.log(this);
88         }
89     }
90
91     /**
92      * @see LoggableObject#getLogType
93      */

94     public LogEntryType getLogType() {
95         return LogEntryType.LOG_IN_DUPDELETE_INFO;
96     }
97
98     /**
99      * @see LoggableObject#marshallOutsideWriteLatch
100      * Can be marshalled outside the log write latch.
101      */

102     public boolean marshallOutsideWriteLatch() {
103         return true;
104     }
105
106     /**
107      * @see LoggableObject#countAsObsoleteWhenLogged
108      */

109     public boolean countAsObsoleteWhenLogged() {
110         return false;
111     }
112
113     /**
114      * @see LoggableObject#postLogWork
115      */

116     public void postLogWork(long justLoggedLsn) {
117     }
118
119     /**
120      * @see LoggableObject#getLogSize
121      */

122     public int getLogSize() {
123         return LogUtils.LONG_BYTES +
124             LogUtils.getByteArrayLogSize(deletedMainKey) +
125             LogUtils.getByteArrayLogSize(deletedDupKey) +
126             dbId.getLogSize();
127     }
128
129     /**
130      * @see LogWritable#writeToLog
131      */

132     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
133
134         LogUtils.writeLong(logBuffer, deletedNodeId);
135         LogUtils.writeByteArray(logBuffer, deletedMainKey);
136         LogUtils.writeByteArray(logBuffer, deletedDupKey);
137         dbId.writeToLog(logBuffer);
138     }
139
140     /**
141      * @see LogReadable#readFromLog
142      */

143     public void readFromLog(ByteBuffer JavaDoc itemBuffer, byte entryTypeVersion)
144     throws LogException {
145
146         deletedNodeId = LogUtils.readLong(itemBuffer);
147         deletedMainKey = LogUtils.readByteArray(itemBuffer);
148         deletedDupKey = LogUtils.readByteArray(itemBuffer);
149         dbId.readFromLog(itemBuffer, entryTypeVersion);
150     }
151
152     /**
153      * @see LogReadable#dumpLog
154      */

155     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
156         sb.append("<INDupDeleteEntry node=\"").append(deletedNodeId);
157         sb.append("\">");
158         sb.append(Key.dumpString(deletedMainKey, 0));
159         sb.append(Key.dumpString(deletedDupKey, 0));
160         dbId.dumpLog(sb, verbose);
161         sb.append("</INDupDeleteEntry>");
162     }
163
164     /**
165      * @see LogReadable#logEntryIsTransactional
166      */

167     public boolean logEntryIsTransactional() {
168     return false;
169     }
170
171     /**
172      * @see LogReadable#getTransactionId
173      */

174     public long getTransactionId() {
175     return 0;
176     }
177 }
178
Popular Tags