adams.data.spreadsheet
Class SqlUtils.Reader

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.data.spreadsheet.SqlUtils.Reader
All Implemented Interfaces:
SizeOfHandler, Stoppable, Serializable
Enclosing class:
SqlUtils

public static class SqlUtils.Reader
extends ConsoleObject
implements Stoppable

For reading data from a database.

Version:
$Revision: 7087 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
protected  boolean m_Finished
          indicates whether the reading has finished.
protected  SpreadSheet m_Header
          the header.
protected  Class m_RowClass
          the row class to use.
protected  boolean m_Stopped
          whether the reading was stopped.
protected  int[] m_Type
          the column types.
 
Constructor Summary
SqlUtils.Reader(Class rowClass)
          Initializes the reader.
 
Method Summary
 SpreadSheet getHeader()
          Returns the current header.
 Class getRowClass()
          Returns the row class in use.
 void initHeader(ResultSet rs)
          Initializes the header
 boolean isFinished()
          Returns whether the reader has finished reading data.
 boolean isStopped()
          Returns whether the reader has been stopped.
 SpreadSheet read(ResultSet rs)
          Reads all the data from the provided result set.
 SpreadSheet read(ResultSet rs, int max)
          Reads the data from the provided result set, up to the specified maximum of rows.
 void stopExecution()
          Stops the execution.
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_RowClass

protected Class m_RowClass
the row class to use.


m_Finished

protected boolean m_Finished
indicates whether the reading has finished.


m_Stopped

protected boolean m_Stopped
whether the reading was stopped.


m_Header

protected SpreadSheet m_Header
the header.


m_Type

protected int[] m_Type
the column types.

Constructor Detail

SqlUtils.Reader

public SqlUtils.Reader(Class rowClass)
Initializes the reader.

Parameters:
rowClass - the class for the rows in the spreadsheet, e.g. DenseDataRow
Method Detail

initHeader

public void initHeader(ResultSet rs)
                throws SQLException
Initializes the header

Parameters:
rs - the resultset to use as basis
Throws:
SQLException - if accessing of meta-data fails

getRowClass

public Class getRowClass()
Returns the row class in use.

Returns:
the class

getHeader

public SpreadSheet getHeader()
Returns the current header.

Returns:
the header, null if not initialized yet
See Also:
initHeader(ResultSet)

read

public SpreadSheet read(ResultSet rs)
                 throws SQLException
Reads all the data from the provided result set.

Parameters:
rs - the result set to turn into a spreadsheet
Returns:
the generated spreadsheet
Throws:
SQLException - if reading fails

read

public SpreadSheet read(ResultSet rs,
                        int max)
                 throws SQLException
Reads the data from the provided result set, up to the specified maximum of rows. Automatically closes the result set if all data has been read.

Parameters:
rs - the result set to turn into a spreadsheet
max - the maximum number of rows to read, 0 or less means all
Returns:
the generated spreadsheet
Throws:
SQLException - if reading fails

stopExecution

public void stopExecution()
Stops the execution.

Specified by:
stopExecution in interface Stoppable

isStopped

public boolean isStopped()
Returns whether the reader has been stopped.

Returns:
true if stopped

isFinished

public boolean isFinished()
Returns whether the reader has finished reading data.

Returns:
true if finished


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.