KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealSortStatistics
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
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 import org.apache.derby.iapi.services.io.FormatableProperties;
31 import org.apache.derby.iapi.util.PropertyUtil;
32
33 import java.io.ObjectOutput JavaDoc;
34 import java.io.ObjectInput JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 import java.util.Enumeration JavaDoc;
38 import java.util.Properties JavaDoc;
39
40 /**
41   ResultSetStatistics implemenation for SortResultSet.
42
43   @author jerry
44
45 */

46 public class RealSortStatistics
47     extends RealNoPutResultSetStatistics
48 {
49
50     /* Leave these fields public for object inspectors */
51     public int rowsInput;
52     public int rowsReturned;
53     public boolean eliminateDuplicates;
54     public boolean inSortedOrder;
55     public ResultSetStatistics childResultSetStatistics;
56     public FormatableProperties sortProperties;
57
58     // CONSTRUCTORS
59

60     /**
61      *
62      *
63      */

64     public RealSortStatistics(
65                         int numOpens,
66                         int rowsSeen,
67                         int rowsFiltered,
68                         long constructorTime,
69                         long openTime,
70                         long nextTime,
71                         long closeTime,
72                         int resultSetNumber,
73                         int rowsInput,
74                         int rowsReturned,
75                         boolean eliminateDuplicates,
76                         boolean inSortedOrder,
77                         Properties sortProperties,
78                         double optimizerEstimatedRowCount,
79                         double optimizerEstimatedCost,
80                         ResultSetStatistics childResultSetStatistics
81                         )
82     {
83         super(
84             numOpens,
85             rowsSeen,
86             rowsFiltered,
87             constructorTime,
88             openTime,
89             nextTime,
90             closeTime,
91             resultSetNumber,
92             optimizerEstimatedRowCount,
93             optimizerEstimatedCost
94             );
95         this.rowsInput = rowsInput;
96         this.rowsReturned = rowsReturned;
97         this.eliminateDuplicates = eliminateDuplicates;
98         this.inSortedOrder = inSortedOrder;
99         this.childResultSetStatistics = childResultSetStatistics;
100         this.sortProperties = new FormatableProperties();
101         for (Enumeration JavaDoc e = sortProperties.keys(); e.hasMoreElements(); )
102         {
103             String JavaDoc key = (String JavaDoc)e.nextElement();
104             this.sortProperties.put(key, sortProperties.get(key));
105         }
106     }
107
108     // ResultSetStatistics methods
109

110     /**
111      * Return the statement execution plan as a String.
112      *
113      * @param depth Indentation level.
114      *
115      * @return String The statement execution plan as a String.
116      */

117     public String JavaDoc getStatementExecutionPlanText(int depth)
118     {
119         initFormatInfo(depth);
120
121         String JavaDoc sortInfo = (inSortedOrder) ? "" :
122             indent + MessageService.getTextMessage(SQLState.RTS_SORT_INFO) +
123             ": \n" + PropertyUtil.sortProperties(sortProperties, subIndent);
124
125         return
126             indent + MessageService.getTextMessage(SQLState.RTS_SORT_RS) +
127                 ":\n" +
128             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
129                 " = " + numOpens + "\n" +
130             indent + MessageService.getTextMessage(SQLState.RTS_ROWS_INPUT) +
131                 " = " + rowsInput + "\n" +
132             indent + MessageService.getTextMessage(
133                                                 SQLState.RTS_ROWS_RETURNED) +
134                 " = " + rowsReturned + "\n" +
135             indent + MessageService.getTextMessage(
136                                                 SQLState.RTS_ELIMINATE_DUPS) +
137                 " = " + eliminateDuplicates + "\n" +
138             indent + MessageService.getTextMessage(
139                                                 SQLState.RTS_IN_SORTED_ORDER) +
140                 " = " + inSortedOrder + "\n" +
141             sortInfo +
142             dumpTimeStats(indent, subIndent) + "\n" +
143             dumpEstimatedCosts(subIndent) + "\n" +
144             indent + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS) +
145                 ":\n" +
146             childResultSetStatistics.getStatementExecutionPlanText(
147                                                                 sourceDepth) +
148                 "\n";
149     }
150
151     /**
152      * Return information on the scan nodes from the statement execution
153      * plan as a String.
154      *
155      * @param depth Indentation level.
156      * @param tableName if not NULL then print information for this table only
157      *
158      * @return String The information on the scan nodes from the
159      * statement execution plan as a String.
160      */

161     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
162     {
163         return childResultSetStatistics.getScanStatisticsText(tableName, depth);
164     }
165
166     // Class implementation
167

168     public String JavaDoc toString()
169     {
170         return getStatementExecutionPlanText(0);
171     }
172   public java.util.Vector JavaDoc getChildren(){
173     java.util.Vector JavaDoc children = new java.util.Vector JavaDoc();
174     children.addElement(childResultSetStatistics);
175     return children;
176   }
177     /**
178    * Format for display, a name for this node.
179      *
180      */

181   public String JavaDoc getNodeName(){
182     return MessageService.getTextMessage(SQLState.RTS_SORT);
183   }
184 }
185
Popular Tags