com.xigole.util.sql.outputformatter
Class DefaultFormatter

java.lang.Object
  extended by com.xigole.util.sql.outputformatter.DefaultFormatter
All Implemented Interfaces:
JisqlFormatter

public class DefaultFormatter
extends java.lang.Object
implements JisqlFormatter

This is the default formatter for Jisql. It outputs data in a "normal" format that is similar to most other database command line formatters.


Constructor Summary
DefaultFormatter()
           
 
Method Summary
 void consumeOptions(joptsimple.OptionSet options)
          Consumes any options that were specified on the command line.
 void formatData(java.io.PrintStream out, java.sql.ResultSet resultSet, java.sql.ResultSetMetaData metaData)
          Called to output the data.
 void formatFooter(java.io.PrintStream out, java.sql.ResultSetMetaData metaData)
          Outputs a footer for a query.
 void formatHeader(java.io.PrintStream out, java.sql.ResultSetMetaData metaData)
          Outputs a header for a query.
 void setSupportedOptions(joptsimple.OptionParser parser)
          Sets a the option list for this formatter.
 void usage(java.io.PrintStream out)
          Called to output a usage message to the command line window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFormatter

public DefaultFormatter()
Method Detail

setSupportedOptions

public void setSupportedOptions(joptsimple.OptionParser parser)
Sets a the option list for this formatter. This formatter accepts the following options:
  • -noheader do not print the header column info.
  • -spacer The character to use for "empty" space. This defaults to the space character. From mrider - "I added the ability to specify the spacer for columns - which used to be the single char ' '. I did this because of brain-dead Windows' command line copy/paste. It seems that when a line of text ends in space, copy does not copy that space. Which makes it difficult to copy/paste into another program. This can probably be ignored most of the time."
  • -delimiter Specify a single character delimiter for columns.
  • -trim trim the spaces from columns.
  • -nonull print an empty string instead of the word "NULL" when there is a null value.
  • -left left justify the output
  • -w specify the max width of a column. The default is 2048
  • -debug add debug headers to the output
  • Specified by:
    setSupportedOptions in interface JisqlFormatter
    Parameters:
    parser - the OptionParser to use.

    consumeOptions

    public void consumeOptions(joptsimple.OptionSet options)
                        throws java.lang.Exception
    Consumes any options that were specified on the command line.

    Specified by:
    consumeOptions in interface JisqlFormatter
    Parameters:
    options - the OptionSet that the main driver is using.
    Throws:
    java.lang.Exception - if there is a problem parsing the command line arguments.

    usage

    public void usage(java.io.PrintStream out)
    Called to output a usage message to the command line window. This message should contain information on how to call the formatter.

    Specified by:
    usage in interface JisqlFormatter
    Parameters:
    out - the stream to print the output on

    formatHeader

    public void formatHeader(java.io.PrintStream out,
                             java.sql.ResultSetMetaData metaData)
                      throws java.lang.Exception
    Outputs a header for a query. For the DefaultFormatter the data is output by default unless the "noheader" option is specified.

    Specified by:
    formatHeader in interface JisqlFormatter
    Parameters:
    out - - a PrintStream to send any output to.
    metaData - - the ResultSetMetaData for the output.
    Throws:
    java.lang.Exception

    formatData

    public void formatData(java.io.PrintStream out,
                           java.sql.ResultSet resultSet,
                           java.sql.ResultSetMetaData metaData)
                    throws java.lang.Exception
    Called to output the data.

    Specified by:
    formatData in interface JisqlFormatter
    Parameters:
    out - the PrintStream to output data to.
    resultSet - the ResultSet for the row.
    metaData - the ResultSetMetaData for the row.
    Throws:
    java.lang.Exception

    formatFooter

    public void formatFooter(java.io.PrintStream out,
                             java.sql.ResultSetMetaData metaData)
                      throws java.lang.Exception
    Outputs a footer for a query. This is called after all data has been exhausted. This method isn't used in the DefaultFormatter.

    Specified by:
    formatFooter in interface JisqlFormatter
    Parameters:
    out - the PrintStream to output data to.
    metaData - the ResultSetMetaData for the output.
    Throws:
    java.lang.Exception