Package adams.data.spreadsheet.sql
Class Reader
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.data.spreadsheet.sql.Reader
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Stoppable
,Serializable
public class Reader extends LoggingObject implements Stoppable
For reading data from a database.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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.protected AbstractTypeMapper
m_TypeMapper
the type mapper to use.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description Reader(AbstractTypeMapper typeMapper, Class rowClass)
Initializes the reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SpreadSheet
getHeader()
Returns the current header.Class
getRowClass()
Returns the row class in use.AbstractTypeMapper
getTypeMapper()
Returns the type mapper in use.void
initHeader(ResultSet rs)
Initializes the headerboolean
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
setLoggingLevel(LoggingLevel value)
Sets the logging level.void
stopExecution()
Stops the execution.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_RowClass
protected Class m_RowClass
the row class to use.
-
m_TypeMapper
protected AbstractTypeMapper m_TypeMapper
the type mapper 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
-
Reader
public Reader(AbstractTypeMapper typeMapper, Class rowClass)
Initializes the reader.- Parameters:
rowClass
- the class for the rows in the spreadsheet, e.g.DenseDataRow
typeMapper
- the type mapper to use
-
-
Method Detail
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Parameters:
value
- the level
-
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
-
getTypeMapper
public AbstractTypeMapper getTypeMapper()
Returns the type mapper in use.- Returns:
- the type mapper
-
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 spreadsheetmax
- 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 interfaceStoppable
-
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
-
-