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 / BTreeScanInfo.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/btree/BTreeScanInfo.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/access/btree/BTreeScanInfo.java
new file mode 100644 (file)
index 0000000..b02b595
--- /dev/null
@@ -0,0 +1,172 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.btree.BTreeScanInfo\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;\r
+\r
+import org.apache.derby.iapi.store.access.ScanInfo;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.services.io.FormatableBitSet;\r
+import org.apache.derby.iapi.services.i18n.MessageService;\r
+import java.util.Properties;\r
+\r
+/**\r
+\r
+  This object provides performance information related to an open scan.\r
+  The information is accumulated during operations on a ScanController() and\r
+  then copied into this object and returned by a call to \r
+  ScanController.getStatistic().\r
+\r
+\r
+**/\r
+class BTreeScanInfo implements ScanInfo\r
+{\r
+    /**\r
+     * Performance counters ...\r
+     */\r
+    private int     stat_numpages_visited           = 0;\r
+    private int     stat_numrows_visited            = 0;\r
+    private int     stat_numrows_qualified          = 0;\r
+    private int     stat_numdeleted_rows_visited    = 0;\r
+    private int     stat_numColumnsFetched          = 0;\r
+    private int     stat_treeHeight                 = 0;\r
+    private FormatableBitSet  stat_validColumns               = null;\r
+\r
+    /* Constructors for This class: */\r
+    BTreeScanInfo(BTreeScan scan)\r
+    {\r
+        // copy perfomance state out of scan, to get a fixed set of stats\r
+        stat_numpages_visited           = scan.stat_numpages_visited;\r
+        stat_numrows_visited            = scan.stat_numrows_visited;\r
+        stat_numrows_qualified          = scan.stat_numrows_qualified;\r
+        stat_numdeleted_rows_visited    = scan.stat_numdeleted_rows_visited;\r
+\r
+        stat_validColumns = \r
+            (scan.init_scanColumnList == null ? \r
+                null : ((FormatableBitSet) scan.init_scanColumnList.clone()));\r
+\r
+        if (stat_validColumns == null)\r
+        {\r
+            stat_numColumnsFetched = scan.init_template.length;\r
+        }\r
+        else\r
+        {\r
+            for (int i = 0; i < stat_validColumns.size(); i++)\r
+            {\r
+                if (stat_validColumns.get(i))\r
+                    stat_numColumnsFetched++;\r
+            }\r
+        }\r
+\r
+        try\r
+        {\r
+            stat_treeHeight = scan.getHeight();\r
+        }\r
+        catch (Throwable t)\r
+        {\r
+            stat_treeHeight = -1;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Return all information gathered about the scan.\r
+     * <p>\r
+     * This routine returns a list of properties which contains all information\r
+     * gathered about the scan.  If a Property is passed in, then that property\r
+     * list is appeneded to, otherwise a new property object is created and\r
+     * returned.\r
+     * <p>\r
+     * Not all scans may support all properties, if the property is not \r
+     * supported then it will not be returned.  The following is a list of\r
+     * properties that may be returned:\r
+     *\r
+     *     numPagesVisited\r
+     *         - the number of pages visited during the scan.  For btree scans\r
+     *           this number only includes the leaf pages visited.  \r
+     *     numRowsVisited\r
+     *         - the number of rows visited during the scan.  This number \r
+     *           includes all rows, including: those marked deleted, those\r
+     *           that don't meet qualification, ...\r
+     *     numRowsQualified\r
+     *         - the number of undeleted rows, which met the qualification.\r
+     *     treeHeight (btree's only)\r
+     *         - for btree's the height of the tree.  A tree with one page\r
+     *           has a height of 1.  Total number of pages visited in a btree\r
+     *           scan is (treeHeight - 1 + numPagesVisited).\r
+     *     numColumnsFetched\r
+     *         - the number of columns Fetched - partial scans will result\r
+     *           in fetching less columns than the total number in the scan.\r
+     *     columnsFetched\r
+     *         - The FormatableBitSet.toString() method called on the validColumns arg.\r
+     *           to the scan, unless validColumns was set to null, and in that\r
+     *           case we will return "all".\r
+     *     NOTE - this list will be expanded as more information about the scan\r
+     *            is gathered and returned.\r
+     *\r
+     * @param prop   Property list to fill in.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+    public Properties getAllScanInfo(Properties prop)\r
+               throws StandardException\r
+    {\r
+        if (prop == null)\r
+            prop = new Properties();\r
+\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_SCAN_TYPE),\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_BTREE));\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED),\r
+            Integer.toString(stat_numpages_visited));\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED),\r
+            Integer.toString(stat_numrows_visited));\r
+        prop.put(\r
+                       MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_NUM_DELETED_ROWS_VISITED),\r
+            Integer.toString(stat_numdeleted_rows_visited));\r
+        prop.put(\r
+                       MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_NUM_ROWS_QUALIFIED),\r
+            Integer.toString(stat_numrows_qualified));\r
+        prop.put(\r
+                       MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_TREE_HEIGHT),\r
+            Integer.toString(stat_treeHeight));\r
+        prop.put(\r
+                       MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_NUM_COLUMNS_FETCHED),\r
+            Integer.toString(stat_numColumnsFetched));\r
+        prop.put(\r
+                       MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_COLUMNS_FETCHED_BIT_SET),\r
+                       (stat_validColumns == null ?\r
+                               MessageService.getTextMessage(\r
+                                                               SQLState.STORE_RTS_ALL) :\r
+                stat_validColumns.toString()));\r
+\r
+        return(prop);\r
+    }\r
+}\r