Package org.apache.derby.tools
Class JDBCDisplayUtil
- java.lang.Object
-
- org.apache.derby.tools.JDBCDisplayUtil
-
public class JDBCDisplayUtil extends java.lang.ObjectThis class contains utility methods for displaying JDBC objects and results.All of the methods are static. The output stream to write to is always passed in, along with the JDBC objects to display.
-
-
Field Summary
Fields Modifier and Type Field Description private static intMAX_RETRIESprivate static intmaxWidthprivate static intMINWIDTHprivate static booleanshowSelectCount
-
Constructor Summary
Constructors Constructor Description JDBCDisplayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckNotNull(java.lang.Object o, java.lang.String what)Check if an object is null, and if it is, throw an exception with an informative parameter about what was null.static intDisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd)static intDisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd)Print a banner containing the column labels separated with '|'s and a line of '-'s.static voidDisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)static voidDisplayCurrentRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn)Display the current row of the result set along with a banner.static voidDisplayMultipleResults(java.io.PrintWriter out, java.util.List<java.sql.ResultSet> resultSets, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths)private static voidDisplayNestedResults(java.io.PrintStream out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel)private static voidDisplayNestedResults(java.io.PrintWriter out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel)static voidDisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)static voidDisplayNextRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn)Fetch the next row of the result set, and if it exists format and display a banner and the row.static voidDisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)static voidDisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn)static voidDisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths)static voidDisplayResults(java.io.PrintWriter out, java.sql.Statement stmt, java.sql.Connection conn)Pretty-print the results of a statement that has been executed.private static voidDisplayRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.ResultSetMetaData rsmd, int rowLen, java.util.Vector<java.sql.ResultSet> nestedResults, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidDisplayRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.ResultSetMetaData rsmd, int rowLen, java.util.Vector<java.sql.ResultSet> nestedResults, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)Print one row of a result set, padding each field to the display width and separating them with '|'s(package private) static voidDisplayUpdateCount(java.io.PrintStream out, int count, int indentLevel)(package private) static voidDisplayUpdateCount(java.io.PrintWriter out, int count, int indentLevel)static voiddoTrace(java.io.PrintStream out, java.lang.Exception e)static voiddoTrace(java.io.PrintWriter out, java.lang.Exception e)If the property ij.exceptionTrace is true, display the stack trace to the print stream.private static int[]getColumnDisplayWidths(java.sql.ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput)Calculates column display widths from the default widths of the result set.static booleangetShowSelectCount()private static booleangetSystemBoolean(java.lang.String name)Get an ij boolean system property.private static voidindent(java.io.PrintStream out, int indentLevel)private static voidindent(java.io.PrintWriter out, int indentLevel)private static intindent_DisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static intindent_DisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayCurrentRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayNextRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayResults(java.io.PrintWriter out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindent_DisplayResults(java.io.PrintWriter out, java.util.List<java.sql.ResultSet> resultSets, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)private static voidindentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.String text)private static voidindentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.StringBuffer text)private static voidindentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.String text)private static voidindentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.StringBuffer text)static java.lang.StringmapNull(java.lang.String s, java.lang.String nullValue)Map the string to the value if it is null.static voidsetMaxDisplayWidth(int maxDisplayWidth)static voidsetShowSelectCount(boolean newValue)static voidShowException(java.io.PrintStream out, java.lang.Throwable e)static voidShowException(java.io.PrintWriter out, java.lang.Throwable e)Print information about the exception to the given PrintWriter.static voidShowSQLException(java.io.PrintStream out, java.sql.SQLException e)static voidShowSQLException(java.io.PrintWriter out, java.sql.SQLException e)Print information about the SQL exception to the given PrintWriter.static voidShowWarnings(java.io.PrintStream out, java.sql.Connection theConnection)static voidShowWarnings(java.io.PrintStream out, java.sql.ResultSet rs)static voidShowWarnings(java.io.PrintStream out, java.sql.SQLWarning warning)static voidShowWarnings(java.io.PrintStream out, java.sql.Statement s)static voidShowWarnings(java.io.PrintWriter out, java.sql.Connection theConnection)Print information about the SQL warnings for the connection to the given PrintWriter.static voidShowWarnings(java.io.PrintWriter out, java.sql.ResultSet rs)Print information about the SQL warnings for the ResultSet to the given PrintWriter.static voidShowWarnings(java.io.PrintWriter out, java.sql.SQLWarning warning)static voidShowWarnings(java.io.PrintWriter out, java.sql.Statement s)Print information about the SQL warnings for the Statement to the given PrintWriter.
-
-
-
Field Detail
-
MINWIDTH
private static final int MINWIDTH
- See Also:
- Constant Field Values
-
maxWidth
private static int maxWidth
-
showSelectCount
private static boolean showSelectCount
-
MAX_RETRIES
private static final int MAX_RETRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getShowSelectCount
public static boolean getShowSelectCount()
-
setShowSelectCount
public static void setShowSelectCount(boolean newValue)
-
ShowException
public static void ShowException(java.io.PrintWriter out, java.lang.Throwable e)Print information about the exception to the given PrintWriter. For non-SQLExceptions, does a stack trace. For SQLExceptions, print a standard error message and walk the list, if any.- Parameters:
out- the place to write toe- the exception to display
-
ShowSQLException
public static void ShowSQLException(java.io.PrintWriter out, java.sql.SQLException e)Print information about the SQL exception to the given PrintWriter. Walk the list of exceptions, if any.- Parameters:
out- the place to write toe- the exception to display
-
ShowWarnings
public static void ShowWarnings(java.io.PrintWriter out, java.sql.Connection theConnection)Print information about the SQL warnings for the connection to the given PrintWriter. Walks the list of exceptions, if any.- Parameters:
out- the place to write totheConnection- the connection that may have warnings.
-
ShowWarnings
public static void ShowWarnings(java.io.PrintWriter out, java.sql.SQLWarning warning)- Parameters:
out- the place to write towarning- the SQLWarning
-
ShowWarnings
public static void ShowWarnings(java.io.PrintWriter out, java.sql.ResultSet rs)Print information about the SQL warnings for the ResultSet to the given PrintWriter. Walk the list of exceptions, if any.- Parameters:
out- the place to write tors- the ResultSet that may have warnings on it
-
ShowWarnings
public static void ShowWarnings(java.io.PrintWriter out, java.sql.Statement s)Print information about the SQL warnings for the Statement to the given PrintWriter. Walks the list of exceptions, if any.- Parameters:
out- the place to write tos- the Statement that may have warnings on it
-
DisplayResults
public static void DisplayResults(java.io.PrintWriter out, java.sql.Statement stmt, java.sql.Connection conn) throws java.sql.SQLExceptionPretty-print the results of a statement that has been executed. If it is a select, gathers and prints the results. Display partial results up to the first error. If it is not a SELECT, determine if rows were involved or not, and print the appropriate message.- Parameters:
out- the place to write tostmt- the Statement to displayconn- the Connection against which the statement was executed- Throws:
java.sql.SQLException- on JDBC access failure
-
indent_DisplayResults
private static void indent_DisplayResults(java.io.PrintWriter out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayUpdateCount
static void DisplayUpdateCount(java.io.PrintWriter out, int count, int indentLevel)- Parameters:
out- the place to write tocount- the update count to displayindentLevel- number of tab stops to indent line
-
getColumnDisplayWidths
private static int[] getColumnDisplayWidths(java.sql.ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput) throws java.sql.SQLExceptionCalculates column display widths from the default widths of the result set.- Throws:
java.sql.SQLException
-
DisplayMultipleResults
public static void DisplayMultipleResults(java.io.PrintWriter out, java.util.List<java.sql.ResultSet> resultSets, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Parameters:
out- the place to write toresultSets- list ofResultSets to displayconn- the connection against which theResultSets were retrieveddisplayColumns- column numbers to display,nullif alldisplayColumnWidths- column widths, in characters, ifdisplayColumnsis specified- Throws:
java.sql.SQLException- on JDBC access failure
-
DisplayResults
public static void DisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Parameters:
out- the place to write tors- theResultSetto displayconn- the connection against which theResultSetwas retrieveddisplayColumns- column numbers to display,nullif alldisplayColumnWidths- column widths, in characters, ifdisplayColumnsis specified- Throws:
java.sql.SQLException- on JDBC access failure
-
indent_DisplayResults
private static void indent_DisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayResults
private static void indent_DisplayResults(java.io.PrintWriter out, java.util.List<java.sql.ResultSet> resultSets, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayNestedResults
private static void DisplayNestedResults(java.io.PrintWriter out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel) throws java.sql.SQLException- Parameters:
out- the place to write tonr- the vector of resultsconn- the Connection against which the ResultSet was retrievedindentLevel- number of tab stops to indent line- Throws:
java.sql.SQLException- thrown on access error
-
DisplayNextRow
public static void DisplayNextRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn) throws java.sql.SQLExceptionFetch the next row of the result set, and if it exists format and display a banner and the row.- Parameters:
out- the place to write tors- the ResultSet in useconn- the Connection against which the ResultSet was retrieved- Throws:
java.sql.SQLException- on JDBC access failure
-
indent_DisplayNextRow
private static void indent_DisplayNextRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayCurrentRow
public static void DisplayCurrentRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn) throws java.sql.SQLExceptionDisplay the current row of the result set along with a banner. Assume the result set is on a row.- Parameters:
out- the place to write tors- the ResultSet in useconn- the Connection against which the ResultSet was retrieved- Throws:
java.sql.SQLException- on JDBC access failure
-
indent_DisplayCurrentRow
private static void indent_DisplayCurrentRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayBanner
public static int DisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd) throws java.sql.SQLExceptionPrint a banner containing the column labels separated with '|'s and a line of '-'s. Each field is as wide as the display width reported by the metadata.- Parameters:
out- the place to write torsmd- the ResultSetMetaData to use- Throws:
java.sql.SQLException- on JDBC access failure
-
indent_DisplayBanner
private static int indent_DisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayRow
private static void DisplayRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.ResultSetMetaData rsmd, int rowLen, java.util.Vector<java.sql.ResultSet> nestedResults, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLExceptionPrint one row of a result set, padding each field to the display width and separating them with '|'s- Parameters:
out- the place to write tors- the ResultSet to usersmd- the ResultSetMetaData to userowLen-nestedResults-conn-indentLevel- number of tab stops to indent linedisplayColumns- A list of column numbers to displaydisplayColumnWidths- If displayColumns is set, the width of columns to display, in characters.- Throws:
java.sql.SQLException- thrown on JDBC access failure
-
checkNotNull
public static void checkNotNull(java.lang.Object o, java.lang.String what)Check if an object is null, and if it is, throw an exception with an informative parameter about what was null. The exception is a run-time exception that is internal to ij.- Parameters:
o- the object to testwhat- the information to include in the error if it is null
-
mapNull
public static java.lang.String mapNull(java.lang.String s, java.lang.String nullValue)Map the string to the value if it is null.- Parameters:
s- the string to test for nullnullValue- the value to use if s is null- Returns:
- if s is non-null, s; else nullValue.
-
doTrace
public static void doTrace(java.io.PrintWriter out, java.lang.Exception e)If the property ij.exceptionTrace is true, display the stack trace to the print stream. Otherwise, do nothing.- Parameters:
out- the output stream to write toe- the exception to display
-
setMaxDisplayWidth
public static void setMaxDisplayWidth(int maxDisplayWidth)
-
indentedPrintLine
private static void indentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.String text)
-
indentedPrintLine
private static void indentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.StringBuffer text)
-
indent
private static void indent(java.io.PrintWriter out, int indentLevel)
-
ShowException
public static void ShowException(java.io.PrintStream out, java.lang.Throwable e)
-
ShowSQLException
public static void ShowSQLException(java.io.PrintStream out, java.sql.SQLException e)
-
ShowWarnings
public static void ShowWarnings(java.io.PrintStream out, java.sql.Connection theConnection)
-
ShowWarnings
public static void ShowWarnings(java.io.PrintStream out, java.sql.SQLWarning warning)
-
ShowWarnings
public static void ShowWarnings(java.io.PrintStream out, java.sql.ResultSet rs)
-
ShowWarnings
public static void ShowWarnings(java.io.PrintStream out, java.sql.Statement s)
-
DisplayResults
public static void DisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayResults
private static void indent_DisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayUpdateCount
static void DisplayUpdateCount(java.io.PrintStream out, int count, int indentLevel)
-
DisplayResults
public static void DisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayResults
private static void indent_DisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayNestedResults
private static void DisplayNestedResults(java.io.PrintStream out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayNextRow
public static void DisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayNextRow
private static void indent_DisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayCurrentRow
public static void DisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayCurrentRow
private static void indent_DisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayBanner
public static int DisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
indent_DisplayBanner
private static int indent_DisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
DisplayRow
private static void DisplayRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.ResultSetMetaData rsmd, int rowLen, java.util.Vector<java.sql.ResultSet> nestedResults, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
doTrace
public static void doTrace(java.io.PrintStream out, java.lang.Exception e)
-
indentedPrintLine
private static void indentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.String text)
-
indentedPrintLine
private static void indentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.StringBuffer text)
-
indent
private static void indent(java.io.PrintStream out, int indentLevel)
-
getSystemBoolean
private static boolean getSystemBoolean(java.lang.String name)
Get an ij boolean system property.- Parameters:
name- name of the property
-
-