KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > db > OptimizerTrace


1 /*
2
3    Derby - Class org.apache.derby.iapi.db.OptimizerTrace
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.iapi.db;
23
24 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
25 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
26
27 /**
28   <P>
29   This class provides static methods for controlling the
30   optimizer tracing in a Cloudscape database.
31   
32   <P>
33   <i>
34   Cloudscape reserves the right to change, rename, or remove this interface
35   at any time. </i>
36   */

37 public class OptimizerTrace
38 {
39     /**
40      * Control whether or not optimizer trace is on.
41      *
42      * @param onOrOff Whether to turn optimizer trace on (true) or off (false).
43      *
44      * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.)
45      */

46     public static boolean setOptimizerTrace(boolean onOrOff)
47     {
48         boolean retCode = false;
49
50         try
51         {
52             // Get the current language connection context. This is associated
53
// with the current database.
54
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
55             retCode = lcc.setOptimizerTrace(onOrOff);
56         }
57         catch (Throwable JavaDoc t)
58         {
59             // eat all exceptions, simply return false
60
}
61
62         return retCode;
63     }
64
65     /**
66      * Control whether or not optimizer trace is generated in html.
67      *
68      * @param onOrOff Whether or not optimizer trace will be in html (true) or not (false).
69      *
70      * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.)
71      */

72     public static boolean setOptimizerTraceHtml(boolean onOrOff)
73     {
74         boolean retCode = false;
75
76         try
77         {
78             // Get the current language connection context. This is associated
79
// with the current database.
80
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
81             retCode = lcc.setOptimizerTraceHtml(onOrOff);
82         }
83         catch (Throwable JavaDoc t)
84         {
85             // eat all exceptions, simply return false
86
}
87
88         return retCode;
89     }
90
91     /**
92      * Get the optimizer trace output for the last optimized query as a String. If optimizer trace
93      * html is on, then the String will contain the html tags.
94      *
95      * @return The optimizer trace output for the last optimized query as a String.
96      * Null will be returned if optimizer trace output is off or not supported
97      * or no trace output was found or an exception occurred.
98      */

99     public static String JavaDoc getOptimizerTraceOutput()
100     {
101         String JavaDoc retCode = null;
102
103         try
104         {
105             // Get the current language connection context. This is associated
106
// with the current database.
107
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
108             retCode = lcc.getOptimizerTraceOutput();
109         }
110         catch (Throwable JavaDoc t)
111         {
112             // eat all exceptions, simply return null
113
}
114
115         return retCode;
116     }
117
118     /**
119      * Send the optimizer trace output for the last optimized query to a file with a .html extension.
120      * If optimizer trace html is on, then the output will contain the html tags.
121      *
122      * @param fileName The name of the file to write to. (.html extension will be added.)
123      *
124      * @return Whether or not the request was successful.
125      * false mayl be returned for a number of reasons, including if optimizer trace output is off or not supported
126      * or no trace output was found or an exception occurred.
127      */

128     public static boolean writeOptimizerTraceOutputHtml(String JavaDoc fileName)
129     {
130         boolean retCode = true;
131
132         try
133         {
134         String JavaDoc output = getOptimizerTraceOutput();
135         //RESOLVEOPTIMIZERTRACE - need to write out the html
136
}
137         catch (Throwable JavaDoc t)
138         {
139             // eat all exceptions, simply return false
140
retCode = false;
141         }
142
143         return retCode;
144     }
145
146 }
147
Popular Tags