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 Detail

      • m_Table

        protected String m_Table
        the table to write the data to.
      • 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.
    • Constructor Detail

      • SpreadSheetDbWriter

        public SpreadSheetDbWriter()
    • Method Detail

      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class AbstractActor
      • 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:
        setBatchSize in interface BatchSizeSupporter
        Parameters:
        value - the batch size
      • getBatchSize

        public int getBatchSize()
        Returns the batch size.
        Specified by:
        getBatchSize in interface BatchSizeSupporter
        Returns:
        the batch size
      • batchSizeTipText

        public String batchSizeTipText()
        Returns the tip text for this property.
        Specified by:
        batchSizeTipText in interface BatchSizeSupporter
        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:
        accepts in interface InputConsumer
        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:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • wrapUp

        public void wrapUp()
        Cleans up after the execution has finished. Graphical output is left untouched.
        Specified by:
        wrapUp in interface Actor
        Overrides:
        wrapUp in class AbstractSink