Package adams.flow.sink
Class SpreadSheetDbWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler,CleanUpHandler,Destroyable,GlobalInfoSupporter,BatchSizeSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,QuickInfoSupporter,ShallowCopySupporter<Actor>,SizeOfHandler,Stoppable,StoppableWithFeedback,VariablesInspectionHandler,DatabaseConnectionUser,VariableChangeListener,Actor,ErrorHandler,InputConsumer,Serializable,Comparable
public class SpreadSheetDbWriter extends AbstractSink implements BatchSizeSupporter, DatabaseConnectionUser
Transfers a SpreadSheet object into a database.
Input/output:
- accepts:
adams.data.spreadsheet.SpreadSheet
adams.data.spreadsheet.Row
-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: SpreadSheetDbWriter
-annotation <adams.core.base.BaseAnnotation> (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
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false
-table <java.lang.String> (property: table) The table to write the data to (gets automatically created). default: blah
-column-name-conversion <AS_IS|LOWER_CASE|UPPER_CASE> (property: columnNameConversion) How to convert the column headers into SQL table column names. default: UPPER_CASE
-max-string-length <int> (property: maxStringLength) The maximum length for strings to enforce; can be used as @MAX in the 'stringColumnsSQL' property. default: 50 minimum: 1
-string-column-sql <java.lang.String> (property: stringColumnSQL) The SQL type to use for STRING columns in the CREATE statement; you can use the @MAX placeholder to tie the type to the 'naxStringLength' property; see also: http://en.wikipedia.org/wiki/SQL default: VARCHAR(@MAX)
-batch-size <int> (property: batchSize) The size of the batch when inserting the data; can help improve speed of data import. default: 1 minimum: 1
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_BatchSizethe batch size.protected ColumnNameConversionm_ColumnNameConversionthe column name conversion.protected String[]m_ColumnNamesthe column names (shortened, disambiguated).protected AbstractDatabaseConnectionm_DatabaseConnectionthe database connection.protected intm_MaxColumnLengththe maximum length for column names.protected intm_MaxStringLengththe maximum length for strings.protected Stringm_StringColumnSQLthe SQL type for string columns.protected Stringm_Tablethe table to write the data to.protected AbstractTypeMapperm_TypeMapperthe type mapper to use.protected Cell.ContentType[]m_Typesthe type used for the table.protected Writerm_Writerthe writer for writing the data to the database.-
Fields inherited from class adams.flow.sink.AbstractSink
BACKUP_INPUT, m_InputToken
-
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 SpreadSheetDbWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]accepts()Returns the class that the consumer accepts.StringbatchSizeTipText()Returns the tip text for this property.StringcolumnNameConversionTipText()Returns the tip text for this property.voiddefineOptions()Adds options to the internal list of options.protected StringdoExecute()Executes the flow item.intgetBatchSize()Returns the batch size.ColumnNameConversiongetColumnNameConversion()Returns how to convert the column headers into SQL table column names.protected AbstractDatabaseConnectiongetDatabaseConnection()Determines the database connection in the flow.intgetMaxStringLength()Returns the maximum length for strings.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.StringgetStringColumnSQL()Returns the SQL type for string columns for the CREATE statement.StringgetTable()Returns the table to write the data to.AbstractTypeMappergetTypeMapper()Returns the type mapper in use.StringglobalInfo()Returns a string describing the object.StringmaxStringLengthTipText()Returns the tip text for this property.protected voidreset()Resets the scheme.voidsetBatchSize(int value)Sets the batch size.voidsetColumnNameConversion(ColumnNameConversion value)Sets how to convert the column headers into SQL table column names.voidsetMaxStringLength(int value)Sets the maximum length for strings.voidsetStringColumnSQL(String value)Sets the SQL type for string columns for the CREATE statement.voidsetTable(String value)Sets the table to write the data to.voidsetTypeMapper(AbstractTypeMapper value)Sets the type mapper to use.voidstopExecution()Stops the execution.StringstringColumnSQLTipText()Returns the tip text for this property.StringtableTipText()Returns the tip text for this property.StringtypeMapperTipText()Returns the tip text for this property.voidwrapUp()Cleans up after the execution has finished.-
Methods inherited from class adams.flow.sink.AbstractSink
backupState, currentInput, hasInput, input, postExecute, restoreState
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, 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, initialize, 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, 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, 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_DatabaseConnection
protected AbstractDatabaseConnection m_DatabaseConnection
the database connection.
-
m_TypeMapper
protected AbstractTypeMapper m_TypeMapper
the type mapper to use.
-
m_Table
protected String m_Table
the table to write the data to.
-
m_Types
protected Cell.ContentType[] m_Types
the type used for the table.
-
m_MaxColumnLength
protected int m_MaxColumnLength
the maximum length for column names.
-
m_ColumnNames
protected String[] m_ColumnNames
the column names (shortened, disambiguated).
-
m_ColumnNameConversion
protected ColumnNameConversion m_ColumnNameConversion
the column name conversion.
-
m_StringColumnSQL
protected String m_StringColumnSQL
the SQL type for string columns.
-
m_MaxStringLength
protected int m_MaxStringLength
the maximum length for strings.
-
m_BatchSize
protected int m_BatchSize
the batch size.
-
m_Writer
protected Writer m_Writer
the writer for writing the data to the database.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractActor
-
reset
protected void reset()
Resets the scheme.- Overrides:
resetin classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin classAbstractActor- Returns:
- null if no info available, otherwise short string
-
setTypeMapper
public void setTypeMapper(AbstractTypeMapper value)
Sets the type mapper to use.- Parameters:
value- the mapper
-
getTypeMapper
public AbstractTypeMapper getTypeMapper()
Returns the type mapper in use.- Returns:
- the mapper
-
typeMapperTipText
public String typeMapperTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setTable
public void setTable(String value)
Sets the table to write the data to.- Parameters:
value- the table name
-
getTable
public String getTable()
Returns the table to write the data to.- Returns:
- the table name
-
tableTipText
public String tableTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setColumnNameConversion
public void setColumnNameConversion(ColumnNameConversion value)
Sets how to convert the column headers into SQL table column names.- Parameters:
value- the conversion
-
getColumnNameConversion
public ColumnNameConversion getColumnNameConversion()
Returns how to convert the column headers into SQL table column names.- Returns:
- the conversion
-
columnNameConversionTipText
public String columnNameConversionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMaxStringLength
public void setMaxStringLength(int value)
Sets the maximum length for strings.- Parameters:
value- the maximum
-
getMaxStringLength
public int getMaxStringLength()
Returns the maximum length for strings.- Returns:
- the maximum
-
maxStringLengthTipText
public String maxStringLengthTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStringColumnSQL
public void setStringColumnSQL(String value)
Sets the SQL type for string columns for the CREATE statement.- Parameters:
value- the SQL type
-
getStringColumnSQL
public String getStringColumnSQL()
Returns the SQL type for string columns for the CREATE statement.- Returns:
- the SQL type
-
stringColumnSQLTipText
public String stringColumnSQLTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setBatchSize
public void setBatchSize(int value)
Sets the batch size.- Specified by:
setBatchSizein interfaceBatchSizeSupporter- Parameters:
value- the batch size
-
getBatchSize
public int getBatchSize()
Returns the batch size.- Specified by:
getBatchSizein interfaceBatchSizeSupporter- Returns:
- the batch size
-
batchSizeTipText
public String batchSizeTipText()
Returns the tip text for this property.- Specified by:
batchSizeTipTextin interfaceBatchSizeSupporter- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
accepts
public Class[] accepts()
Returns the class that the consumer accepts.- Specified by:
acceptsin interfaceInputConsumer- Returns:
- adams.data.spreadsheet.SpreadSheet.class, adams.data.spreadsheet.Row.class
-
getDatabaseConnection
protected AbstractDatabaseConnection getDatabaseConnection()
Determines the database connection in the flow.- Returns:
- the database connection to use
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecutein classAbstractActor- Returns:
- null if everything is fine, otherwise error message
-
stopExecution
public void stopExecution()
Stops the execution. No message set.- Specified by:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractActor
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.- Specified by:
wrapUpin interfaceActor- Overrides:
wrapUpin classAbstractSink
-
-