KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > StatParser


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.StatParser
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.derbyTesting.functionTests.util;
23
24 /**
25  * Utilities for parsing runtimestats
26  *
27  * RESOLVE: This class should be internationalized.
28  */

29 public class StatParser
30 {
31     public static String JavaDoc getScanCols(String JavaDoc runTimeStats)
32         throws Throwable JavaDoc
33     {
34         if (runTimeStats == null)
35         {
36             return "The RunTimeStatistics string passed in is null";
37         }
38
39         int startIndex;
40         int endIndex = 0;
41         int indexIndex;
42
43         StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
44
45         /*
46         ** We need to know if we used an index
47         */

48         if ((indexIndex = runTimeStats.indexOf("Index Scan ResultSet")) != -1)
49         {
50             int textend = runTimeStats.indexOf("\n", indexIndex);
51             strbuf.append(runTimeStats.substring(indexIndex, textend+1));
52         }
53         else
54         {
55             strbuf.append("TableScan\n");
56         }
57
58         int count = 0;
59         while ((startIndex = runTimeStats.indexOf("Bit set of columns fetched", endIndex)) != -1)
60         {
61             count++;
62             endIndex = runTimeStats.indexOf("}", startIndex);
63             if (endIndex == -1)
64             {
65                 endIndex = runTimeStats.indexOf("All", startIndex);
66                 if (endIndex == -1)
67                 {
68                     throw new Throwable JavaDoc("couldn't find the closing } on "+
69                         "columnFetchedBitSet in "+runTimeStats);
70                 }
71                 endIndex+=5;
72             }
73             else
74             {
75                 endIndex++;
76             }
77             strbuf.append(runTimeStats.substring(startIndex, endIndex));
78             strbuf.append("\n");
79         }
80         if (count == 0)
81         {
82             throw new Throwable JavaDoc("couldn't find string 'Bit set of columns fetched' in :\n"+
83                 runTimeStats);
84         }
85
86         return strbuf.toString();
87     }
88 }
89
Popular Tags