1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.db.OptimizerTrace |
4 | |
5 | Copyright 2000, 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.iapi.db; |
22 | |
23 | import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; |
24 | import org.apache.derby.iapi.sql.conn.ConnectionUtil; |
25 | |
26 | /** |
27 | <P> |
28 | This class provides static methods for controlling the |
29 | optimizer tracing in a Cloudscape database. |
30 | |
31 | <P> |
32 | <i> |
33 | Cloudscape reserves the right to change, rename, or remove this interface |
34 | at any time. </i> |
35 | */ |
36 | public class OptimizerTrace |
37 | { |
38 | /** |
39 | * Control whether or not optimizer trace is on. |
40 | * |
41 | * @param onOrOff Whether to turn optimizer trace on (true) or off (false). |
42 | * |
43 | * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.) |
44 | */ |
45 | public static boolean setOptimizerTrace(boolean onOrOff) |
46 | { |
47 | boolean retCode = false; |
48 | |
49 | try |
50 | { |
51 | // Get the current language connection context. This is associated |
52 | // with the current database. |
53 | LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); |
54 | retCode = lcc.setOptimizerTrace(onOrOff); |
55 | } |
56 | catch (Throwable t) |
57 | { |
58 | // eat all exceptions, simply return false |
59 | } |
60 | |
61 | return retCode; |
62 | } |
63 | |
64 | /** |
65 | * Control whether or not optimizer trace is generated in html. |
66 | * |
67 | * @param onOrOff Whether or not optimizer trace will be in html (true) or not (false). |
68 | * |
69 | * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.) |
70 | */ |
71 | public static boolean setOptimizerTraceHtml(boolean onOrOff) |
72 | { |
73 | boolean retCode = false; |
74 | |
75 | try |
76 | { |
77 | // Get the current language connection context. This is associated |
78 | // with the current database. |
79 | LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); |
80 | retCode = lcc.setOptimizerTraceHtml(onOrOff); |
81 | } |
82 | catch (Throwable t) |
83 | { |
84 | // eat all exceptions, simply return false |
85 | } |
86 | |
87 | return retCode; |
88 | } |
89 | |
90 | /** |
91 | * Get the optimizer trace output for the last optimized query as a String. If optimizer trace |
92 | * html is on, then the String will contain the html tags. |
93 | * |
94 | * @return The optimizer trace output for the last optimized query as a String. |
95 | * Null will be returned if optimizer trace output is off or not supported |
96 | * or no trace output was found or an exception occurred. |
97 | */ |
98 | public static String getOptimizerTraceOutput() |
99 | { |
100 | String retCode = null; |
101 | |
102 | try |
103 | { |
104 | // Get the current language connection context. This is associated |
105 | // with the current database. |
106 | LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); |
107 | retCode = lcc.getOptimizerTraceOutput(); |
108 | } |
109 | catch (Throwable t) |
110 | { |
111 | // eat all exceptions, simply return null |
112 | } |
113 | |
114 | return retCode; |
115 | } |
116 | |
117 | /** |
118 | * Send the optimizer trace output for the last optimized query to a file with a .html extension. |
119 | * If optimizer trace html is on, then the output will contain the html tags. |
120 | * |
121 | * @param fileName The name of the file to write to. (.html extension will be added.) |
122 | * |
123 | * @return Whether or not the request was successful. |
124 | * false mayl be returned for a number of reasons, including if optimizer trace output is off or not supported |
125 | * or no trace output was found or an exception occurred. |
126 | */ |
127 | public static boolean writeOptimizerTraceOutputHtml(String fileName) |
128 | { |
129 | boolean retCode = true; |
130 | |
131 | try |
132 | { |
133 | String output = getOptimizerTraceOutput(); |
134 | //RESOLVEOPTIMIZERTRACE - need to write out the html |
135 | } |
136 | catch (Throwable t) |
137 | { |
138 | // eat all exceptions, simply return false |
139 | retCode = false; |
140 | } |
141 | |
142 | return retCode; |
143 | } |
144 | |
145 | } |