1 21 22 package org.apache.derby.iapi.store.raw; 23 24 import org.apache.derby.iapi.util.Matchable; 25 import org.apache.derby.iapi.services.io.CompressedNumber; 26 27 import java.io.ObjectOutput ; 28 import java.io.ObjectInput ; 29 import java.io.IOException ; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 import org.apache.derby.iapi.services.locks.Lockable; 33 import org.apache.derby.iapi.services.locks.Latch; 34 import org.apache.derby.iapi.services.locks.VirtualLockTable; 35 36 import java.util.Hashtable ; 37 38 42 public final class ContainerKey implements Matchable, Lockable 43 { 44 private final long segmentId; private final long containerId; 47 50 public ContainerKey(long segmentId, long containerId) { 51 this.segmentId = segmentId; 52 this.containerId = containerId; 53 } 54 55 58 public long getContainerId() { 59 return containerId; 60 } 61 62 65 public long getSegmentId() { 66 return segmentId; 67 } 68 69 72 73 public void writeExternal(ObjectOutput out) throws IOException 74 { 75 CompressedNumber.writeLong(out, segmentId); 76 CompressedNumber.writeLong(out, containerId); 77 } 78 79 public static ContainerKey read(ObjectInput in) throws IOException 80 { 81 long sid = CompressedNumber.readLong(in); 82 long cid = CompressedNumber.readLong(in); 83 84 return new ContainerKey(sid, cid); 85 } 86 87 90 91 public boolean equals(Object other) { 92 if (other == this) 93 return true; 94 95 if (other instanceof ContainerKey) { 96 ContainerKey otherKey = (ContainerKey) other; 97 98 return (containerId == otherKey.containerId) && 99 (segmentId == otherKey.segmentId); 100 } else { 101 return false; 102 } 103 } 104 105 public int hashCode() { 106 107 return (int) (segmentId ^ containerId); 108 } 109 110 public String toString() { 111 112 return "Container(" + segmentId + ", " + containerId + ")"; 113 } 114 115 118 119 public boolean match(Object key) { 120 if (equals(key)) 122 return true; 123 124 if (key instanceof PageKey) 125 return equals(((PageKey) key).getContainerId()); 126 127 if (key instanceof RecordHandle) { 128 return equals(((RecordHandle) key).getContainerId()); 129 } 130 return false; 131 } 132 135 136 public void lockEvent(Latch lockInfo) { 137 } 138 139 140 public boolean requestCompatible(Object requestedQualifier, Object grantedQualifier) { 141 if (SanityManager.DEBUG) { 142 SanityManager.ASSERT(requestedQualifier instanceof ContainerLock); 143 SanityManager.ASSERT(grantedQualifier instanceof ContainerLock); 144 } 145 146 ContainerLock clRequested = (ContainerLock) requestedQualifier; 147 ContainerLock clGranted = (ContainerLock) grantedQualifier; 148 149 return clRequested.isCompatible(clGranted); 150 } 151 152 158 public boolean lockerAlwaysCompatible() { 159 return true; 160 } 161 162 public void unlockEvent(Latch lockInfo) { 163 } 164 165 168 public boolean lockAttributes(int flag, Hashtable attributes) 169 { 170 if (SanityManager.DEBUG) 171 { 172 SanityManager.ASSERT(attributes != null, 173 "cannot call lockProperties with null attribute list"); 174 } 175 176 if ((flag & VirtualLockTable.TABLE_AND_ROWLOCK) == 0) 177 return false; 178 179 attributes.put(VirtualLockTable.CONTAINERID, 180 new Long (getContainerId())); 181 attributes.put(VirtualLockTable.LOCKNAME, "Tablelock"); 182 attributes.put(VirtualLockTable.LOCKTYPE, "TABLE"); 183 184 186 return true; 187 } 188 } 189 | Popular Tags |