Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / access / btree / index / B2IRowLockingRR.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLockingRR.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/btree/index/B2IRowLockingRR.java
new file mode 100644 (file)
index 0000000..20109be
--- /dev/null
@@ -0,0 +1,161 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.btree.index.B2IRowLockingRR\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.impl.store.access.btree.index;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.error.StandardException; \r
+\r
+import org.apache.derby.iapi.store.access.ConglomerateController;\r
+import org.apache.derby.iapi.types.RowLocation;\r
+\r
+import org.apache.derby.iapi.store.raw.FetchDescriptor;\r
+import org.apache.derby.iapi.store.raw.LockingPolicy;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.impl.store.access.btree.BTree;\r
+import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;\r
+import org.apache.derby.impl.store.access.btree.BTreeRowPosition;\r
+import org.apache.derby.impl.store.access.btree.OpenBTree;\r
+\r
+/**\r
+\r
+**/\r
+\r
+class B2IRowLockingRR extends B2IRowLocking3 implements BTreeLockingPolicy\r
+{\r
+\r
+    /**************************************************************************\r
+     * Constructors for This class:\r
+     **************************************************************************\r
+     */\r
+    B2IRowLockingRR(\r
+    Transaction             rawtran,\r
+    int                     lock_level,\r
+    LockingPolicy           locking_policy,\r
+    ConglomerateController  base_cc,\r
+    OpenBTree               open_btree)\r
+    {\r
+        super(rawtran, lock_level, locking_policy, base_cc, open_btree);\r
+    }\r
+\r
+    /**************************************************************************\r
+     * Public Methods of This class:\r
+     **************************************************************************\r
+     */\r
+\r
+    /**\r
+     * Lock a row as part of doing the scan.\r
+     * <p>\r
+     * Lock the row at the given slot (or the previous row if slot is 0).\r
+     * Get the scan lock on the page if "request_scan_lock" is true.\r
+     * <p>\r
+     * If this routine returns true all locks were acquired while maintaining\r
+     * the latch on leaf.  If this routine returns false, locks may or may\r
+     * not have been acquired, and the routine should be called again after\r
+     * the client has researched the tree to reget the latch on the \r
+     * appropriate page.\r
+     * (p>\r
+     * As a side effect stores the value of the record handle of the current\r
+     * scan lock.\r
+     *\r
+        * @return Whether locks were acquired without releasing latch on leaf.\r
+     *\r
+     * @param open_btree        The open_btree to associate latches with - \r
+     *                          used if routine has to scan backward.\r
+     * @param btree             the conglomerate info.\r
+     * @param pos               The position of the row to lock.\r
+     * @param request_scan_lock Whether to request the page scan lock, should\r
+     *                          only be requested once per page in the scan.\r
+     * @param lock_template     A scratch area to use to read in rows.\r
+     * @param previous_key_lock Is this a previous key lock call?\r
+     * @param forUpdate         Is the scan for update or for read only.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public boolean lockScanRow(\r
+    OpenBTree               open_btree,\r
+    BTree                   btree,\r
+    BTreeRowPosition        pos,\r
+    boolean                 request_scan_lock,\r
+    FetchDescriptor         lock_fetch_desc,\r
+    DataValueDescriptor[]   lock_template,\r
+    RowLocation             lock_row_loc,\r
+    boolean                 previous_key_lock,\r
+    boolean                 forUpdate,\r
+    int                     lock_operation)\r
+               throws StandardException\r
+    {\r
+        // don't request row lock if this a previous key lock request, previous\r
+        // key lock is not required in isolation level 2.\r
+        return(\r
+            _lockScanRow(\r
+                open_btree,\r
+                btree,\r
+                pos,\r
+                !previous_key_lock, // request row lock iff not prev key lock \r
+                request_scan_lock,\r
+                lock_fetch_desc, lock_template, lock_row_loc,\r
+                previous_key_lock,\r
+                forUpdate,\r
+                lock_operation));\r
+    }\r
+\r
+    /**\r
+     * Unlock a record after it has been locked for read.\r
+     * <p>\r
+     * In repeatable read only unlock records which "did not qualify".  For\r
+     * example in a query like "select * from foo where a = 1" on a table\r
+     * with no index it is only necessary to hold locks on rows where a=1, but\r
+     * in the process of finding those rows the system will get locks on other\r
+     * rows to verify they are committed before applying the qualifier.  Those\r
+     * locks can be released under repeatable read isolation.\r
+     * <p>\r
+     * if it is forUpdate then get S lock and release U lock, else there is \r
+     * nothing to do in serializable - we keep the S locks until end of \r
+     * transaction.\r
+     *\r
+     * @param forUpdate         Is the scan for update or for read only.\r
+     *\r
+     **/\r
+    public void unlockScanRecordAfterRead(\r
+    BTreeRowPosition        pos,\r
+    boolean                 forUpdate)\r
+               throws StandardException\r
+    {\r
+        if (!pos.current_rh_qualified)\r
+        {\r
+            if (SanityManager.DEBUG)\r
+            {\r
+                SanityManager.ASSERT(pos.current_leaf != null , "leaf is null");\r
+\r
+                SanityManager.ASSERT(\r
+                    pos.current_lock_row_loc != null , "row_loc is null");\r
+            }\r
+\r
+            base_cc.unlockRowAfterRead(\r
+                pos.current_lock_row_loc, forUpdate, pos.current_rh_qualified);\r
+        }\r
+    }\r
+}\r