1 8 9 package com.sleepycat.je.tree; 10 11 import java.nio.ByteBuffer ; 12 13 import com.sleepycat.je.dbi.MemoryBudget; 14 import com.sleepycat.je.log.LogEntryType; 15 import com.sleepycat.je.log.LogException; 16 import com.sleepycat.je.log.LogUtils; 17 18 22 public final class DupCountLN extends LN { 23 24 private static final String BEGIN_TAG = "<dupCountLN>"; 25 private static final String END_TAG = "</dupCountLN>"; 26 27 private int dupCount; 28 29 32 public DupCountLN(int count) { 33 super(new byte[0]); 34 35 41 this.dupCount = count; 42 } 43 44 47 public DupCountLN() { 48 super(); 49 dupCount = 0; 50 } 51 52 public int getDupCount() { 53 return dupCount; 54 } 55 56 public int incDupCount() { 57 dupCount++; 58 setDirty(); 59 assert dupCount >= 0; 60 return dupCount; 61 } 62 63 public int decDupCount() { 64 dupCount--; 65 setDirty(); 66 assert dupCount >= 0; 67 return dupCount; 68 } 69 70 void setDupCount(int dupCount) { 71 this.dupCount = dupCount; 72 setDirty(); 73 } 74 75 79 public boolean containsDuplicates() { 80 return true; 81 } 82 83 public boolean isDeleted() { 84 return false; 85 } 86 87 91 public long getMemorySizeIncludedByParent() { 92 return MemoryBudget.DUPCOUNTLN_OVERHEAD; 93 } 94 95 98 public void accumulateStats(TreeWalkerStatsAccumulator acc) { 99 acc.processDupCountLN(this, new Long (getNodeId())); 100 } 101 102 105 106 public String toString() { 107 return dumpString(0, true); 108 } 109 110 public String beginTag() { 111 return BEGIN_TAG; 112 } 113 114 public String endTag() { 115 return END_TAG; 116 } 117 118 public String dumpString(int nSpaces, boolean dumpTags) { 119 StringBuffer sb = new StringBuffer (); 120 if (dumpTags) { 121 sb.append(TreeUtils.indent(nSpaces)); 122 sb.append(beginTag()); 123 sb.append('\n'); 124 } 125 sb.append(TreeUtils.indent(nSpaces+2)); 126 sb.append("<count v=\"").append(dupCount).append("\"/>").append('\n'); 127 sb.append(super.dumpString(nSpaces, false)); 128 if (dumpTags) { 129 sb.append(TreeUtils.indent(nSpaces)); 130 sb.append(endTag()); 131 } 132 return sb.toString(); 133 } 134 135 138 139 142 protected LogEntryType getTransactionalLogType() { 143 return LogEntryType.LOG_DUPCOUNTLN_TRANSACTIONAL; 144 } 145 146 149 public LogEntryType getLogType() { 150 return LogEntryType.LOG_DUPCOUNTLN; 151 } 152 153 156 public int getLogSize() { 157 return super.getLogSize() + 158 LogUtils.INT_BYTES; 159 } 160 161 164 public void writeToLog(ByteBuffer logBuffer) { 165 super.writeToLog(logBuffer); 167 LogUtils.writeInt(logBuffer, dupCount); 168 } 169 170 173 public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion) 174 throws LogException { 175 176 super.readFromLog(itemBuffer, entryTypeVersion); 177 dupCount = LogUtils.readInt(itemBuffer); 178 } 179 180 183 protected void dumpLogAdditional(StringBuffer sb, boolean verbose) { 184 super.dumpLogAdditional(sb, verbose); 185 sb.append("<count v=\"").append(dupCount).append("\"/>"); 186 } 187 } 188 | Popular Tags |