Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / access / btree / index / B2IForwardScan.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/btree/index/B2IForwardScan.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/btree/index/B2IForwardScan.java
new file mode 100644 (file)
index 0000000..9d0106c
--- /dev/null
@@ -0,0 +1,265 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.btree.index.B2IForwardScan\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.error.StandardException;\r
+import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;\r
+import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;\r
+import org.apache.derby.iapi.store.access.ConglomerateController;\r
+import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;\r
+import org.apache.derby.iapi.store.access.Qualifier;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+import org.apache.derby.iapi.store.raw.ContainerHandle;\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.iapi.services.io.FormatableBitSet;\r
+\r
+import org.apache.derby.impl.store.access.btree.BTreeLockingPolicy;\r
+import org.apache.derby.impl.store.access.btree.BTreeForwardScan;\r
+\r
+// For JavaDoc references (i.e. @see)\r
+import org.apache.derby.iapi.store.access.GenericScanController;\r
+\r
+/**\r
+\r
+The btree secondary index implementation of ScanManager which provides reading \r
+and deleting of entries in the btree secondary index.  \r
+\r
+This supports setting up and\r
+iterating through a set of rows while providing a start key, stop key,\r
+and a set of AND and OR qualifiers to skip unwanted rows.  Currently\r
+derby only supports forward scans (but individual columns can have\r
+descending order).  This interface is also used to delete rows from\r
+the conglomerate.  Note that update is not supported, it must be\r
+implemented as a delete, followed by an insert.\r
+\r
+Note most work of this class is inherited from the generic btree implementation.\r
+This class initializes the top level object and deals with locking information\r
+specific to a secondary index implementation of a btree.\r
+\r
+**/\r
+\r
+public class B2IForwardScan extends BTreeForwardScan\r
+{\r
+\r
+       /*\r
+       ** Fields of B2IForwardScan.\r
+       */\r
+    private ConglomerateController  base_cc_for_locking;\r
+    private int                     init_isolation_level;\r
+\r
+       /*\r
+       ** Methods of B2IForwardScan.\r
+       */\r
+\r
+       B2IForwardScan()\r
+       {\r
+               // Perform the generic b-tree scan construction.\r
+               super();\r
+       }\r
+\r
+    /**\r
+    Close the scan.\r
+       @see GenericScanController#newRowLocationTemplate\r
+    **/\r
+    public void close()\r
+        throws StandardException\r
+       {\r
+               super.close();\r
+\r
+        if (base_cc_for_locking != null)\r
+        {\r
+            base_cc_for_locking.close();\r
+            base_cc_for_locking = null;\r
+        }\r
+       }\r
+\r
+\r
+    /**\r
+    Close the scan, a commit or abort is about to happen.\r
+    **/\r
+    public boolean closeForEndTransaction(boolean closeHeldScan)\r
+        throws StandardException\r
+       {\r
+               boolean ret_val = super.closeForEndTransaction(closeHeldScan);\r
+\r
+        if (base_cc_for_locking != null)\r
+        {\r
+            base_cc_for_locking.close();\r
+            base_cc_for_locking = null;\r
+        }\r
+\r
+        return(ret_val);\r
+       }\r
+\r
+    /**\r
+     * Open the container after it has been closed previously.\r
+     * <p>\r
+     * Open the container, obtaining necessary locks.  Most work is actually\r
+     * done by RawStore.openContainer().  Will only reopen() if the container\r
+     * is not already open.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public ContainerHandle reopen()\r
+        throws StandardException\r
+    {\r
+\r
+        ContainerHandle container = super.reopen();\r
+        B2I             b2i       = (B2I) getConglomerate();\r
+\r
+        // open and lock the base table.\r
+\r
+        int base_open_mode = \r
+            getOpenMode() | TransactionController.OPENMODE_FOR_LOCK_ONLY;\r
+\r
+\r
+        // TODO - figure out what to do with static_info stuff\r
+\r
+\r
+        // open the base conglomerate - just to get lock\r
+        /*\r
+        if (static_info != null)\r
+        {\r
+            base_cc_for_locking = \r
+                xact_manager.openCompiledConglomerate(\r
+                    false,\r
+                    base_open_mode, lock_level, isolation_level,\r
+                    static_info.base_table_static_info,\r
+                    ((Conglomerate) static_info.getConglom()).\r
+                        getDynamicCompiledConglomInfo(\r
+                            b2i.baseConglomerateId));\r
+        }\r
+        else\r
+        */\r
+        {\r
+            base_cc_for_locking = \r
+                getXactMgr().openConglomerate(\r
+                    b2i.baseConglomerateId, \r
+                    false,\r
+                    base_open_mode, init_lock_level,\r
+                    init_isolation_level);\r
+\r
+            setLockingPolicy(\r
+                b2i.getBtreeLockingPolicy(\r
+                    getXactMgr().getRawStoreXact(), \r
+                    getLockLevel(), \r
+                    getOpenMode(), \r
+                    init_isolation_level, \r
+                    base_cc_for_locking, this));\r
+        }\r
+        \r
+        return(container);\r
+    }\r
+\r
+\r
+       /**\r
+       Initialize the scan for use.\r
+       <p>\r
+       Any changes to this method may have to be reflected in close as well.\r
+    <p>\r
+    The btree init opens the container (super.init), and stores away the\r
+    state of the qualifiers.  The actual searching for the first position\r
+    is delayed until the first next() call.\r
+\r
+       @exception  StandardException  Standard exception policy.\r
+       **/\r
+       public void init(\r
+    TransactionManager              xact_manager,\r
+    Transaction                     rawtran,\r
+    boolean                         hold,\r
+    int                             open_mode,\r
+    int                             lock_level,\r
+    LockingPolicy                   locking_policy,\r
+    int                             isolation_level,\r
+    boolean                         open_for_locking,\r
+    FormatableBitSet                         scanColumnList,\r
+    DataValueDescriptor[]              startKeyValue,\r
+    int                             startSearchOperator,\r
+    Qualifier                       qualifier[][],\r
+    DataValueDescriptor[]              stopKeyValue,\r
+    int                             stopSearchOperator,\r
+    B2I                             conglomerate,\r
+    B2IUndo                         undo,\r
+    B2IStaticCompiledInfo           static_info,\r
+    DynamicCompiledOpenConglomInfo  dynamic_info)\r
+        throws StandardException\r
+       {\r
+        // open and lock the base table.\r
+\r
+        int base_open_mode = \r
+            open_mode | TransactionController.OPENMODE_FOR_LOCK_ONLY;\r
+\r
+        // open the base conglomerate - just to get lock\r
+        if (static_info != null)\r
+        {\r
+            base_cc_for_locking = \r
+                xact_manager.openCompiledConglomerate(\r
+                    false,\r
+                    base_open_mode, lock_level, isolation_level,\r
+                    static_info.base_table_static_info,\r
+                    /* TODO - maintain a dynamic info for this */\r
+                    ((Conglomerate) static_info.getConglom()).\r
+                        getDynamicCompiledConglomInfo(\r
+                            conglomerate.baseConglomerateId));\r
+        }\r
+        else\r
+        {\r
+            base_cc_for_locking = \r
+                xact_manager.openConglomerate(\r
+                    conglomerate.baseConglomerateId, false, base_open_mode, lock_level,\r
+                    isolation_level);\r
+        }\r
+        \r
+        BTreeLockingPolicy b2i_locking_policy = \r
+            conglomerate.getBtreeLockingPolicy(\r
+                rawtran, lock_level, open_mode, isolation_level, \r
+                base_cc_for_locking, this);\r
+\r
+               super.init(\r
+            xact_manager,\r
+            rawtran,\r
+            hold,\r
+            open_mode,\r
+            lock_level,\r
+            b2i_locking_policy,\r
+            scanColumnList,\r
+            startKeyValue,\r
+            startSearchOperator,\r
+            qualifier,\r
+            stopKeyValue,\r
+            stopSearchOperator,\r
+            conglomerate,\r
+            undo,\r
+            static_info,\r
+            dynamic_info);\r
+\r
+\r
+        // todo - should just save the isolation level in OpenBtree but\r
+        // save it here for now.\r
+        init_isolation_level = isolation_level;\r
+       }\r
+}\r