--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.rts.RunTimeStatisticsImpl\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.sql.execute.rts;\r
+\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.services.io.Formatable;\r
+\r
+import org.apache.derby.iapi.services.i18n.MessageService;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.services.io.FormatableHashtable;\r
+\r
+import org.apache.derby.iapi.sql.execute.RunTimeStatistics;\r
+import java.util.Vector;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+import java.sql.Timestamp;\r
+\r
+/**\r
+ RunTimeStatistics implemenation.\r
+\r
+\r
+*/\r
+public final class RunTimeStatisticsImpl implements RunTimeStatistics\r
+{\r
+\r
+\r
+ /* Leave these fields public for object inspectors */\r
+ public String statementText;\r
+ public String statementName;\r
+ public String spsName;\r
+ public long parseTime;\r
+ public long bindTime;\r
+ public long optimizeTime;\r
+ public long generateTime;\r
+ public long compileTime;\r
+ public long executeTime;\r
+ public Timestamp beginCompilationTimestamp;\r
+ public Timestamp endCompilationTimestamp;\r
+ public Timestamp beginExecutionTimestamp;\r
+ public Timestamp endExecutionTimestamp;\r
+ public ResultSetStatistics topResultSetStatistics;\r
+ public ResultSetStatistics[] subqueryTrackingArray;\r
+\r
+ // CONSTRUCTORS\r
+ /**\r
+ * \r
+ */\r
+ public RunTimeStatisticsImpl(\r
+ String spsName,\r
+ String statementName,\r
+ String statementText,\r
+ long compileTime,\r
+ long parseTime,\r
+ long bindTime,\r
+ long optimizeTime,\r
+ long generateTime,\r
+ long executeTime,\r
+ Timestamp beginCompilationTimestamp,\r
+ Timestamp endCompilationTimestamp,\r
+ Timestamp beginExecutionTimestamp,\r
+ Timestamp endExecutionTimestamp,\r
+ ResultSetStatistics[] subqueryTrackingArray,\r
+ ResultSetStatistics topResultSetStatistics)\r
+ {\r
+ this.spsName = spsName;\r
+ this.statementName = statementName;\r
+ this.statementText = statementText;\r
+ this.compileTime = compileTime;\r
+ this.parseTime = parseTime;\r
+ this.bindTime = bindTime;\r
+ this.optimizeTime = optimizeTime;\r
+ this.generateTime = generateTime;\r
+ this.executeTime = executeTime;\r
+ this.beginCompilationTimestamp = beginCompilationTimestamp;\r
+ this.endCompilationTimestamp = endCompilationTimestamp;\r
+ this.beginExecutionTimestamp = beginExecutionTimestamp;\r
+ this.endExecutionTimestamp = endExecutionTimestamp;\r
+ this.subqueryTrackingArray = subqueryTrackingArray;\r
+ this.topResultSetStatistics = topResultSetStatistics;\r
+ }\r
+\r
+ // RunTimeStatistics methods\r
+ /**\r
+ * Get the total compile time for the associated query in milliseconds.\r
+ * Compile time can be divided into parse, bind, optimize and generate times.\r
+ * \r
+ * @return long The total compile time for the associated query in milliseconds.\r
+ */\r
+ public long getCompileTimeInMillis()\r
+ {\r
+ return compileTime;\r
+ }\r
+\r
+ /**\r
+ * Get the parse time for the associated query in milliseconds.\r
+ * \r
+ * @return long The parse time for the associated query in milliseconds.\r
+ */\r
+ public long getParseTimeInMillis()\r
+ {\r
+ return parseTime;\r
+ }\r
+\r
+ /**\r
+ * Get the bind time for the associated query in milliseconds.\r
+ * \r
+ * @return long The bind time for the associated query in milliseconds.\r
+ */\r
+ public long getBindTimeInMillis()\r
+ {\r
+ return bindTime;\r
+ }\r
+\r
+ /**\r
+ * Get the optimize time for the associated query in milliseconds.\r
+ * \r
+ * @return long The optimize time for the associated query in milliseconds.\r
+ */\r
+ public long getOptimizeTimeInMillis()\r
+ {\r
+ return optimizeTime;\r
+ }\r
+\r
+ /**\r
+ * Get the generate time for the associated query in milliseconds.\r
+ * \r
+ * @return long The generate time for the associated query in milliseconds.\r
+ */\r
+ public long getGenerateTimeInMillis()\r
+ {\r
+ return generateTime;\r
+ }\r
+\r
+ /**\r
+ * Get the execute time for the associated query in milliseconds.\r
+ * \r
+ * @return long The execute time for the associated query in milliseconds.\r
+ */\r
+ public long getExecuteTimeInMillis()\r
+ {\r
+ return executeTime;\r
+ }\r
+\r
+ /**\r
+ * Get the timestamp for the beginning of query compilation. \r
+ *\r
+ * @return java.sql.Timestamp The timestamp for the beginning of query compilation.\r
+ */\r
+ public Timestamp getBeginCompilationTimestamp()\r
+ {\r
+ return beginCompilationTimestamp;\r
+ }\r
+\r
+ /**\r
+ * Get the timestamp for the end of query compilation. \r
+ *\r
+ * @return java.sql.Timestamp The timestamp for the end of query compilation.\r
+ */\r
+ public Timestamp getEndCompilationTimestamp()\r
+ {\r
+ return endCompilationTimestamp;\r
+ }\r
+\r
+ /**\r
+ * Get the timestamp for the beginning of query execution. \r
+ *\r
+ * @return java.sql.Timestamp The timestamp for the beginning of query execution.\r
+ */\r
+ public Timestamp getBeginExecutionTimestamp()\r
+ {\r
+ return beginExecutionTimestamp;\r
+ }\r
+\r
+ /**\r
+ * Get the timestamp for the end of query execution. \r
+ *\r
+ * @return java.sql.Timestamp The timestamp for the end of query execution.\r
+ */\r
+ public Timestamp getEndExecutionTimestamp()\r
+ {\r
+ return endExecutionTimestamp;\r
+ }\r
+\r
+ /**\r
+ * Get the name of the associated query or statement.\r
+ * (This will be an internally generated name if the\r
+ * user did not assign a name.)\r
+ *\r
+ * @return java.lang.String The name of the associated query or statement.\r
+ */\r
+ public String getStatementName() \r
+ {\r
+ return statementName;\r
+ }\r
+\r
+ /**\r
+ * Get the name of the Stored Prepared Statement \r
+ * for the statement.\r
+ *\r
+ * @return java.lang.String The SPS name of the associated query or statement.\r
+ */\r
+ public String getSPSName() \r
+ {\r
+ return spsName;\r
+ }\r
+\r
+ /**\r
+ * Get the text for the associated query or statement.\r
+ *\r
+ * @return java.lang.String The text for the associated query or statement.\r
+ */\r
+ public String getStatementText()\r
+ {\r
+ return statementText;\r
+ }\r
+\r
+ /**\r
+ * Get the estimated row count for the number of rows returned\r
+ * by the associated query or statement.\r
+ *\r
+ * @return The estimated number of rows returned by the associated\r
+ * query or statement.\r
+ */\r
+ public double getEstimatedRowCount()\r
+ {\r
+ if (topResultSetStatistics == null)\r
+ {\r
+ return 0.0;\r
+ }\r
+ return topResultSetStatistics.getEstimatedRowCount();\r
+ }\r
+\r
+ /**\r
+ * Get the execution plan for the associated query or statement as a String.\r
+ *\r
+ * @return java.lang.String The execution plan for the associated query or statement.\r
+ */\r
+ public String getStatementExecutionPlanText() \r
+ {\r
+ if (topResultSetStatistics == null)\r
+ {\r
+ return (String) null;\r
+ }\r
+\r
+ String subqueryInfo = "";\r
+\r
+ /* Dump out the statistics for any subqueries */\r
+\r
+ if (subqueryTrackingArray != null)\r
+ {\r
+ boolean foundAttached = false;\r
+\r
+ for (int index = 0; index < subqueryTrackingArray.length; index++)\r
+ {\r
+ if (subqueryTrackingArray[index] != null)\r
+ {\r
+ /* Only print attached subqueries message once */\r
+ if (! foundAttached)\r
+ {\r
+ subqueryInfo = MessageService.getTextMessage(\r
+ SQLState.RTS_MATERIALIZED_SUBQS) +\r
+ ":\n";\r
+ foundAttached = true;\r
+ }\r
+ subqueryInfo = subqueryInfo +\r
+ subqueryTrackingArray[index].getStatementExecutionPlanText(1);\r
+ }\r
+ }\r
+ }\r
+ return subqueryInfo +\r
+ topResultSetStatistics.getStatementExecutionPlanText(0);\r
+ }\r
+\r
+ /**\r
+ * Get the information on the nodes relating to table and index scans\r
+ * from the execution plan for the associated query or statement as a String.\r
+ *\r
+ * @return java.lang.String The nodes relating to table and index scans\r
+ * from the execution plan for the associated query or statement.\r
+ */\r
+ public String getScanStatisticsText()\r
+ {\r
+ return (topResultSetStatistics == null) ? \r
+ (String)null :\r
+ topResultSetStatistics.getScanStatisticsText(null, 0);\r
+ }\r
+\r
+ /**\r
+ * Get the information on the nodes relating to table and index scans\r
+ * for table tableName from the execution plan for the associated query \r
+ * or statement as a String.\r
+ *\r
+ * @param tableName table for which user seeks statistics.\r
+ *\r
+ * @return java.lang.String The nodes relating to table and index scans\r
+ * from the execution plan for the associated query or statement for \r
+ * tableName.\r
+ */\r
+ public String getScanStatisticsText(String tableName)\r
+ {\r
+ if (topResultSetStatistics == null) \r
+ return (String)null;\r
+ String s = topResultSetStatistics.getScanStatisticsText(tableName, 0);\r
+ return (s.equals("")) ? null : s;\r
+ }\r
+\r
+\r
+\r
+ // Class implementation\r
+ \r
+ public String toString()\r
+ {\r
+ String spstext = \r
+ (spsName != null) ? \r
+ ("Stored Prepared Statement Name: \n\t" + spsName + "\n") : \r
+ "";\r
+ return \r
+ spstext +\r
+ MessageService.getTextMessage(SQLState.RTS_STATEMENT_NAME) +\r
+ ": \n\t" + statementName + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_STATEMENT_TEXT) +\r
+ ": \n\t" + statementText + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_PARSE_TIME) +\r
+ ": " + parseTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_BIND_TIME) +\r
+ ": " + bindTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_OPTIMIZE_TIME) +\r
+ ": " + optimizeTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_GENERATE_TIME) +\r
+ ": " + generateTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_COMPILE_TIME) +\r
+ ": " + compileTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_EXECUTE_TIME) +\r
+ ": " + executeTime + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_BEGIN_COMP_TS) +\r
+ " : " + beginCompilationTimestamp + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_END_COMP_TS) +\r
+ " : " + endCompilationTimestamp + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_BEGIN_EXE_TS) +\r
+ " : " + beginExecutionTimestamp + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_END_EXE_TS) +\r
+ " : " + endExecutionTimestamp + "\n" +\r
+ MessageService.getTextMessage(SQLState.RTS_STMT_EXE_PLAN_TXT) +\r
+ ": \n" + getStatementExecutionPlanText();\r
+ }\r
+\r
+ /**\r
+ * Get the objects to be displayed when this tree object is expanded.\r
+ * <P>\r
+ * The objects returned can be of any type, including addtional Inspectables.\r
+ *\r
+ * @return java.util.Vector A vector of objects.\r
+ */\r
+ public Vector getChildren(){\r
+ Vector children = new Vector();\r
+ children.addElement(topResultSetStatistics);\r
+ return children;\r
+ }\r
+\r
+}\r