Class TimeseriesDbReader

  • All Implemented Interfaces:
    AdditionalInformationHandler, CleanUpHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, DatabaseConnectionUser, VariableChangeListener, Actor, ErrorHandler, InputConsumer, OutputProducer, Serializable, Comparable

    public class TimeseriesDbReader
    extends AbstractDbTransformer
    Outputs timeseries containers generated from an SQL SELECT statement.
    A new container is started, whenever the value of the ID column changes (hence you need to ensure that the data is ordered on this column).

    Input/output:
    - generates:
       adams.data.timeseries.Timeseries


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: TimeseriesDbReader
     
    -annotation <adams.core.base.BaseText> (property: annotations)
        The annotations to attach to this actor.
        default: 
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded 
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow gets stopped in case this actor encounters an error;
         useful for critical actors.
        default: false
     
    -sql <adams.db.SQLStatement> (property: SQL)
        The SQL statement that selects the timeseries data.
        default: select id,timestamp,value from table order by id
     
    -column-id <java.lang.String> (property: columnID)
        The name of the column containing the ID that distinguishes the timeseries 
        (accepted types: numeric, string); if left empty, the first string column 
        from the SQL statement is used.
        default: 
     
    -column-timestamp <java.lang.String> (property: columnTimestamp)
        The name of the column containing the timestamp for a data point (accepted 
        types: integer, date, time, datetime, timestamp); if left empty, the first 
        date-like column from the SQL statement is used.
        default: 
     
    -column-value <java.lang.String> (property: columnValue)
        The name of the column containing the value for a data point (accepted types:
         numeric); if left empty, the first numeric column from the SQL statement 
        is used.
        default: 
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_SQL

        protected SQLStatement m_SQL
        the SQL statement to execute.
      • m_ColumnTimestamp

        protected String m_ColumnTimestamp
        the timestamp column.
      • m_ColumnTimestampType

        protected int m_ColumnTimestampType
        the timestamp column index.
      • m_ColumnTimestampIndex

        protected int m_ColumnTimestampIndex
        the timestamp column type.
      • m_ColumnValue

        protected String m_ColumnValue
        the value column.
      • m_ColumnValueType

        protected int m_ColumnValueType
        the value column type.
      • m_ColumnValueIndex

        protected int m_ColumnValueIndex
        the value column index.
    • Constructor Detail

      • TimeseriesDbReader

        public TimeseriesDbReader()
    • Method Detail

      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class AbstractActor
      • setSQL

        public void setSQL​(SQLStatement value)
        Sets the SQL statement to run.
        Parameters:
        value - the statement
      • getSQL

        public SQLStatement getSQL()
        Returns the SQL statement to run.
        Returns:
        the statement
      • SQLTipText

        public String SQLTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColumnTimestamp

        public void setColumnTimestamp​(String value)
        Sets the name of the timestamp column.
        Parameters:
        value - the column name
      • getColumnTimestamp

        public String getColumnTimestamp()
        Returns the name of the timestamp column.
        Returns:
        the column name
      • columnTimestampTipText

        public String columnTimestampTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setColumnValue

        public void setColumnValue​(String value)
        Sets the name of the value column.
        Parameters:
        value - the column name
      • getColumnValue

        public String getColumnValue()
        Returns the name of the value column.
        Returns:
        the column name
      • columnValueTipText

        public String columnValueTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • accepts

        public Class[] accepts()
        Returns the class of objects that it accepts.
        Returns:
        the Class of the accepted tokens
      • generates

        public Class[] generates()
        Returns the class of objects that it generates.
        Returns:
        the Class of the generated tokens
      • readDataPoint

        protected TimeseriesPoint readDataPoint​(ResultSet rs)
                                         throws Exception
        Reads the next timeseries data point.
        Parameters:
        rs - the resultset to read from
        Returns:
        the next data point
        Throws:
        Exception - if reading of timeseries data fails
      • read

        protected Timeseries read​(ResultSet rs)
                           throws Exception
        Completes and returns the last timeseries that was started.
        Parameters:
        rs - the resultset to read from
        Returns:
        the last timeseries, null if none previously started
        Throws:
        Exception - if reading of timeseries data fails
      • analyzeColumns

        protected void analyzeColumns​(ResultSet rs)
                               throws Exception
        Analyzes the columns.
        Parameters:
        rs - the resultset to obtain the meta-data from
        Throws:
        Exception - if columns not present or of wrong type
      • queryDatabase

        protected String queryDatabase()
        Performs the actual database query.
        Specified by:
        queryDatabase in class AbstractDbTransformer
        Returns:
        null if everything is fine, otherwise error message