1 21 22 package org.apache.derby.impl.store.raw.xact; 23 24 import org.apache.derby.iapi.services.io.FormatIdUtil; 25 import org.apache.derby.iapi.services.io.StoredFormatIds; 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.store.raw.xact.TransactionId; 31 32 import org.apache.derby.iapi.services.io.CompressedNumber; 33 34 35 import java.io.ObjectOutput ; 36 import java.io.ObjectInput ; 37 import java.io.IOException ; 38 39 50 public class XactId implements TransactionId 51 { 52 55 private long id; 57 60 public XactId(long id) { 61 this.id = id; 62 } 63 64 67 68 public XactId() { super(); } 70 71 75 public void writeExternal(ObjectOutput out) throws IOException 76 { 77 CompressedNumber.writeLong(out, id); 78 } 79 80 84 public void readExternal(ObjectInput in) throws IOException 85 { 86 id = CompressedNumber.readLong(in); 87 } 88 89 92 public int getTypeFormatId() { 93 return StoredFormatIds.RAW_STORE_XACT_ID; 94 } 95 96 99 100 public int getMaxStoredSize() 101 { 102 return FormatIdUtil.getFormatIdByteLength(StoredFormatIds.RAW_STORE_XACT_ID) + 103 CompressedNumber.MAX_LONG_STORED_SIZE; 104 } 105 106 public boolean equals(Object other) { 107 if (other == this) 108 return true; 109 110 try 113 { 114 XactId oxid = (XactId)other; 115 return (id == oxid.id); 116 } 117 catch (ClassCastException cce) 118 { 119 return false; 120 } 121 } 122 123 public int hashCode() 124 { 125 return (int)id; 126 } 127 128 131 132 133 138 public static long compare(TransactionId a, TransactionId b) 139 { 140 if (a == null || b == null) 141 { 142 if (a == null) 143 return -1; 144 else if (b == null) 145 return 1; 146 else 147 return 0; 148 } 149 150 if (SanityManager.DEBUG) 151 { 152 SanityManager.ASSERT(a instanceof XactId); 153 SanityManager.ASSERT(b instanceof XactId); 154 } 155 XactId A = (XactId)a; 156 XactId B = (XactId)b; 157 158 return A.id - B.id; 159 } 160 161 protected long getId() 162 { 163 return id; 164 } 165 166 167 public String toString() 168 { 169 return Long.toString(id); 171 } 172 173 174 } 175 176 177 | Popular Tags |