Package adams.flow.source
Class TimeseriesDbReader
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,VariableChangeListener
,Actor
,ErrorHandler
,OutputProducer
,Serializable
,Comparable
public class TimeseriesDbReader extends AbstractDbSource
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 Summary
Fields Modifier and Type Field Description protected String
m_ColumnID
the ID column.protected int
m_ColumnIDIndex
the ID column index.protected int
m_ColumnIDType
the ID column type.protected String
m_ColumnTimestamp
the timestamp column.protected int
m_ColumnTimestampIndex
the timestamp column type.protected int
m_ColumnTimestampType
the timestamp column index.protected String
m_ColumnValue
the value column.protected int
m_ColumnValueIndex
the value column index.protected int
m_ColumnValueType
the value column type.protected ResultSet
m_ResultSet
the resultset for retrieving the data.protected SQLStatement
m_SQL
the SQL statement to execute.protected Timeseries
m_Timeseries
the current container.-
Fields inherited from class adams.flow.source.AbstractDbSource
m_DatabaseConnection
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description TimeseriesDbReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
analyzeColumns()
Analyzes the columns.String
columnIDTipText()
Returns the tip text for this property.String
columnTimestampTipText()
Returns the tip text for this property.String
columnValueTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.Class[]
generates()
Returns the class of objects that it generates.String
getColumnID()
Returns the name of the ID column.String
getColumnTimestamp()
Returns the name of the timestamp column.String
getColumnValue()
Returns the name of the value column.protected AbstractDatabaseConnection
getDatabaseConnection()
Determines the database connection in the flow.protected AbstractDatabaseConnection
getDefaultDatabaseConnection()
Returns the default database connection.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.SQLStatement
getSQL()
Returns the SQL statement to run.String
globalInfo()
Returns a string describing the object.boolean
hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.Token
output()
Returns the generated token.protected String
queryDatabase()
Performs the actual database query.protected Timeseries
read()
Completes and returns the last timeseries that was started.protected TimeseriesPoint
readDataPoint()
Reads the next timeseries data point.protected void
reset()
Resets the scheme.void
setColumnID(String value)
Sets the name of the ID column.void
setColumnTimestamp(String value)
Sets the name of the timestamp column.void
setColumnValue(String value)
Sets the name of the value column.void
setSQL(SQLStatement value)
Sets the SQL statement to run.String
SQLTipText()
Returns the tip text for this property.void
wrapUp()
Cleans up after the execution has finished.-
Methods inherited from class adams.flow.source.AbstractDbSource
doExecute, initialize, setUpDatabaseConnection
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, preExecute, pruneBackup, pruneBackup, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
m_SQL
protected SQLStatement m_SQL
the SQL statement to execute.
-
m_ColumnID
protected String m_ColumnID
the ID column.
-
m_ColumnIDType
protected int m_ColumnIDType
the ID column type.
-
m_ColumnIDIndex
protected int m_ColumnIDIndex
the ID column index.
-
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.
-
m_Timeseries
protected Timeseries m_Timeseries
the current container.
-
m_ResultSet
protected transient ResultSet m_ResultSet
the resultset for retrieving the data.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in classAbstractActor
-
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.
-
setColumnID
public void setColumnID(String value)
Sets the name of the ID column.- Parameters:
value
- the column name
-
getColumnID
public String getColumnID()
Returns the name of the ID column.- Returns:
- the column name
-
columnIDTipText
public String columnIDTipText()
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.
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Returns:
- the Class of the generated tokens
-
getDefaultDatabaseConnection
protected AbstractDatabaseConnection getDefaultDatabaseConnection()
Returns the default database connection.- Specified by:
getDefaultDatabaseConnection
in classAbstractDbSource
- Returns:
- the default database connection
-
getDatabaseConnection
protected AbstractDatabaseConnection getDatabaseConnection()
Determines the database connection in the flow.- Specified by:
getDatabaseConnection
in classAbstractDbSource
- Returns:
- the database connection to use
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
readDataPoint
protected TimeseriesPoint readDataPoint() throws Exception
Reads the next timeseries data point.- Returns:
- the next data point
- Throws:
Exception
- if reading of timeseries data fails
-
read
protected Timeseries read() throws Exception
Completes and returns the last timeseries that was started.- Returns:
- the last timeseries, null if none previously started
- Throws:
Exception
- if reading of timeseries data fails
-
analyzeColumns
protected void analyzeColumns() throws Exception
Analyzes the columns.- Throws:
Exception
- if columns not present or of wrong type
-
queryDatabase
protected String queryDatabase()
Performs the actual database query.- Specified by:
queryDatabase
in classAbstractDbSource
- Returns:
- null if everything is fine, otherwise error message
-
hasPendingOutput
public boolean hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.- Returns:
- true if there is pending output
-
output
public Token output()
Returns the generated token.- Returns:
- the generated token
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.- Specified by:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractDbSource
-
-