KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealBasicNoPutResultSetStatistics
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 java.util.Vector JavaDoc;
33
34 import java.io.ObjectOutput JavaDoc;
35 import java.io.ObjectInput JavaDoc;
36 import java.io.IOException JavaDoc;
37
38 import java.text.DecimalFormat JavaDoc;
39
40
41 /**
42   ResultSetStatistics implemenation for BasicNoPutResultSetImpl.
43
44   @author jerry
45
46 */

47 abstract class RealBasicNoPutResultSetStatistics
48     implements ResultSetStatistics
49 {
50
51     /* Leave these fields public for object inspectors */
52     public int numOpens;
53     public int rowsSeen;
54     public int rowsFiltered;
55     public long constructorTime;
56     public long openTime;
57     public long nextTime;
58     public long closeTime;
59     public long inspectOverall;
60     public long inspectNum;
61     public String JavaDoc inspectDesc;
62     public double optimizerEstimatedRowCount;
63     public double optimizerEstimatedCost;
64
65     // CONSTRUCTORS
66

67     /**
68      *
69      *
70      */

71     public RealBasicNoPutResultSetStatistics(
72                                                 int numOpens,
73                                                 int rowsSeen,
74                                                 int rowsFiltered,
75                                                 long constructorTime,
76                                                 long openTime,
77                                                 long nextTime,
78                                                 long closeTime,
79                                                 double optimizerEstimatedRowCount,
80                                                 double optimizerEstimatedCost
81                                             )
82     {
83         this.numOpens = numOpens;
84         this.rowsSeen = rowsSeen;
85         this.rowsFiltered = rowsFiltered;
86         this.constructorTime = constructorTime;
87         this.openTime = openTime;
88         this.nextTime = nextTime;
89         this.closeTime = closeTime;
90         this.optimizerEstimatedRowCount = optimizerEstimatedRowCount;
91         this.optimizerEstimatedCost = optimizerEstimatedCost;
92     }
93
94
95
96     // Class implementation
97
/**
98      * Dump out the time information for run time stats.
99      *
100      * @return Nothing.
101      */

102     protected final String JavaDoc dumpTimeStats(String JavaDoc indent, String JavaDoc subIndent)
103     {
104         return
105 /*
106             indent + "time spent in this ResultSet = " +
107                 getTimeSpent(ResultSet.CURRENT_RESULTSET_ONLY) + "\n" +
108             indent + "time spent in this ResultSet and below = " +
109                 getTimeSpent(NoPutResultSet.ENTIRE_RESULTSET_TREE) + "\n" +
110                 indent + "total time breakdown: " + "\n" +
111 */

112             subIndent +
113               MessageService.getTextMessage(SQLState.LANG_CONSTRUCTOR_TIME) +
114                 " " + constructorTime + "\n" +
115             subIndent +
116               MessageService.getTextMessage(SQLState.LANG_OPEN_TIME) +
117                 " " + openTime + "\n" +
118             subIndent +
119               MessageService.getTextMessage(SQLState.LANG_NEXT_TIME) +
120                 " " + nextTime + "\n" +
121             subIndent +
122               MessageService.getTextMessage(SQLState.LANG_CLOSE_TIME) +
123                 " " + closeTime;
124     }
125
126     /**
127      * Dump out the estimated cost information
128      *
129      * @return Nothing.
130      */

131     protected final String JavaDoc dumpEstimatedCosts(String JavaDoc subIndent)
132     {
133         return subIndent +
134                 MessageService.getTextMessage(SQLState.RTS_OPT_EST_RC) +
135                     ": " +
136                 formatDouble(optimizerEstimatedRowCount) + "\n" +
137                 subIndent +
138                 MessageService.getTextMessage(SQLState.RTS_OPT_EST_COST) +
139                     ": " +
140                 formatDouble(optimizerEstimatedCost) + "\n";
141     }
142
143     /**
144      * Format a double as a String with leading spaces and two digits
145      * after the decimal.
146      */

147     private static DecimalFormat JavaDoc df = null;
148     private String JavaDoc formatDouble(double toFormat)
149     {
150         if (df == null)
151         {
152             // RESOLVE: This really should use the database locale to
153
// format the number.
154
df = new DecimalFormat JavaDoc("###########0.00");
155             df.setMinimumIntegerDigits(1);
156         }
157
158         String JavaDoc retval = df.format(toFormat);
159
160         if (retval.length() < 15)
161         {
162             retval =
163                 " ".substring(0, 15 - retval.length()) + retval;
164         }
165
166         return retval;
167     }
168
169     /**
170      * Get the objects to be displayed when this tree object is expanded.
171      * <P>
172      * The objects returned can be of any type, including addtional Inspectables.
173    *
174      * @return java.util.Vector A vector of objects.
175      */

176   public Vector JavaDoc getChildren(){
177     return new Vector JavaDoc();
178   }
179     /**
180    * Return the time for all operations performed by this node, and the children
181    * of this node. The times included open, next, and close.
182      *
183      */

184   public long getTotalTime(){
185     //The method below is the original calculation. However, the constructor
186
//time was found to be inaccurate, and was therefore removed from the calculation.
187
//return constructorTime + openTime + nextTime + closeTime;
188
return openTime + nextTime + closeTime;
189   }
190
191     /**
192    * Return the time for all operations performed by the children of this node.
193      *
194      */

195   public long getChildrenTime(){
196     long childrenTime = 0;
197     java.util.Enumeration JavaDoc e = getChildren().elements();
198     while (e.hasMoreElements()){
199       childrenTime = childrenTime + ((RealBasicNoPutResultSetStatistics)e.nextElement()).getTotalTime();
200     }
201     return childrenTime;
202   }
203
204     /**
205    * Return the time for all operations performed by this node, but not the
206    * time for the children of this node.
207      *
208      */

209   public long getNodeTime(){
210     return getTotalTime() - getChildrenTime();
211   }
212
213     /**
214    * Format for display, a name for this node.
215      *
216      */

217   public abstract String JavaDoc getNodeName();
218
219     /**
220      * If this node is on a database item (like a table or an index), then provide a
221    * string that describes the on item.
222    *
223      */

224   public String JavaDoc getNodeOn(){
225     return "";
226   }
227
228
229     /**
230      * Get the estimated row count for the number of rows returned
231      * by the associated query or statement.
232      *
233      * @return The estimated number of rows returned by the associated
234      * query or statement.
235      */

236     public double getEstimatedRowCount()
237     {
238         return optimizerEstimatedRowCount;
239     }
240 }
241
Popular Tags