001: /*
002:
003: Derby - Class org.apache.derby.iapi.db.OptimizerTrace
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.db;
023:
024: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
025: import org.apache.derby.iapi.sql.conn.ConnectionUtil;
026:
027: /**
028: <P>
029: This class provides static methods for controlling the
030: optimizer tracing in a Cloudscape database.
031:
032: <P>
033: <i>
034: Cloudscape reserves the right to change, rename, or remove this interface
035: at any time. </i>
036: */
037: public class OptimizerTrace {
038: /**
039: * Control whether or not optimizer trace is on.
040: *
041: * @param onOrOff Whether to turn optimizer trace on (true) or off (false).
042: *
043: * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.)
044: */
045: public static boolean setOptimizerTrace(boolean onOrOff) {
046: boolean retCode = false;
047:
048: try {
049: // Get the current language connection context. This is associated
050: // with the current database.
051: LanguageConnectionContext lcc = ConnectionUtil
052: .getCurrentLCC();
053: retCode = lcc.setOptimizerTrace(onOrOff);
054: } catch (Throwable t) {
055: // eat all exceptions, simply return false
056: }
057:
058: return retCode;
059: }
060:
061: /**
062: * Control whether or not optimizer trace is generated in html.
063: *
064: * @param onOrOff Whether or not optimizer trace will be in html (true) or not (false).
065: *
066: * @return Whether or not the call was successful. (false will be returned when optimizer tracing is not supported.)
067: */
068: public static boolean setOptimizerTraceHtml(boolean onOrOff) {
069: boolean retCode = false;
070:
071: try {
072: // Get the current language connection context. This is associated
073: // with the current database.
074: LanguageConnectionContext lcc = ConnectionUtil
075: .getCurrentLCC();
076: retCode = lcc.setOptimizerTraceHtml(onOrOff);
077: } catch (Throwable t) {
078: // eat all exceptions, simply return false
079: }
080:
081: return retCode;
082: }
083:
084: /**
085: * Get the optimizer trace output for the last optimized query as a String. If optimizer trace
086: * html is on, then the String will contain the html tags.
087: *
088: * @return The optimizer trace output for the last optimized query as a String.
089: * Null will be returned if optimizer trace output is off or not supported
090: * or no trace output was found or an exception occurred.
091: */
092: public static String getOptimizerTraceOutput() {
093: String retCode = null;
094:
095: try {
096: // Get the current language connection context. This is associated
097: // with the current database.
098: LanguageConnectionContext lcc = ConnectionUtil
099: .getCurrentLCC();
100: retCode = lcc.getOptimizerTraceOutput();
101: } catch (Throwable t) {
102: // eat all exceptions, simply return null
103: }
104:
105: return retCode;
106: }
107:
108: /**
109: * Send the optimizer trace output for the last optimized query to a file with a .html extension.
110: * If optimizer trace html is on, then the output will contain the html tags.
111: *
112: * @param fileName The name of the file to write to. (.html extension will be added.)
113: *
114: * @return Whether or not the request was successful.
115: * false mayl be returned for a number of reasons, including if optimizer trace output is off or not supported
116: * or no trace output was found or an exception occurred.
117: */
118: public static boolean writeOptimizerTraceOutputHtml(String fileName) {
119: boolean retCode = true;
120:
121: try {
122: String output = getOptimizerTraceOutput();
123: //RESOLVEOPTIMIZERTRACE - need to write out the html
124: } catch (Throwable t) {
125: // eat all exceptions, simply return false
126: retCode = false;
127: }
128:
129: return retCode;
130: }
131:
132: }
|