KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealHashScanStatistics
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.util.PropertyUtil;
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 import org.apache.derby.iapi.services.io.FormatableProperties;
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.Hashtable JavaDoc;
39 import java.util.Properties JavaDoc;
40
41
42 /**
43   ResultSetStatistics implemenation for HashScanResultSet.
44
45   @author jerry
46
47 */

48 public class RealHashScanStatistics
49     extends RealNoPutResultSetStatistics
50 {
51
52     /* Leave these fields public for object inspectors */
53     public boolean isConstraint;
54     public int hashtableSize;
55     public int[] hashKeyColumns;
56     public String JavaDoc isolationLevel;
57     public String JavaDoc lockString;
58     public String JavaDoc tableName;
59     public String JavaDoc indexName;
60     public String JavaDoc nextQualifiers;
61     public String JavaDoc scanQualifiers;
62     public String JavaDoc startPosition = null;
63     public String JavaDoc stopPosition = null;
64     public FormatableProperties scanProperties;
65
66     // CONSTRUCTORS
67

68     /**
69      *
70      *
71      */

72     public RealHashScanStatistics(
73                                     int numOpens,
74                                     int rowsSeen,
75                                     int rowsFiltered,
76                                     long constructorTime,
77                                     long openTime,
78                                     long nextTime,
79                                     long closeTime,
80                                     int resultSetNumber,
81                                     String JavaDoc tableName,
82                                     String JavaDoc indexName,
83                                     boolean isConstraint,
84                                     int hashtableSize,
85                                     int[] hashKeyColumns,
86                                     String JavaDoc scanQualifiers,
87                                     String JavaDoc nextQualifiers,
88                                     Properties scanProperties,
89                                     String JavaDoc startPosition,
90                                     String JavaDoc stopPosition,
91                                     String JavaDoc isolationLevel,
92                                     String JavaDoc lockString,
93                                     double optimizerEstimatedRowCount,
94                                     double optimizerEstimatedCost
95                                     )
96     {
97         super(
98             numOpens,
99             rowsSeen,
100             rowsFiltered,
101             constructorTime,
102             openTime,
103             nextTime,
104             closeTime,
105             resultSetNumber,
106             optimizerEstimatedRowCount,
107             optimizerEstimatedCost
108             );
109         this.tableName = tableName;
110         this.indexName = indexName;
111         this.isConstraint = isConstraint;
112         this.hashtableSize = hashtableSize;
113         this.hashKeyColumns = hashKeyColumns;
114         this.scanQualifiers = scanQualifiers;
115         this.nextQualifiers = nextQualifiers;
116         this.scanProperties = new FormatableProperties();
117         if (scanProperties != null)
118         {
119             for (Enumeration JavaDoc e = scanProperties.keys(); e.hasMoreElements(); )
120             {
121                 String JavaDoc key = (String JavaDoc)e.nextElement();
122                 this.scanProperties.put(key, scanProperties.get(key));
123             }
124         }
125         this.startPosition = startPosition;
126         this.stopPosition = stopPosition;
127         this.isolationLevel = isolationLevel;
128         this.lockString = lockString;
129     }
130
131     // ResultSetStatistics methods
132

133     /**
134      * Return the statement execution plan as a String.
135      *
136      * @param depth Indentation level.
137      *
138      * @return String The statement executio plan as a String.
139      */

140     public String JavaDoc getStatementExecutionPlanText(int depth)
141     {
142         String JavaDoc header;
143         String JavaDoc isolationString = null;
144
145         initFormatInfo(depth);
146
147         if (indexName != null)
148         {
149             header =
150                 indent +
151                     MessageService.getTextMessage(
152                                         SQLState.RTS_HASH_SCAN_RS_USING,
153                                         tableName,
154                                         MessageService.getTextMessage(
155                                             isConstraint ?
156                                                 SQLState.RTS_CONSTRAINT :
157                                                 SQLState.RTS_INDEX),
158                                         indexName);
159         }
160         else
161         {
162             header =
163                 indent +
164                     MessageService.getTextMessage(SQLState.RTS_HASH_SCAN_RS,
165                                                         tableName);
166         }
167
168         header = header + " " +
169                     MessageService.getTextMessage(
170                                         SQLState.RTS_LOCKING,
171                                         isolationLevel,
172                                         lockString) +
173                     ": \n";
174
175         String JavaDoc scanInfo =
176             indent +
177                     MessageService.getTextMessage(SQLState.RTS_SCAN_INFO) +
178                     ": \n" +
179                     PropertyUtil.sortProperties(scanProperties, subIndent);
180         
181         String JavaDoc hashKeyColumnString;
182         if (hashKeyColumns.length == 1)
183         {
184             hashKeyColumnString = MessageService.getTextMessage(
185                                                         SQLState.RTS_HASH_KEY) +
186                                     " " + hashKeyColumns[0];
187         }
188         else
189         {
190             hashKeyColumnString = MessageService.getTextMessage(
191                                                     SQLState.RTS_HASH_KEYS) +
192                                     " (" + hashKeyColumns[0];
193             for (int index = 1; index < hashKeyColumns.length; index++)
194             {
195                 hashKeyColumnString = hashKeyColumnString + "," + hashKeyColumns[index];
196             }
197             hashKeyColumnString = hashKeyColumnString + ")";
198         }
199
200         return
201             header +
202             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
203                         " = " + numOpens + "\n" +
204             indent + MessageService.getTextMessage(
205                                                 SQLState.RTS_HASH_TABLE_SIZE) +
206                         " = " + hashtableSize + "\n" +
207             indent + hashKeyColumnString + "\n" +
208             indent + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN) +
209                         " = " + rowsSeen + "\n" +
210             indent + MessageService.getTextMessage(
211                                                 SQLState.RTS_ROWS_FILTERED) +
212                         " = " + rowsFiltered + "\n" +
213             dumpTimeStats(indent, subIndent) + "\n" +
214             ((rowsSeen > 0)
215                 ?
216                     subIndent + MessageService.getTextMessage(
217                                                     SQLState.RTS_NEXT_TIME) +
218                                 " = " + (nextTime / rowsSeen) + "\n"
219                 :
220                     "") + "\n" +
221             scanInfo +
222             subIndent + MessageService.getTextMessage(
223                                                 SQLState.RTS_START_POSITION) +
224                     ": \n" + startPosition +
225             subIndent + MessageService.getTextMessage(
226                                                 SQLState.RTS_STOP_POSITION) +
227                     ": \n" + stopPosition +
228             subIndent + MessageService.getTextMessage(
229                                                     SQLState.RTS_SCAN_QUALS) +
230                     ":\n" + scanQualifiers + "\n" +
231             subIndent + MessageService.getTextMessage(
232                                                     SQLState.RTS_NEXT_QUALS) +
233                     ":\n" + nextQualifiers + "\n" +
234             // RESOLVE - estimated row count and cost will eventually
235
// be displayed for all nodes
236
dumpEstimatedCosts(subIndent);
237     }
238
239     /**
240      * Return information on the scan nodes from the statement execution
241      * plan as a String.
242      *
243      * @param depth Indentation level.
244      * @param tableName if not NULL then print information for this table only
245      *
246      * @return String The information on the scan nodes from the
247      * statement execution plan as a String.
248      */

249     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
250     {
251         if ((tableName == null) || (tableName.equals(this.tableName)))
252             return getStatementExecutionPlanText(depth);
253         else
254             return (String JavaDoc)"";
255     }
256         
257
258
259     // Class implementation
260

261     public String JavaDoc toString()
262     {
263         return getStatementExecutionPlanText(0);
264     }
265     /**
266      * If this node is on a database item (like a table or an index), then provide a
267    * string that describes the on item.
268    *
269      */

270   public String JavaDoc getNodeOn(){
271     return MessageService.getTextMessage(
272                                         SQLState.RTS_ON_USING,
273                                         tableName,
274                                         indexName);
275   }
276     /**
277    * Format for display, a name for this node.
278      *
279      */

280   public String JavaDoc getNodeName(){
281     return MessageService.getTextMessage(SQLState.RTS_HASH_SCAN);
282   }
283 }
284
Popular Tags