Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/impl/sql/execute/rts/RealBasicNoPutResultSetStatistics.java


1   /*
2   
3      Derby - Class org.apache.derby.impl.sql.execute.rts.RealBasicNoPutResultSetStatistics
4   
5      Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.impl.sql.execute.rts;
22  
23  import org.apache.derby.iapi.services.io.StoredFormatIds;
24  import org.apache.derby.iapi.services.io.Formatable;
25  
26  import org.apache.derby.iapi.services.i18n.MessageService;
27  import org.apache.derby.iapi.reference.SQLState;
28  
29  import org.apache.derby.iapi.services.io.FormatableHashtable;
30  
31  import java.util.Vector;
32  
33  import java.io.ObjectOutput;
34  import java.io.ObjectInput;
35  import java.io.IOException;
36  
37  import java.text.DecimalFormat;
38  
39  
40  /**
41    ResultSetStatistics implemenation for BasicNoPutResultSetImpl.
42  
43    @author jerry
44  
45  */
46  abstract class RealBasicNoPutResultSetStatistics
47    implements ResultSetStatistics
48  {
49  
50    /* Leave these fields public for object inspectors */
51    public int numOpens;
52    public int rowsSeen;
53    public int rowsFiltered;
54    public long constructorTime;
55    public long openTime;
56    public long nextTime;
57    public long closeTime;
58    public long inspectOverall;
59    public long inspectNum;
60    public String inspectDesc;
61    public double optimizerEstimatedRowCount;
62    public double optimizerEstimatedCost;
63  
64    // CONSTRUCTORS
65  
66    /**
67     *
68     *
69     */
70      public  RealBasicNoPutResultSetStatistics(
71                          int numOpens,
72                          int rowsSeen,
73                          int rowsFiltered,
74                          long constructorTime,
75                          long openTime,
76                          long nextTime,
77                          long closeTime,
78                          double optimizerEstimatedRowCount,
79                          double optimizerEstimatedCost
80                        )
81    {
82      this.numOpens = numOpens;
83      this.rowsSeen = rowsSeen;
84      this.rowsFiltered = rowsFiltered;
85      this.constructorTime = constructorTime;
86      this.openTime = openTime;
87      this.nextTime = nextTime;
88      this.closeTime = closeTime;
89      this.optimizerEstimatedRowCount = optimizerEstimatedRowCount;
90      this.optimizerEstimatedCost = optimizerEstimatedCost;
91    }
92  
93  
94  
95    // Class implementation
96    /**
97     * Dump out the time information for run time stats.
98     *
99     * @return Nothing.
100    */
101   protected final String dumpTimeStats(String indent, String subIndent)
102   {
103     return
104 /*
105       indent + "time spent in this ResultSet = " +
106         getTimeSpent(ResultSet.CURRENT_RESULTSET_ONLY) + "\n" +
107       indent + "time spent in this ResultSet and below = " +
108         getTimeSpent(NoPutResultSet.ENTIRE_RESULTSET_TREE) + "\n" +
109         indent + "total time breakdown: " + "\n" +
110 */
111       subIndent +
112         MessageService.getTextMessage(SQLState.LANG_CONSTRUCTOR_TIME) +
113         " " + constructorTime + "\n" +
114       subIndent +
115         MessageService.getTextMessage(SQLState.LANG_OPEN_TIME) +
116         " " + openTime + "\n" +
117       subIndent +
118         MessageService.getTextMessage(SQLState.LANG_NEXT_TIME) +
119         " " + nextTime + "\n" +
120       subIndent +
121         MessageService.getTextMessage(SQLState.LANG_CLOSE_TIME) +
122         " " + closeTime;
123   }
124 
125   /**
126    * Dump out the estimated cost information
127    *
128    * @return Nothing.
129    */
130   protected final String dumpEstimatedCosts(String subIndent)
131   {
132     return  subIndent +
133         MessageService.getTextMessage(SQLState.RTS_OPT_EST_RC) +
134           ": " +
135         formatDouble(optimizerEstimatedRowCount) + "\n" +
136         subIndent +
137         MessageService.getTextMessage(SQLState.RTS_OPT_EST_COST) +
138           ": " +
139         formatDouble(optimizerEstimatedCost) + "\n";
140   }
141 
142   /**
143    * Format a double as a String with leading spaces and two digits
144    * after the decimal.
145    */
146   private static DecimalFormat df = null;
147   private String formatDouble(double toFormat)
148   {
149     if (df == null)
150     {
151       // RESOLVE: This really should use the database locale to
152       // format the number.
153       df = new DecimalFormat("###########0.00");
154       df.setMinimumIntegerDigits(1);
155     }
156 
157     String retval = df.format(toFormat);
158 
159     if (retval.length() < 15)
160     {
161       retval =
162         "               ".substring(0, 15 - retval.length()) + retval;
163     }
164 
165     return retval;
166   }
167 
168   /**
169    * Get the objects to be displayed when this tree object is expanded.
170    * <P>
171    * The objects returned can be of any type, including addtional Inspectables.
172    *
173    * @return java.util.Vector  A vector of objects.
174    */
175   public Vector getChildren(){
176     return new Vector();
177   }
178   /**
179    * Return the time for all operations performed by this node, and the children
180    * of this node.  The times included open, next, and close.
181    *
182    */
183   public long getTotalTime(){
184     //The method below is the original calculation.  However, the constructor
185     //time was found to be inaccurate, and was therefore removed from the calculation.
186     //return constructorTime + openTime + nextTime + closeTime;
187     return openTime + nextTime + closeTime;
188   }
189 
190   /**
191    * Return the time for all operations performed by the children of this node.
192    *
193    */
194   public long getChildrenTime(){
195     long childrenTime = 0;
196     java.util.Enumeration e = getChildren().elements();
197     while (e.hasMoreElements()){
198       childrenTime = childrenTime + ((RealBasicNoPutResultSetStatistics)e.nextElement()).getTotalTime();
199     }
200     return childrenTime;
201   }
202 
203   /**
204    * Return the time for all operations performed by this node, but not the
205    * time for the children of this node.
206    *
207    */
208   public long getNodeTime(){
209     return getTotalTime() - getChildrenTime();
210   }
211 
212   /**
213    * Format for display, a name for this node.
214    *
215    */
216   public abstract String getNodeName();
217 
218   /**
219    * If this node is on a database item (like a table or an index), then provide a
220    * string that describes the on item.
221    *
222    */
223   public String getNodeOn(){
224     return "";
225   }
226 
227 
228   /**
229    * Get the estimated row count for the number of rows returned
230    * by the associated query or statement.
231    *
232    * @return  The estimated number of rows returned by the associated
233    * query or statement.
234    */
235   public double getEstimatedRowCount()
236   {
237     return optimizerEstimatedRowCount;
238   }
239 }