--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.store.raw.ContainerKey\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.store.raw;\r
+\r
+import org.apache.derby.iapi.util.Matchable;\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.services.locks.Lockable;\r
+import org.apache.derby.iapi.services.locks.Latch;\r
+import org.apache.derby.iapi.services.locks.VirtualLockTable;\r
+\r
+import java.util.Hashtable;\r
+\r
+/**\r
+ A key that identifies a Container within the RawStore.\r
+ <BR> MT - Immutable\r
+*/\r
+public final class ContainerKey implements Matchable, Lockable\r
+{\r
+ private final long segmentId; // segment identifier\r
+ private final long containerId; // container identifier\r
+\r
+ /**\r
+ Create a new ContainerKey\r
+ */\r
+ public ContainerKey(long segmentId, long containerId) {\r
+ this.segmentId = segmentId;\r
+ this.containerId = containerId;\r
+ }\r
+\r
+ /**\r
+ Return my identifier within the segment\r
+ */\r
+ public long getContainerId() {\r
+ return containerId;\r
+ }\r
+\r
+ /**\r
+ Return my segment identifier\r
+ */\r
+ public long getSegmentId() {\r
+ return segmentId;\r
+ }\r
+\r
+ /*\r
+ ** Methods to read and write ContainerKeys.\r
+ */\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException \r
+ {\r
+ CompressedNumber.writeLong(out, segmentId);\r
+ CompressedNumber.writeLong(out, containerId);\r
+ }\r
+\r
+ public static ContainerKey read(ObjectInput in) throws IOException\r
+ {\r
+ long sid = CompressedNumber.readLong(in);\r
+ long cid = CompressedNumber.readLong(in);\r
+\r
+ return new ContainerKey(sid, cid);\r
+ }\r
+\r
+ /*\r
+ ** Methods of Object\r
+ */\r
+\r
+ public boolean equals(Object other) {\r
+ if (other == this)\r
+ return true;\r
+\r
+ if (other instanceof ContainerKey) {\r
+ ContainerKey otherKey = (ContainerKey) other;\r
+\r
+ return (containerId == otherKey.containerId) &&\r
+ (segmentId == otherKey.segmentId);\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public int hashCode() {\r
+\r
+ return (int) (segmentId ^ containerId);\r
+ }\r
+\r
+ public String toString() {\r
+\r
+ return "Container(" + segmentId + ", " + containerId + ")";\r
+ }\r
+\r
+ /*\r
+ ** methods of Matchable\r
+ */\r
+\r
+ public boolean match(Object key) {\r
+ // instance of ContainerKey?\r
+ if (equals(key))\r
+ return true;\r
+\r
+ if (key instanceof PageKey)\r
+ return equals(((PageKey) key).getContainerId());\r
+\r
+ if (key instanceof RecordHandle) {\r
+ return equals(((RecordHandle) key).getContainerId());\r
+ }\r
+ return false;\r
+ }\r
+ /*\r
+ ** Methods of Lockable\r
+ */\r
+\r
+ public void lockEvent(Latch lockInfo) {\r
+ }\r
+ \r
+\r
+ public boolean requestCompatible(Object requestedQualifier, Object grantedQualifier) {\r
+ if (SanityManager.DEBUG) {\r
+ SanityManager.ASSERT(requestedQualifier instanceof ContainerLock);\r
+ SanityManager.ASSERT(grantedQualifier instanceof ContainerLock);\r
+ }\r
+\r
+ ContainerLock clRequested = (ContainerLock) requestedQualifier;\r
+ ContainerLock clGranted = (ContainerLock) grantedQualifier;\r
+\r
+ return clRequested.isCompatible(clGranted);\r
+ }\r
+\r
+ /**\r
+ This method will only be called if requestCompatible returned false.\r
+ This results from two cases, some other compatabilty space has some\r
+ lock that would conflict with the request, or this compatability space\r
+ has a lock tha\r
+ */\r
+ public boolean lockerAlwaysCompatible() {\r
+ return true;\r
+ }\r
+\r
+ public void unlockEvent(Latch lockInfo) {\r
+ }\r
+\r
+ /**\r
+ This lockable wants to participate in the Virtual Lock table.\r
+ */\r
+ public boolean lockAttributes(int flag, Hashtable attributes)\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(attributes != null, \r
+ "cannot call lockProperties with null attribute list");\r
+ }\r
+\r
+ if ((flag & VirtualLockTable.TABLE_AND_ROWLOCK) == 0)\r
+ return false;\r
+\r
+ attributes.put(VirtualLockTable.CONTAINERID, \r
+ new Long(getContainerId()));\r
+ attributes.put(VirtualLockTable.LOCKNAME, "Tablelock");\r
+ attributes.put(VirtualLockTable.LOCKTYPE, "TABLE");\r
+\r
+ // attributes.put(VirtualLockTable.SEGMENTID, new Long(identity.getSegmentId()));\r
+\r
+ return true;\r
+ }\r
+}\r