adams.flow.sink
Class SpreadSheetDbWriter

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.flow.core.AbstractActor
              extended by adams.flow.sink.AbstractSink
                  extended by adams.flow.sink.SpreadSheetDbWriter
All Implemented Interfaces:
AdditionalInformationHandler, CleanUpHandler, Debuggable, DebugOutputHandler, Destroyable, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<AbstractActor>, SizeOfHandler, Stoppable, VariableChangeListener, Actor, ErrorHandler, InputConsumer, Serializable, Comparable

public class SpreadSheetDbWriter
extends AbstractSink

Transfers a SpreadSheet object into a database.

Input/output:
- accepts:
   adams.data.spreadsheet.SpreadSheet

Valid options are:

-D <int> (property: debugLevel)
    The greater the number the more additional info the scheme may output to 
    the console (0 = off).
    default: 0
    minimum: 0
 
-name <java.lang.String> (property: name)
    The name of the actor.
    default: SpreadSheetDbWriter
 
-annotation <adams.core.base.BaseText> (property: annotations)
    The annotations to attach to this actor.
    default: 
 
-skip (property: skip)
    If set to true, transformation is skipped and the input token is just forwarded 
    as it is.
 
-stop-flow-on-error (property: stopFlowOnError)
    If set to true, the flow gets stopped in case this actor encounters an error;
     useful for critical actors.
 
-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)
 

Version:
$Revision: 6332 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Nested Class Summary
static class SpreadSheetDbWriter.ColumnNameConversion
          Defines how column names are converted.
 
Field Summary
protected  SpreadSheetDbWriter.ColumnNameConversion m_ColumnNameConversion
          the column name conversion.
protected  String[] m_ColumnNames
          the column names (shortened, disambiguated).
protected  AbstractDatabaseConnection m_DatabaseConnection
          the database connection.
protected  int m_MaxColumnLength
          the maximum length for column names.
protected  int m_MaxStringLength
          the maximum length for strings.
protected  String m_StringColumnSQL
          the SQL type for string columns.
protected  String m_Table
          the table to write the data to.
protected  Cell.ContentType[] m_Types
          the type used for the table.
static String PLACEHOLDER_MAX
          the placeholder for the maximum length for string values.
 
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_FullName, m_Headless, m_Name, m_Parent, m_Root, m_Self, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
 
Constructor Summary
SpreadSheetDbWriter()
           
 
Method Summary
 Class[] accepts()
          Returns the class that the consumer accepts.
 String columnNameConversionTipText()
          Returns the tip text for this property.
protected  String createTable(SQL sql, SpreadSheet sheet)
          Creates the table.
 void defineOptions()
          Adds options to the internal list of options.
protected  String determineSetup(SpreadSheet sheet)
          Determines the column types and names.
protected  String doExecute()
          Executes the flow item.
protected  String fixColumnName(String s)
          Fixes the column name.
 SpreadSheetDbWriter.ColumnNameConversion getColumnNameConversion()
          Returns how to convert the column headers into SQL table column names.
protected  AbstractDatabaseConnection getDatabaseConnection()
          Determines the database connection in the flow.
 int getMaxStringLength()
          Returns the maximum length for strings.
 String getQuickInfo()
          Returns a quick info about the actor, which will be displayed in the GUI.
 String getStringColumnSQL()
          Returns the SQL type for string columns for the CREATE statement.
 String getTable()
          Returns the table to write the data to.
 String globalInfo()
          Returns a string describing the object.
 String maxStringLengthTipText()
          Returns the tip text for this property.
 void setColumnNameConversion(SpreadSheetDbWriter.ColumnNameConversion value)
          Sets how to convert the column headers into SQL table column names.
 void setMaxStringLength(int value)
          Sets the maximum length for strings.
 void setStringColumnSQL(String value)
          Sets the SQL type for string columns for the CREATE statement.
 void setTable(String value)
          Sets the table to write the data to.
 String setUp()
          Initializes the item for flow execution.
 String stringColumnSQLTipText()
          Returns the tip text for this property.
 String tableTipText()
          Returns the tip text for this property.
 void wrapUp()
          Cleans up after the execution has finished.
protected  String writeData(SQL sql, SpreadSheet sheet)
          Writes the data to the table.
 
Methods inherited from class adams.flow.sink.AbstractSink
backupState, input, restoreState
 
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, debug, destroy, equals, execute, findVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFullName, getName, getNextSibling, getParent, getPreviousSibling, getRoot, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, postExecute, preExecute, pruneBackup, pruneBackup, reset, setAnnotations, setErrorHandler, setHeadless, setName, setParent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debugLevelTipText, finishInit, getDebugLevel, getOptionManager, isDebugOn, newOptionManager, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut
 
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, debug, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFullName, getName, getNextSibling, getParent, getPreviousSibling, getRoot, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setHeadless, setName, setParent, setSkip, setStopFlowOnError, setVariables, sizeOf, stopExecution, stopExecution, variableChanged
 
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
 
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
 

Field Detail

PLACEHOLDER_MAX

public static final String PLACEHOLDER_MAX
the placeholder for the maximum length for string values.

See Also:
Constant Field Values

m_DatabaseConnection

protected AbstractDatabaseConnection m_DatabaseConnection
the database connection.


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 SpreadSheetDbWriter.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.

Constructor Detail

SpreadSheetDbWriter

public SpreadSheetDbWriter()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
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 interface OptionHandler
Overrides:
defineOptions in class AbstractActor

getQuickInfo

public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.

Specified by:
getQuickInfo in interface QuickInfoSupporter
Specified by:
getQuickInfo in interface Actor
Overrides:
getQuickInfo in class AbstractActor
Returns:
null if no info available, otherwise short string

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(SpreadSheetDbWriter.ColumnNameConversion value)
Sets how to convert the column headers into SQL table column names.

Parameters:
value - the conversion

getColumnNameConversion

public SpreadSheetDbWriter.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.

accepts

public Class[] accepts()
Returns the class that the consumer accepts.

Returns:
adams.data.spreadsheet.SpreadSheet.class

getDatabaseConnection

protected AbstractDatabaseConnection getDatabaseConnection()
Determines the database connection in the flow.

Returns:
the database connection to use

setUp

public String setUp()
Initializes the item for flow execution.

Specified by:
setUp in interface Actor
Overrides:
setUp in class AbstractActor
Returns:
null if everything is fine, otherwise error message

fixColumnName

protected String fixColumnName(String s)
Fixes the column name.

Parameters:
s - the column name to fix
Returns:
the fixed name

determineSetup

protected String determineSetup(SpreadSheet sheet)
Determines the column types and names.

Parameters:
sheet - the sheet to analyze
See Also:
m_Types, m_ColumnNames

createTable

protected String createTable(SQL sql,
                             SpreadSheet sheet)
Creates the table.

Parameters:
sql - for executing queries
sheet - the data to write to the database
Returns:
null if everything OK, otherwise error message

writeData

protected String writeData(SQL sql,
                           SpreadSheet sheet)
Writes the data to the table.

Parameters:
sql - for performing the writing
sheet - the data to write
Returns:
null if everything OK, otherwise error message

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


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.