1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.store.raw.ContainerKey; 25 import org.apache.derby.iapi.store.raw.PageKey; 26 import org.apache.derby.iapi.services.locks.Latch; 27 28 import org.apache.derby.iapi.store.raw.RowLock; 29 import org.apache.derby.iapi.store.raw.RecordHandle; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 import org.apache.derby.iapi.services.locks.VirtualLockTable; 33 34 import org.apache.derby.catalog.UUID; 35 import java.util.Hashtable ; 36 37 47 public final class RecordId implements RecordHandle { 48 49 53 private final PageKey pageId; 54 55 59 private final int recordId; 60 61 64 transient private int slotNumberHint; 65 66 public RecordId(ContainerKey container, long pageNumber, int recordId) { 67 this.pageId = new PageKey(container, pageNumber); 68 this.recordId = recordId; 69 70 } 73 74 public RecordId(PageKey pageId, int recordId) { 75 this.pageId = pageId; 76 this.recordId = recordId; 77 78 } 81 82 public RecordId(PageKey pageId, int recordId, int current_slot) { 83 this.pageId = pageId; 84 this.recordId = recordId; 85 this.slotNumberHint = current_slot; 86 } 87 88 91 92 100 public int getId() { 101 return recordId; 102 } 103 104 112 113 public long getPageNumber() { 114 return pageId.getPageNumber(); 115 } 116 117 public Object getPageId() { 118 return pageId; 119 } 120 121 public ContainerKey getContainerId() { 122 return pageId.getContainerId(); 123 } 124 125 126 137 public int getSlotNumberHint() 138 { 139 return(slotNumberHint); 140 } 141 142 145 146 154 public void lockEvent(Latch lockInfo) { 155 } 156 157 158 169 public boolean requestCompatible( 170 Object requestedQualifier, 171 Object grantedQualifier) 172 { 173 174 if (SanityManager.DEBUG) { 175 SanityManager.ASSERT((requestedQualifier == RowLock.RS2) || 176 (requestedQualifier == RowLock.RS3) || 177 (requestedQualifier == RowLock.RU2) || 178 (requestedQualifier == RowLock.RU3) || 179 (requestedQualifier == RowLock.RIP) || 180 (requestedQualifier == RowLock.RI) || 181 (requestedQualifier == RowLock.RX2) || 182 (requestedQualifier == RowLock.RX3)); 183 SanityManager.ASSERT((grantedQualifier == RowLock.RS2) || 184 (grantedQualifier == RowLock.RS3) || 185 (grantedQualifier == RowLock.RU2) || 186 (grantedQualifier == RowLock.RU3) || 187 (grantedQualifier == RowLock.RIP) || 188 (grantedQualifier == RowLock.RI) || 189 (grantedQualifier == RowLock.RX2) || 190 (grantedQualifier == RowLock.RX3)); 191 } 192 193 RowLock rlRequested = (RowLock) requestedQualifier; 194 RowLock rlGranted = (RowLock) grantedQualifier; 195 196 return(rlRequested.isCompatible(rlGranted)); 197 } 198 199 210 public boolean lockerAlwaysCompatible() { 211 return true; 212 } 213 214 222 public void unlockEvent(Latch lockInfo) { 223 } 224 225 228 229 234 public boolean equals(Object ref) { 235 236 if (!(ref instanceof RecordId)) 237 return false; 238 239 RecordId other = (RecordId) ref; 240 241 return ((recordId == other.recordId) 242 && pageId.equals(other.pageId)); 243 } 244 245 250 public int hashCode() { 251 252 return (int) recordId ^ pageId.hashCode(); 253 } 254 255 public String toString() 256 { 257 if (SanityManager.DEBUG) 258 { 259 return "Record id=" + recordId + " " + pageId.toString(); 260 } 261 else 262 { 263 return(null); 264 } 265 266 } 267 268 271 public boolean lockAttributes(int flag, Hashtable attributes) 272 { 273 274 if (SanityManager.DEBUG) 275 { 276 SanityManager.ASSERT(attributes != null, 277 "cannot call lockProperties with null attribute list"); 278 SanityManager.ASSERT(pageId != null, 279 "RecordId PageId is null"); 280 } 281 282 if ((flag & VirtualLockTable.TABLE_AND_ROWLOCK) == 0) 283 return false; 284 285 attributes.put(VirtualLockTable.CONTAINERID, 286 new Long (pageId.getContainerId().getContainerId())); 287 288 attributes.put(VirtualLockTable.LOCKNAME, 289 "(" + pageId.getPageNumber() + "," + recordId + ")"); 290 291 attributes.put(VirtualLockTable.LOCKTYPE, "ROW"); 292 293 299 return true; 300 } 301 302 } 303 | Popular Tags |