Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / access / sort / MergeSortInfo.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/sort/MergeSortInfo.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/access/sort/MergeSortInfo.java
new file mode 100644 (file)
index 0000000..da4ccdf
--- /dev/null
@@ -0,0 +1,170 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.access.sort.MergeSortInfo\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.sort;\r
+\r
+import org.apache.derby.iapi.store.access.SortInfo;\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.i18n.MessageService;\r
+\r
+import java.util.Vector;\r
+import java.util.Properties;\r
+\r
+/**\r
+\r
+  This object provides performance information related to a sort.\r
+  The information is accumulated during operations on a SortController() and\r
+  then copied into this object and returned by a call to\r
+  SortController.getSortInfo().\r
+\r
+  @see org.apache.derby.iapi.store.access.SortController#getSortInfo()\r
+\r
+**/\r
+class MergeSortInfo implements SortInfo\r
+{\r
+    /**\r
+     * Performance counters ...\r
+     */\r
+\r
+    private String  stat_sortType;\r
+    // private long    stat_estimMemUsed;\r
+    private int     stat_numRowsInput;\r
+    private int     stat_numRowsOutput;\r
+    private int     stat_numMergeRuns;\r
+    private Vector  stat_mergeRunsSize;\r
+\r
+\r
+    /* Constructors for This class: */\r
+    MergeSortInfo(MergeInserter sort)\r
+    {\r
+        // copy perfomance state out of sort, to get a fixed set of stats\r
+        stat_sortType               = sort.stat_sortType;\r
+        // stat_estimMemUsed           = sort.estimatedMemoryUsed;\r
+        stat_numRowsInput           = sort.stat_numRowsInput;\r
+        stat_numRowsOutput          = sort.stat_numRowsOutput;\r
+        stat_numMergeRuns           = sort.stat_numMergeRuns;\r
+        stat_mergeRunsSize          = sort.stat_mergeRunsSize;\r
+    }\r
+\r
+    /**\r
+     * Return all information gathered about the sort.\r
+     * <p>\r
+     * This routine returns a list of properties which contains all information\r
+     * gathered about the sort.  If a Property is passed in, then that property\r
+     * list is appended to, otherwise a new property object is created and\r
+     * returned.\r
+     * <p>\r
+     * Not all sorts 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
+     *     sortType\r
+     *         - type of the sort being performed:\r
+     *           internal\r
+     *           external\r
+     *     numRowsInput\r
+     *         - the number of rows input to the sort.  This\r
+     *           number includes duplicates.\r
+     *     numRowsOutput\r
+     *         - the number of rows to be output by the sort.  This number\r
+     *           may be different from numRowsInput since duplicates may not\r
+     *           be output.\r
+     *     numMergeRuns\r
+     *         - the number of merge runs for the sort.\r
+     *           Applicable to external sorts only.\r
+     *           Note: when a SortController is closed, numMergeRuns may increase by 1, to\r
+     *           reflect the additional merge run that may be created for\r
+     *           any data still in the sort buffer.\r
+     *     mergeRunsSize\r
+     *         - the size (number of rows) of each merge run for the sort.\r
+     *           Applicable to external sorts only.\r
+     *           e.g. [3,3,2] indicates 3 merge runs, where the first two runs\r
+     *           have 3 rows each, and the last run has 2 rows.\r
+     *           Note: when a SortController is closed, this vector may get an\r
+     *           additional element, to reflect the additional merge run that\r
+     *           may be created for any data still in the sort buffer.\r
+     *     NOTE - this list will be expanded as more information about the sort\r
+     *            is gathered and returned.\r
+     *\r
+     * @param prop   Property list to fill in.\r
+     *\r
+        * @exception  StandardException  Standard exception policy.\r
+     **/\r
+\r
+    public Properties getAllSortInfo(Properties prop)\r
+               throws StandardException\r
+    {\r
+        if (prop == null)\r
+            prop = new Properties();\r
+\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_SORT_TYPE),\r
+                       "external".equals(this.stat_sortType) ?\r
+                               MessageService.getTextMessage(SQLState.STORE_RTS_EXTERNAL) :\r
+                               MessageService.getTextMessage(SQLState.STORE_RTS_INTERNAL));\r
+        // prop.put(\r
+               //  MessageService.getTextMessage(SQLState.STORE_RTS_ESTIMATED_MEMORY_USED),\r
+               //  Long.toString(stat_estimMemUsed));\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_INPUT),\r
+                       Integer.toString(stat_numRowsInput));\r
+        prop.put(\r
+                       MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_OUTPUT),\r
+                       Integer.toString(stat_numRowsOutput));\r
+        if (this.stat_sortType == "external")\r
+        {\r
+            prop.put(\r
+                         MessageService.getTextMessage(SQLState.STORE_RTS_NUM_MERGE_RUNS),\r
+                         Integer.toString(stat_numMergeRuns));\r
+            prop.put(\r
+                         MessageService.getTextMessage(SQLState.STORE_RTS_MERGE_RUNS_SIZE),\r
+                         stat_mergeRunsSize.toString());\r
+        }\r
+        return(prop);\r
+    }\r
+}\r
+\r
+\r
+    /**\r
+     *     estimMemUsed IS NOT CURRENTLY SUPPORTED SINCE IT IS UNRELIABLE\r
+     *     estimMemUsed\r
+     *         - the estimated memory used by the sort.\r
+     *\r
+     *           This is only measured when the system runs out of sort\r
+     *           buffer space, AND when it tries to avoid doing an external sort.\r
+     *           It measures this by subtracting the memory usage at initialization\r
+     *           from the memory usage at the time we are trying to avoid doing an\r
+     *           external sort.  The result could be negative: this probably indicates\r
+     *           that there has been some garbage collection in the interim.\r
+     *           If the attempt at keeping the sort internal succeeds, the buffer grows\r
+     *           but the increased memory usage is not measured.\r
+     *\r
+     *           The system may never measure the memory usage. This happens if\r
+     *           it never runs out of sort buffer space, or if it is set up not\r
+     *           to avoid external sorts. In cases that it is not measured, it returns 0.\r
+     *\r
+     *           In future, this info may improve with an improved JVM API.\r
+     */\r
+\r