Package org.apache.derby.tools
Class JDBCDisplayUtil
- java.lang.Object
-
- org.apache.derby.tools.JDBCDisplayUtil
-
public class JDBCDisplayUtil extends java.lang.Object
This 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 int
MAX_RETRIES
private static int
maxWidth
private static int
MINWIDTH
private static boolean
showSelectCount
-
Constructor Summary
Constructors Constructor Description JDBCDisplayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static int
DisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd)
static int
DisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd)
Print a banner containing the column labels separated with '|'s and a line of '-'s.static void
DisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)
static void
DisplayCurrentRow(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 void
DisplayMultipleResults(java.io.PrintWriter out, java.util.List<java.sql.ResultSet> resultSets, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths)
private static void
DisplayNestedResults(java.io.PrintStream out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel)
private static void
DisplayNestedResults(java.io.PrintWriter out, java.util.Vector<java.sql.ResultSet> nr, java.sql.Connection conn, int indentLevel)
static void
DisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)
static void
DisplayNextRow(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 void
DisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn)
static void
DisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn)
static void
DisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int[] displayColumns, int[] displayColumnWidths)
static void
DisplayResults(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 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)
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)
Print one row of a result set, padding each field to the display width and separating them with '|'s(package private) static void
DisplayUpdateCount(java.io.PrintStream out, int count, int indentLevel)
(package private) static void
DisplayUpdateCount(java.io.PrintWriter out, int count, int indentLevel)
static void
doTrace(java.io.PrintStream out, java.lang.Exception e)
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.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 boolean
getShowSelectCount()
private static boolean
getSystemBoolean(java.lang.String name)
Get an ij boolean system property.private static void
indent(java.io.PrintStream out, int indentLevel)
private static void
indent(java.io.PrintWriter out, int indentLevel)
private static int
indent_DisplayBanner(java.io.PrintStream out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static int
indent_DisplayBanner(java.io.PrintWriter out, java.sql.ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayCurrentRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayCurrentRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayNextRow(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayNextRow(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayResults(java.io.PrintStream out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayResults(java.io.PrintStream out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayResults(java.io.PrintWriter out, java.sql.ResultSet rs, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
private static void
indent_DisplayResults(java.io.PrintWriter out, java.sql.Statement stmt, java.sql.Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
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)
private static void
indentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.String text)
private static void
indentedPrintLine(java.io.PrintStream out, int indentLevel, java.lang.StringBuffer text)
private static void
indentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.String text)
private static void
indentedPrintLine(java.io.PrintWriter out, int indentLevel, java.lang.StringBuffer text)
static java.lang.String
mapNull(java.lang.String s, java.lang.String nullValue)
Map the string to the value if it is null.static void
setMaxDisplayWidth(int maxDisplayWidth)
static void
setShowSelectCount(boolean newValue)
static void
ShowException(java.io.PrintStream out, java.lang.Throwable e)
static void
ShowException(java.io.PrintWriter out, java.lang.Throwable e)
Print information about the exception to the given PrintWriter.static void
ShowSQLException(java.io.PrintStream out, java.sql.SQLException e)
static void
ShowSQLException(java.io.PrintWriter out, java.sql.SQLException e)
Print information about the SQL exception to the given PrintWriter.static void
ShowWarnings(java.io.PrintStream out, java.sql.Connection theConnection)
static void
ShowWarnings(java.io.PrintStream out, java.sql.ResultSet rs)
static void
ShowWarnings(java.io.PrintStream out, java.sql.SQLWarning warning)
static void
ShowWarnings(java.io.PrintStream out, java.sql.Statement s)
static void
ShowWarnings(java.io.PrintWriter out, java.sql.Connection theConnection)
Print information about the SQL warnings for the connection to the given PrintWriter.static void
ShowWarnings(java.io.PrintWriter out, java.sql.ResultSet rs)
Print information about the SQL warnings for the ResultSet to the given PrintWriter.static void
ShowWarnings(java.io.PrintWriter out, java.sql.SQLWarning warning)
static void
ShowWarnings(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.SQLException
Pretty-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.SQLException
Calculates 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 ofResultSet
s to displayconn
- the connection against which theResultSet
s were retrieveddisplayColumns
- column numbers to display,null
if alldisplayColumnWidths
- column widths, in characters, ifdisplayColumns
is 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
- theResultSet
to displayconn
- the connection against which theResultSet
was retrieveddisplayColumns
- column numbers to display,null
if alldisplayColumnWidths
- column widths, in characters, ifdisplayColumns
is 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.SQLException
Fetch 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.SQLException
Display 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.SQLException
Print 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.SQLException
Print 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
-
-