Package adams.flow.transformer
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 Summary
Fields Modifier and Type Field Description 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 SQLStatement
m_SQL
the SQL statement to execute.static String
PLACEHOLDER_ID
the placeholder for the ID.-
Fields inherited from class adams.flow.transformer.AbstractDbTransformer
m_DatabaseConnection
-
Fields inherited from class adams.flow.transformer.AbstractTransformer
BACKUP_INPUT, BACKUP_OUTPUT, m_InputToken, m_OutputToken
-
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 Class[]
accepts()
Returns the class of objects that it accepts.protected void
analyzeColumns(ResultSet rs)
Analyzes the columns.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
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.protected String
queryDatabase()
Performs the actual database query.protected Timeseries
read(ResultSet rs)
Completes and returns the last timeseries that was started.protected TimeseriesPoint
readDataPoint(ResultSet rs)
Reads the next timeseries data point.protected void
reset()
Resets the scheme.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.-
Methods inherited from class adams.flow.transformer.AbstractDbTransformer
doExecute, initialize, setUpDatabaseConnection, wrapUp
-
Methods inherited from class adams.flow.transformer.AbstractTransformer
backupState, currentInput, execute, hasInput, hasPendingOutput, input, output, postExecute, restoreState
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, 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, preExecute, pruneBackup, pruneBackup, 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, 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
-
PLACEHOLDER_ID
public static final String PLACEHOLDER_ID
the placeholder for the ID.- See Also:
- Constant Field Values
-
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.
-
-
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.
-
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
-
getDefaultDatabaseConnection
protected AbstractDatabaseConnection getDefaultDatabaseConnection()
Returns the default database connection.- Specified by:
getDefaultDatabaseConnection
in classAbstractDbTransformer
- Returns:
- the default database connection
-
getDatabaseConnection
protected AbstractDatabaseConnection getDatabaseConnection()
Determines the database connection in the flow.- Specified by:
getDatabaseConnection
in classAbstractDbTransformer
- 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(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 classAbstractDbTransformer
- Returns:
- null if everything is fine, otherwise error message
-
-