--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.services.locks.ShExLockable\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.services.locks;\r
+\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 org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.util.Hashtable;\r
+\r
+public class ShExLockable implements Lockable\r
+{\r
+\r
+ public ShExLockable()\r
+ { \r
+ }\r
+\r
+ /** @see Lockable#lockerAlwaysCompatible */\r
+ public boolean lockerAlwaysCompatible()\r
+ {\r
+ return true;\r
+ }\r
+\r
+ /** @see Lockable#requestCompatible */\r
+ public boolean requestCompatible(Object requestedQualifier,\r
+ Object grantedQualifier)\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ if (!(requestedQualifier instanceof ShExQual))\r
+ SanityManager.THROWASSERT(\r
+ "requestedQualifier is a " +\r
+ requestedQualifier.getClass().getName() +\r
+ "instead of a ShExQual.");\r
+\r
+ if (!(grantedQualifier instanceof ShExQual))\r
+ SanityManager.THROWASSERT(\r
+ "grantedQualifier is a " +\r
+ grantedQualifier.getClass().getName() +\r
+ "instead of a ShExQual.");\r
+ }\r
+\r
+ ShExQual requested = (ShExQual) requestedQualifier;\r
+ ShExQual granted = (ShExQual) grantedQualifier;\r
+\r
+ return (requested.getLockState() == ShExQual.SHARED) &&\r
+ (granted.getLockState() == ShExQual.SHARED);\r
+ }\r
+\r
+ /** @see Lockable#lockEvent */\r
+ public void lockEvent(Latch lockInfo)\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ if (!(lockInfo.getQualifier() instanceof ShExQual))\r
+ SanityManager.THROWASSERT("qualifier is a " + lockInfo.getQualifier().getClass().getName() +\r
+ "instead of a ShExQual.");\r
+ }\r
+ }\r
+\r
+ /** @see Lockable#unlockEvent */\r
+ public void unlockEvent(Latch lockInfo)\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ if (!(lockInfo.getQualifier() instanceof ShExQual))\r
+ SanityManager.THROWASSERT("qualifier is a " + lockInfo.getQualifier().getClass().getName() +\r
+ "instead of a ShExQual.");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * This lockable want to participate in the Virtual LockTable\r
+ * when we want to print LATCH information.\r
+ * Any lockable object which DOES NOT want to participate should\r
+ * override this function.\r
+ */\r
+ public boolean lockAttributes(int flag, Hashtable attributes)\r
+ {\r
+ if((flag & VirtualLockTable.SHEXLOCK) == 0)\r
+ return false;\r
+ // No containerId, but need something in there so it can print\r
+ attributes.put(VirtualLockTable.CONTAINERID, new Long(-1) ); \r
+\r
+ attributes.put(VirtualLockTable.LOCKNAME, this.toString() );\r
+\r
+ attributes.put(VirtualLockTable.LOCKTYPE, "ShExLockable");\r
+\r
+ return true;\r
+ }\r
+\r
+}\r