com.ricebridge.csvman
Class ResultSetLineProvider

java.lang.Object
  extended bycom.ricebridge.csvman.LineProviderSupportImpl
      extended bycom.ricebridge.csvman.CustomLineProvider
          extended bycom.ricebridge.csvman.ResultSetLineProvider
All Implemented Interfaces:
LineProvider

public class ResultSetLineProvider
extends CustomLineProvider

An implementation of LineProvider that provides data lines for saving from a ResultSet object.

The easiest way to save your CSV data using this format is to use the CsvManager.saveResultSet method.

ResultSetLineProvider is designed to be subclassed. You can change the default implementation by calling the CsvManagerStore.setResultSetLineProviderClass method, and providing a subclass of ResultSetLineProvider. CsvManagerStore can be accessed using CsvManager.getCsvManagerStore().

The Source Code of this Java class is available under a BSD-style license.

See Also:
LineProvider, CustomLineProvider, BasicLineProvider, AsListsLineProvider, TableModelLineProvider, BeanLineProvider

Field Summary
static boolean DEFAULT_ResultSet_saveHeaders
          Default value of ResultSet.saveHeaders (false).
protected  int iFieldCount
          Number of data fields per line.
protected  boolean iFirstLine
          Flag to indicate processing of the first line.
protected  String[] iHeaders
          The column headers
protected  ResultSet iResultSet
          The ResultSet that the data comes from.
protected  boolean iSaveHeaders
          Save the column headers to the CSV file.
static String PROP_ResultSet_saveHeaders
          Save the ResultSet column names as the first line of the CSV file.
 
Constructor Summary
ResultSetLineProvider()
          Create uninitialised for use with setResultSet(java.sql.ResultSet, boolean).
 
Method Summary
protected  void endProcessImpl()
          End the saving process.
protected  String getFieldAsString(int pFieldIndex)
          Get the String value of a ResultSet field.
protected  boolean hasNextLineImpl()
          Return true if ResultSet.next returns true.
protected  String[] nextLineImpl()
          Return current ResultSet row as a String[] array.
protected  void setCsvSpecImpl(CsvSpec pCsvSpec)
          Handle property settings for loading data from a ResultSet.
 void setResultSet(ResultSet pResultSet, boolean pSaveHeaders)
          Set the ResultSet that provides the data to save.
protected  void startProcessImpl()
          Start the saving process.
 
Methods inherited from class com.ricebridge.csvman.CustomLineProvider
setLineSpecImpl
 
Methods inherited from class com.ricebridge.csvman.LineProviderSupportImpl
endProcess, hasNextLine, nextLine, setCsvSpec, setLineSpec, startProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_ResultSet_saveHeaders

public static final String PROP_ResultSet_saveHeaders
Save the ResultSet column names as the first line of the CSV file. (name for CsvSpec.setProperty: ResultSet.saveHeaders).

See Also:
Constant Field Values

DEFAULT_ResultSet_saveHeaders

public static final boolean DEFAULT_ResultSet_saveHeaders
Default value of ResultSet.saveHeaders (false).

See Also:
Constant Field Values

iSaveHeaders

protected boolean iSaveHeaders
Save the column headers to the CSV file.


iResultSet

protected ResultSet iResultSet
The ResultSet that the data comes from.


iHeaders

protected String[] iHeaders
The column headers


iFirstLine

protected boolean iFirstLine
Flag to indicate processing of the first line.


iFieldCount

protected int iFieldCount
Number of data fields per line.

Constructor Detail

ResultSetLineProvider

public ResultSetLineProvider()
Create uninitialised for use with setResultSet(java.sql.ResultSet, boolean).

Method Detail

setCsvSpecImpl

protected void setCsvSpecImpl(CsvSpec pCsvSpec)
                       throws Exception
Handle property settings for loading data from a ResultSet.

You can change these using CsvSpec.

Compatibility note: the correct way to change the settings for a LineProvider is by using the CsvSpec.setProperty method. CSV Manager 1.1 also allowed you to set certain settings as save method parameters (for example: pHasHeaders in CsvManager.save(File, ResultSet, boolean). These parameters will be removed in CSV Manager 2.0, so you should not use them anymore. They are only retained for compatibility with CSV Manager 1.1.

The property you can use here is: PROP_ResultSet_saveHeaders.

Overrides:
setCsvSpecImpl in class CustomLineProvider
Parameters:
pCsvSpec - CsvSpec object
Throws:
Exception
See Also:
LineProvider.setCsvSpec(com.ricebridge.csvman.CsvSpec), PROP_ResultSet_saveHeaders

startProcessImpl

protected void startProcessImpl()
                         throws Exception
Start the saving process.

Overrides:
startProcessImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.startProcess()

hasNextLineImpl

protected boolean hasNextLineImpl()
                           throws Exception
Return true if ResultSet.next returns true.

Specified by:
hasNextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.hasNextLine, nextLineImpl

nextLineImpl

protected String[] nextLineImpl()
                         throws Exception
Return current ResultSet row as a String[] array.

Specified by:
nextLineImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.nextLine, hasNextLineImpl

endProcessImpl

protected void endProcessImpl()
                       throws Exception
End the saving process.

Overrides:
endProcessImpl in class CustomLineProvider
Throws:
Exception
See Also:
LineProvider.endProcess()

setResultSet

public void setResultSet(ResultSet pResultSet,
                         boolean pSaveHeaders)
Set the ResultSet that provides the data to save.

The default number of fields per line is taken from ResultSetMetaData.getColumnCount and the headers (output as the first line when PROP_ResultSet_saveHeaders is true), are taken from ResultSetMetaData.getColumnName.

Parameters:
pResultSet - ResultSet providing data
pSaveHeaders - Save the ResultSet headers as first line (old parameter, use PROP_ResultSet_saveHeaders instead)

getFieldAsString

protected String getFieldAsString(int pFieldIndex)
Get the String value of a ResultSet field.



Copyright © 2003-2006 Ricebridge