com.xigole.util.sql.outputformatter
Class CSVFormatter

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

public class CSVFormatter
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
CSVFormatter()
           
 
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 an optional header for the CSV data.
 void setSupportedOptions(joptsimple.OptionParser parser)
          Sets a the supported 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

CSVFormatter

public CSVFormatter()
Method Detail

setSupportedOptions

public void setSupportedOptions(joptsimple.OptionParser parser)
Sets a the supported option list for this formatter. This formatter accepts the following options:

 

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 PrintStream to display the usage message on.

formatHeader

public void formatHeader(java.io.PrintStream out,
                         java.sql.ResultSetMetaData metaData)
                  throws java.lang.Exception
Outputs an optional header for the CSV data. This header is only enabled if the "colnames" parameter is included.

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. This class uses a third party library to output the CSV data. The library escapes the data as needed.

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. For the CSVFormatter this method does nothing.

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