KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > rts > RunTimeStatisticsImpl


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RunTimeStatisticsImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute.rts;
23
24 import org.apache.derby.iapi.services.io.StoredFormatIds;
25 import org.apache.derby.iapi.services.io.Formatable;
26
27 import org.apache.derby.iapi.services.i18n.MessageService;
28 import org.apache.derby.iapi.reference.SQLState;
29
30 import org.apache.derby.iapi.services.io.FormatableHashtable;
31
32 import org.apache.derby.iapi.sql.execute.RunTimeStatistics;
33 import java.util.Vector JavaDoc;
34
35 import java.io.ObjectOutput JavaDoc;
36 import java.io.ObjectInput JavaDoc;
37 import java.io.IOException JavaDoc;
38
39 import java.sql.Timestamp JavaDoc;
40
41 /**
42   RunTimeStatistics implemenation.
43
44   @author jerry
45
46 */

47 public final class RunTimeStatisticsImpl implements RunTimeStatistics
48 {
49
50
51     /* Leave these fields public for object inspectors */
52     public String JavaDoc statementText;
53     public String JavaDoc statementName;
54     public String JavaDoc spsName;
55     public long parseTime;
56     public long bindTime;
57     public long optimizeTime;
58     public long generateTime;
59     public long compileTime;
60     public long executeTime;
61     public Timestamp JavaDoc beginCompilationTimestamp;
62     public Timestamp JavaDoc endCompilationTimestamp;
63     public Timestamp JavaDoc beginExecutionTimestamp;
64     public Timestamp JavaDoc endExecutionTimestamp;
65     public ResultSetStatistics topResultSetStatistics;
66     public ResultSetStatistics[] subqueryTrackingArray;
67
68     // CONSTRUCTORS
69
/**
70      *
71      */

72     public RunTimeStatisticsImpl(
73                                     String JavaDoc spsName,
74                                     String JavaDoc statementName,
75                                     String JavaDoc statementText,
76                                     long compileTime,
77                                     long parseTime,
78                                     long bindTime,
79                                     long optimizeTime,
80                                     long generateTime,
81                                     long executeTime,
82                                     Timestamp JavaDoc beginCompilationTimestamp,
83                                     Timestamp JavaDoc endCompilationTimestamp,
84                                     Timestamp JavaDoc beginExecutionTimestamp,
85                                     Timestamp JavaDoc endExecutionTimestamp,
86                                     ResultSetStatistics[] subqueryTrackingArray,
87                                     ResultSetStatistics topResultSetStatistics)
88     {
89         this.spsName = spsName;
90         this.statementName = statementName;
91         this.statementText = statementText;
92         this.compileTime = compileTime;
93         this.parseTime = parseTime;
94         this.bindTime = bindTime;
95         this.optimizeTime = optimizeTime;
96         this.generateTime = generateTime;
97         this.executeTime = executeTime;
98         this.beginCompilationTimestamp = beginCompilationTimestamp;
99         this.endCompilationTimestamp = endCompilationTimestamp;
100         this.beginExecutionTimestamp = beginExecutionTimestamp;
101         this.endExecutionTimestamp = endExecutionTimestamp;
102         this.subqueryTrackingArray = subqueryTrackingArray;
103         this.topResultSetStatistics = topResultSetStatistics;
104     }
105
106     // RunTimeStatistics methods
107
/**
108      * Get the total compile time for the associated query in milliseconds.
109      * Compile time can be divided into parse, bind, optimize and generate times.
110      *
111      * @return long The total compile time for the associated query in milliseconds.
112      */

113     public long getCompileTimeInMillis()
114     {
115         return compileTime;
116     }
117
118     /**
119      * Get the parse time for the associated query in milliseconds.
120      *
121      * @return long The parse time for the associated query in milliseconds.
122      */

123     public long getParseTimeInMillis()
124     {
125         return parseTime;
126     }
127
128     /**
129      * Get the bind time for the associated query in milliseconds.
130      *
131      * @return long The bind time for the associated query in milliseconds.
132      */

133     public long getBindTimeInMillis()
134     {
135         return bindTime;
136     }
137
138     /**
139      * Get the optimize time for the associated query in milliseconds.
140      *
141      * @return long The optimize time for the associated query in milliseconds.
142      */

143     public long getOptimizeTimeInMillis()
144     {
145         return optimizeTime;
146     }
147
148     /**
149      * Get the generate time for the associated query in milliseconds.
150      *
151      * @return long The generate time for the associated query in milliseconds.
152      */

153     public long getGenerateTimeInMillis()
154     {
155         return generateTime;
156     }
157
158     /**
159      * Get the execute time for the associated query in milliseconds.
160      *
161      * @return long The execute time for the associated query in milliseconds.
162      */

163     public long getExecuteTimeInMillis()
164     {
165         return executeTime;
166     }
167
168     /**
169      * Get the timestamp for the beginning of query compilation.
170      *
171      * @return java.sql.Timestamp The timestamp for the beginning of query compilation.
172      */

173     public Timestamp JavaDoc getBeginCompilationTimestamp()
174     {
175         return beginCompilationTimestamp;
176     }
177
178     /**
179      * Get the timestamp for the end of query compilation.
180      *
181      * @return java.sql.Timestamp The timestamp for the end of query compilation.
182      */

183     public Timestamp JavaDoc getEndCompilationTimestamp()
184     {
185         return endCompilationTimestamp;
186     }
187
188     /**
189      * Get the timestamp for the beginning of query execution.
190      *
191      * @return java.sql.Timestamp The timestamp for the beginning of query execution.
192      */

193     public Timestamp JavaDoc getBeginExecutionTimestamp()
194     {
195         return beginExecutionTimestamp;
196     }
197
198     /**
199      * Get the timestamp for the end of query execution.
200      *
201      * @return java.sql.Timestamp The timestamp for the end of query execution.
202      */

203     public Timestamp JavaDoc getEndExecutionTimestamp()
204     {
205         return endExecutionTimestamp;
206     }
207
208     /**
209      * Get the name of the associated query or statement.
210      * (This will be an internally generated name if the
211      * user did not assign a name.)
212      *
213      * @return java.lang.String The name of the associated query or statement.
214      */

215     public String JavaDoc getStatementName()
216     {
217         return statementName;
218     }
219
220     /**
221      * Get the name of the Stored Prepared Statement
222      * for the statement.
223      *
224      * @return java.lang.String The SPS name of the associated query or statement.
225      */

226     public String JavaDoc getSPSName()
227     {
228         return spsName;
229     }
230
231     /**
232      * Get the text for the associated query or statement.
233      *
234      * @return java.lang.String The text for the associated query or statement.
235      */

236     public String JavaDoc getStatementText()
237     {
238         return statementText;
239     }
240
241     /**
242      * Get the estimated row count for the number of rows returned
243      * by the associated query or statement.
244      *
245      * @return The estimated number of rows returned by the associated
246      * query or statement.
247      */

248     public double getEstimatedRowCount()
249     {
250         if (topResultSetStatistics == null)
251         {
252             return 0.0;
253         }
254         return topResultSetStatistics.getEstimatedRowCount();
255     }
256
257     /**
258      * Get the execution plan for the associated query or statement as a String.
259      *
260      * @return java.lang.String The execution plan for the associated query or statement.
261      */

262     public String JavaDoc getStatementExecutionPlanText()
263     {
264         if (topResultSetStatistics == null)
265         {
266             return (String JavaDoc) null;
267         }
268
269         String JavaDoc subqueryInfo = "";
270
271         /* Dump out the statistics for any subqueries */
272
273         if (subqueryTrackingArray != null)
274         {
275             boolean foundAttached = false;
276
277             for (int index = 0; index < subqueryTrackingArray.length; index++)
278             {
279                 if (subqueryTrackingArray[index] != null)
280                 {
281                     /* Only print attached subqueries message once */
282                     if (! foundAttached)
283                     {
284                         subqueryInfo = MessageService.getTextMessage(
285                                             SQLState.RTS_MATERIALIZED_SUBQS) +
286                                         ":\n";
287                         foundAttached = true;
288                     }
289                     subqueryInfo = subqueryInfo +
290                         subqueryTrackingArray[index].getStatementExecutionPlanText(1);
291                 }
292             }
293         }
294         return subqueryInfo +
295             topResultSetStatistics.getStatementExecutionPlanText(0);
296     }
297
298     /**
299      * Get the information on the nodes relating to table and index scans
300      * from the execution plan for the associated query or statement as a String.
301      *
302      * @return java.lang.String The nodes relating to table and index scans
303      * from the execution plan for the associated query or statement.
304      */

305     public String JavaDoc getScanStatisticsText()
306     {
307         return (topResultSetStatistics == null) ?
308             (String JavaDoc)null :
309             topResultSetStatistics.getScanStatisticsText(null, 0);
310     }
311
312     /**
313      * Get the information on the nodes relating to table and index scans
314      * for table tableName from the execution plan for the associated query
315      * or statement as a String.
316      *
317      * @param tableName table for which user seeks statistics.
318      *
319      * @return java.lang.String The nodes relating to table and index scans
320      * from the execution plan for the associated query or statement for
321      * tableName.
322      */

323     public String JavaDoc getScanStatisticsText(String JavaDoc tableName)
324     {
325         if (topResultSetStatistics == null)
326             return (String JavaDoc)null;
327         String JavaDoc s = topResultSetStatistics.getScanStatisticsText(tableName, 0);
328         return (s.equals("")) ? null : s;
329     }
330
331
332
333     // Class implementation
334

335     public String JavaDoc toString()
336     {
337         String JavaDoc spstext =
338             (spsName != null) ?
339                     ("Stored Prepared Statement Name: \n\t" + spsName + "\n") :
340                     "";
341         return
342             spstext +
343             MessageService.getTextMessage(SQLState.RTS_STATEMENT_NAME) +
344                 ": \n\t" + statementName + "\n" +
345             MessageService.getTextMessage(SQLState.RTS_STATEMENT_TEXT) +
346                 ": \n\t" + statementText + "\n" +
347             MessageService.getTextMessage(SQLState.RTS_PARSE_TIME) +
348                 ": " + parseTime + "\n" +
349             MessageService.getTextMessage(SQLState.RTS_BIND_TIME) +
350                 ": " + bindTime + "\n" +
351             MessageService.getTextMessage(SQLState.RTS_OPTIMIZE_TIME) +
352                 ": " + optimizeTime + "\n" +
353             MessageService.getTextMessage(SQLState.RTS_GENERATE_TIME) +
354                 ": " + generateTime + "\n" +
355             MessageService.getTextMessage(SQLState.RTS_COMPILE_TIME) +
356                 ": " + compileTime + "\n" +
357             MessageService.getTextMessage(SQLState.RTS_EXECUTE_TIME) +
358                 ": " + executeTime + "\n" +
359             MessageService.getTextMessage(SQLState.RTS_BEGIN_COMP_TS) +
360                 " : " + beginCompilationTimestamp + "\n" +
361             MessageService.getTextMessage(SQLState.RTS_END_COMP_TS) +
362                 " : " + endCompilationTimestamp + "\n" +
363             MessageService.getTextMessage(SQLState.RTS_BEGIN_EXE_TS) +
364                 " : " + beginExecutionTimestamp + "\n" +
365             MessageService.getTextMessage(SQLState.RTS_END_EXE_TS) +
366                 " : " + endExecutionTimestamp + "\n" +
367             MessageService.getTextMessage(SQLState.RTS_STMT_EXE_PLAN_TXT) +
368                 ": \n" + getStatementExecutionPlanText();
369     }
370
371     /**
372      * Get the objects to be displayed when this tree object is expanded.
373      * <P>
374      * The objects returned can be of any type, including addtional Inspectables.
375    *
376      * @return java.util.Vector A vector of objects.
377      */

378   public Vector JavaDoc getChildren(){
379     Vector JavaDoc children = new Vector JavaDoc();
380     children.addElement(topResultSetStatistics);
381     return children;
382   }
383
384 }
385
Popular Tags