1 8 9 package com.sleepycat.je.dbi; 10 11 import java.io.UnsupportedEncodingException ; 12 import java.nio.ByteBuffer ; 13 14 import com.sleepycat.je.DatabaseException; 15 import com.sleepycat.je.log.LogReadable; 16 import com.sleepycat.je.log.LogUtils; 17 import com.sleepycat.je.log.LogWritable; 18 19 22 public class DatabaseId implements Comparable , LogWritable, LogReadable { 23 24 27 public static final int LOG_SIZE = LogUtils.INT_BYTES; 28 29 32 private int id; 33 34 37 public DatabaseId(int id) { 38 this.id = id; 39 } 40 41 44 public DatabaseId() { 45 } 46 47 50 public int getId() { 51 return id; 52 } 53 54 57 public byte[] getBytes() 58 throws DatabaseException { 59 60 try { 61 return toString().getBytes("UTF-8"); 62 } catch (UnsupportedEncodingException UEE) { 63 throw new DatabaseException(UEE); 64 } 65 } 66 67 70 public boolean equals(Object obj) { 71 if (this == obj) { 72 return true; 73 } 74 75 if (!(obj instanceof DatabaseId)) { 76 return false; 77 } 78 79 return ((DatabaseId) obj).id == id; 80 } 81 82 public int hashCode() { 83 return id; 84 } 85 86 public String toString() { 87 return Integer.toString(id); 88 } 89 90 93 public int compareTo(Object o) { 94 if (o == null) { 95 throw new NullPointerException (); 96 } 97 98 DatabaseId argId = (DatabaseId) o; 99 if (id == argId.id) { 100 return 0; 101 } else if (id > argId.id) { 102 return 1; 103 } else { 104 return -1; 105 } 106 } 107 108 111 112 115 public int getLogSize() { 116 return LOG_SIZE; 117 } 118 119 122 public void writeToLog(ByteBuffer logBuffer) { 123 LogUtils.writeInt(logBuffer, id); 124 } 125 126 129 public void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion) { 130 id = LogUtils.readInt(itemBuffer); 131 } 132 133 136 public void dumpLog(StringBuffer sb, boolean verbose) { 137 sb.append("<dbId id=\""); 138 sb.append(id); 139 sb.append("\"/>"); 140 } 141 142 145 public boolean logEntryIsTransactional() { 146 return false; 147 } 148 149 152 public long getTransactionId() { 153 return 0; 154 } 155 } 156 | Popular Tags |