Class WekaDatabaseWriter

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.PasswordSupporter, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<adams.flow.core.Actor>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, adams.core.VariablesInspectionHandler, adams.event.VariableChangeListener, adams.flow.core.Actor, adams.flow.core.ErrorHandler, adams.flow.core.InputConsumer, Serializable, Comparable

    public class WekaDatabaseWriter
    extends adams.flow.sink.AbstractSink
    implements adams.core.PasswordSupporter
    Actor for saving a weka.core.Instances object in a database.
    The relation name of the incoming dataset can be used to replace the current filename (path and extension are kept).

    Input/output:
    - accepts:
       weka.core.Instances
       weka.core.Instance


    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: WekaDatabaseWriter
     
    -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.
     
    -url <java.lang.String> (property: URL)
        The JDBC URL of the database to query.
     
    -user <java.lang.String> (property: user)
        The user for connecting to the database.
     
    -password <adams.core.base.BasePassword> (property: password)
        The password for the database user.
     
    -table <java.lang.String> (property: tableName)
        The name of the table to store the data in.
        default: weka
     
    -auto-key-generation (property: autoKeyGeneration)
        If set to true, a primary key is automatically generated.
     
    -use-relation-as-table (property: useRelationNameAsTable)
        If set to true, the relation name is used as table name.
     
    -custom-props <adams.core.io.PlaceholderFile> (property: customPropsFile)
        Custom properties file to override the default database settings, eg, for
        accessing a different type of database; ignored if pointing to a directory.
        default: .
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String BACKUP_SAVER
      the key for storing the current incremental clusterer in the backup.
      protected boolean m_AutoKeyGeneration
      whether to automatically generate a primary key.
      protected adams.core.io.PlaceholderFile m_CustomPropsFile
      a custom properties file to use instead of default one.
      protected adams.core.base.BasePassword m_Password
      the password for the user used for connecting.
      protected weka.core.converters.DatabaseSaver m_Saver
      the database saver.
      protected String m_TableName
      protected the name of the table to store the data in.
      protected String m_URL
      the database URL to query.
      protected String m_User
      the database user to use for connecting.
      protected boolean m_UseRelationNameAsTable
      whether to use the relation as table name.
      • 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Class[] accepts()
      Returns the class that the consumer accepts.
      String autoKeyGenerationTipText()
      Returns the tip text for this property.
      protected Hashtable<String,​Object> backupState()
      Backs up the current state of the actor before update the variables.
      String customPropsFileTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      protected String doExecute()
      Executes the flow item.
      boolean getAutoKeyGeneration()
      Returns whether a primary key is automatically generated.
      adams.core.io.PlaceholderFile getCustomPropsFile()
      Returns the custom properties file to use for initializing the database setup instead of WEKA's default one.
      adams.core.base.BasePassword getPassword()
      Returns the database password.
      String getQuickInfo()
      Returns a quick info about the actor, which will be displayed in the GUI.
      String getTableName()
      Returns the table name to store the data in.
      String getURL()
      Returns the query to execute.
      String getUser()
      Returns the database user.
      boolean getUseRelationNameAsTable()
      Returns whether to output single Instance objects or just one Instances object.
      String globalInfo()
      Returns a string describing the object.
      String passwordTipText()
      Returns the tip text for this property.
      protected void pruneBackup()
      Removes entries from the backup.
      protected void reset()
      Resets the actor.
      protected void restoreState​(Hashtable<String,​Object> state)
      Restores the state of the actor before the variables got updated.
      void setAutoKeyGeneration​(boolean value)
      Sets whether to automatically generate a primary key.
      void setCustomPropsFile​(adams.core.io.PlaceholderFile value)
      Sets the custom properties file to use for initializing the database setup instead of WEKA's default one.
      void setPassword​(adams.core.base.BasePassword value)
      Sets the database password.
      void setTableName​(String value)
      Sets the table name to store the data in.
      void setURL​(String value)
      Sets the database URL to query.
      void setUser​(String value)
      Sets the database user.
      void setUseRelationNameAsTable​(boolean value)
      Sets whether to output single Instance objects or just one Instances object.
      String tableNameTipText()
      Returns the tip text for this property.
      String URLTipText()
      Returns the tip text for this property.
      String useRelationNameAsTableTipText()
      Returns the tip text for this property.
      String userTipText()
      Returns the tip text for this property.
      void wrapUp()
      Cleans up after the execution has finished.
      • Methods inherited from class adams.flow.sink.AbstractSink

        currentInput, hasInput, input, postExecute
      • 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, 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 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

      • BACKUP_SAVER

        public static final String BACKUP_SAVER
        the key for storing the current incremental clusterer in the backup.
        See Also:
        Constant Field Values
      • m_URL

        protected String m_URL
        the database URL to query.
      • m_User

        protected String m_User
        the database user to use for connecting.
      • m_Password

        protected adams.core.base.BasePassword m_Password
        the password for the user used for connecting.
      • m_TableName

        protected String m_TableName
        protected the name of the table to store the data in.
      • m_AutoKeyGeneration

        protected boolean m_AutoKeyGeneration
        whether to automatically generate a primary key.
      • m_UseRelationNameAsTable

        protected boolean m_UseRelationNameAsTable
        whether to use the relation as table name.
      • m_CustomPropsFile

        protected adams.core.io.PlaceholderFile m_CustomPropsFile
        a custom properties file to use instead of default one.
      • m_Saver

        protected weka.core.converters.DatabaseSaver m_Saver
        the database saver.
    • Constructor Detail

      • WekaDatabaseWriter

        public WekaDatabaseWriter()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.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 adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.flow.core.AbstractActor
      • reset

        protected void reset()
        Resets the actor.
        Overrides:
        reset in class adams.flow.core.AbstractActor
      • getQuickInfo

        public String getQuickInfo()
        Returns a quick info about the actor, which will be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.flow.core.Actor
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class adams.flow.core.AbstractActor
        Returns:
        null if no info available, otherwise short string
      • pruneBackup

        protected void pruneBackup()
        Removes entries from the backup.
        Overrides:
        pruneBackup in class adams.flow.core.AbstractActor
      • backupState

        protected Hashtable<String,​Object> backupState()
        Backs up the current state of the actor before update the variables.
        Overrides:
        backupState in class adams.flow.sink.AbstractSink
        Returns:
        the backup
      • restoreState

        protected void restoreState​(Hashtable<String,​Object> state)
        Restores the state of the actor before the variables got updated.
        Overrides:
        restoreState in class adams.flow.sink.AbstractSink
        Parameters:
        state - the backup of the state to restore from
      • setURL

        public void setURL​(String value)
        Sets the database URL to query.
        Parameters:
        value - the JDBC URL
      • getURL

        public String getURL()
        Returns the query to execute.
        Returns:
        the query
      • URLTipText

        public String URLTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUser

        public void setUser​(String value)
        Sets the database user.
        Parameters:
        value - the user
      • getUser

        public String getUser()
        Returns the database user.
        Returns:
        the user
      • userTipText

        public String userTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPassword

        public void setPassword​(adams.core.base.BasePassword value)
        Sets the database password.
        Specified by:
        setPassword in interface adams.core.PasswordSupporter
        Parameters:
        value - the password
      • getPassword

        public adams.core.base.BasePassword getPassword()
        Returns the database password.
        Specified by:
        getPassword in interface adams.core.PasswordSupporter
        Returns:
        the password
      • passwordTipText

        public String passwordTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTableName

        public void setTableName​(String value)
        Sets the table name to store the data in.
        Parameters:
        value - the table name
      • getTableName

        public String getTableName()
        Returns the table name to store the data in.
        Returns:
        the table name
      • tableNameTipText

        public String tableNameTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setAutoKeyGeneration

        public void setAutoKeyGeneration​(boolean value)
        Sets whether to automatically generate a primary key.
        Parameters:
        value - if true then a primary key is generated
      • getAutoKeyGeneration

        public boolean getAutoKeyGeneration()
        Returns whether a primary key is automatically generated.
        Returns:
        true if a primary key is generated
      • autoKeyGenerationTipText

        public String autoKeyGenerationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseRelationNameAsTable

        public void setUseRelationNameAsTable​(boolean value)
        Sets whether to output single Instance objects or just one Instances object.
        Parameters:
        value - if true then a single Instance objects are output
      • getUseRelationNameAsTable

        public boolean getUseRelationNameAsTable()
        Returns whether to output single Instance objects or just one Instances object.
        Returns:
        true if single Instance objects are output
      • useRelationNameAsTableTipText

        public String useRelationNameAsTableTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setCustomPropsFile

        public void setCustomPropsFile​(adams.core.io.PlaceholderFile value)
        Sets the custom properties file to use for initializing the database setup instead of WEKA's default one.
        Parameters:
        value - the custom props file, ignored if a directory
      • getCustomPropsFile

        public adams.core.io.PlaceholderFile getCustomPropsFile()
        Returns the custom properties file to use for initializing the database setup instead of WEKA's default one.
        Returns:
        the custom props file, ignored if a directory
      • customPropsFileTipText

        public String customPropsFileTipText()
        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.
        Specified by:
        accepts in interface adams.flow.core.InputConsumer
        Returns:
        weka.core.Instances.class, weka.core.Instance.class
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class adams.flow.core.AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • wrapUp

        public void wrapUp()
        Cleans up after the execution has finished.
        Specified by:
        wrapUp in interface adams.flow.core.Actor
        Overrides:
        wrapUp in class adams.flow.sink.AbstractSink