weka.core.converters
Class DatabaseSaver

java.lang.Object
  extended byweka.core.converters.AbstractSaver
      extended byweka.core.converters.DatabaseSaver
All Implemented Interfaces:
BatchConverter, DatabaseConverter, IncrementalConverter, OptionHandler, Saver, java.io.Serializable

public class DatabaseSaver
extends AbstractSaver
implements BatchConverter, IncrementalConverter, DatabaseConverter, OptionHandler

Writes to a database (tested with MySQL, InstantDB, HSQLDB). Available options are: -T


Sets the name of teh table (default: the name of the relation)

-P
If set, a primary key column is generated automatically (containing the row number as INTEGER). The name of this columns is defined in the DatabaseUtils file.

-i
Specifies an ARFF file as input (for command line use)

Version:
$Revision: 1.1 $
Author:
Stefan Mutter (mutter@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface weka.core.converters.Saver
BATCH, INCREMENTAL, NONE
 
Constructor Summary
DatabaseSaver()
          Constructor
 
Method Summary
 java.lang.String autoKeyGenerationTipText()
          Returns the tip text fo this property
 void cancel()
          Cancels the incremental saving process and tries to drop the table if the write mode is CANCEL.
 void connectToDatabase()
          Opens a connection to the database
 boolean getAutoKeyGeneration()
          Gets whether or not a primary key will be generated automatically
 java.lang.String[] getOptions()
          Gets the setting
 boolean getRelationForTableName()
          Gets whether or not the relation name is used as name of the table
 java.lang.String getTableName()
          Gets the table's name
 java.lang.String getUrl()
          Gets the database URL
 java.lang.String getUser()
          Gets the database user
 java.lang.String globalInfo()
          Returns a string describing this Saver
 java.util.Enumeration listOptions()
          Lists the available options
static void main(java.lang.String[] options)
          Main method.
 java.lang.String passwordTipText()
          Returns the tip text fo this property
 java.lang.String relationForTableNameTipText()
          Returns the tip text fo this property
 void resetOptions()
          Resets the Saver ready to save a new data set
 void setAutoKeyGeneration(boolean flag)
          En/Dis-ables the automatic generation of a primary key
 void setDestination()
          Sets the database url using the DatabaseUtils file
 void setDestination(java.lang.String url)
          Sets the database url
 void setDestination(java.lang.String url, java.lang.String userName, java.lang.String password)
          Sets the database url
 void setOptions(java.lang.String[] options)
          Sets the options.
 void setPassword(java.lang.String password)
          Sets the database password
 void setRelationForTableName(boolean flag)
          En/Dis-ables that the relation name is used for the name of the table (default enabled).
 void setTableName(java.lang.String tn)
          Sets the table's name
 void setUrl(java.lang.String url)
          Sets the database URL
 void setUser(java.lang.String user)
          Sets the database user
 java.lang.String tableNameTipText()
          Returns the tip text fo this property
 java.lang.String urlTipText()
          Returns the tip text fo this property
 java.lang.String userTipText()
          Returns the tip text fo this property
 void writeBatch()
          Writes a Batch of instances
 void writeIncremental(Instance inst)
          Saves an instances incrementally.
 
Methods inherited from class weka.core.converters.AbstractSaver
filePrefix, getFileExtension, getInstances, getWriteMode, resetStructure, retrieveDir, setDestination, setDestination, setDir, setDirAndPrefix, setFile, setFilePrefix, setInstances, setRetrieval, setStructure
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseSaver

public DatabaseSaver()
              throws java.lang.Exception
Constructor

Throws:
java.lang.Exception - throws Exception if property file cannot be read
Method Detail

resetOptions

public void resetOptions()
Resets the Saver ready to save a new data set

Overrides:
resetOptions in class AbstractSaver

cancel

public void cancel()
Cancels the incremental saving process and tries to drop the table if the write mode is CANCEL.

Overrides:
cancel in class AbstractSaver

globalInfo

public java.lang.String globalInfo()
Returns a string describing this Saver

Returns:
a description of the Saver suitable for displaying in the explorer/experimenter gui

setTableName

public void setTableName(java.lang.String tn)
Sets the table's name

Parameters:
tn - the name of the table

getTableName

public java.lang.String getTableName()
Gets the table's name

Returns:
the table's name

tableNameTipText

public java.lang.String tableNameTipText()
Returns the tip text fo this property


setAutoKeyGeneration

public void setAutoKeyGeneration(boolean flag)
En/Dis-ables the automatic generation of a primary key


getAutoKeyGeneration

public boolean getAutoKeyGeneration()
Gets whether or not a primary key will be generated automatically

Returns:
true if a primary key column will be generated, false otherwise

autoKeyGenerationTipText

public java.lang.String autoKeyGenerationTipText()
Returns the tip text fo this property


setRelationForTableName

public void setRelationForTableName(boolean flag)
En/Dis-ables that the relation name is used for the name of the table (default enabled).


getRelationForTableName

public boolean getRelationForTableName()
Gets whether or not the relation name is used as name of the table

Returns:
true if the relation name is used as the name of the table, false otherwise

relationForTableNameTipText

public java.lang.String relationForTableNameTipText()
Returns the tip text fo this property


setUrl

public void setUrl(java.lang.String url)
Sets the database URL

Specified by:
setUrl in interface DatabaseConverter

getUrl

public java.lang.String getUrl()
Gets the database URL

Specified by:
getUrl in interface DatabaseConverter
Returns:
the URL

urlTipText

public java.lang.String urlTipText()
Returns the tip text fo this property


setUser

public void setUser(java.lang.String user)
Sets the database user

Specified by:
setUser in interface DatabaseConverter

getUser

public java.lang.String getUser()
Gets the database user

Specified by:
getUser in interface DatabaseConverter
Returns:
the user name

userTipText

public java.lang.String userTipText()
Returns the tip text fo this property


setPassword

public void setPassword(java.lang.String password)
Sets the database password

Specified by:
setPassword in interface DatabaseConverter

passwordTipText

public java.lang.String passwordTipText()
Returns the tip text fo this property


setDestination

public void setDestination(java.lang.String url,
                           java.lang.String userName,
                           java.lang.String password)
Sets the database url

Parameters:
url - the database url
userName - the user name
password - the password

setDestination

public void setDestination(java.lang.String url)
Sets the database url

Parameters:
url - the database url

setDestination

public void setDestination()
Sets the database url using the DatabaseUtils file


connectToDatabase

public void connectToDatabase()
Opens a connection to the database


writeIncremental

public void writeIncremental(Instance inst)
                      throws java.io.IOException
Saves an instances incrementally. Structure has to be set by using the setStructure() method or setInstances() method. When a structure is set, a table is created.

Specified by:
writeIncremental in interface Saver
Overrides:
writeIncremental in class AbstractSaver
Parameters:
inst - the instance to save
Throws:
java.io.IOException - throws IOEXception.

writeBatch

public void writeBatch()
                throws java.io.IOException
Writes a Batch of instances

Specified by:
writeBatch in interface Saver
Specified by:
writeBatch in class AbstractSaver
Throws:
java.io.IOException - throws IOException

getOptions

public java.lang.String[] getOptions()
Gets the setting

Specified by:
getOptions in interface OptionHandler
Returns:
the current setting

listOptions

public java.util.Enumeration listOptions()
Lists the available options

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of the available options

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Sets the options. Available options are: -T
Sets the name of teh table (default: the name of the relation)

-P
If set, a primary key column is generated automatically (containing the row number as INTEGER)

-i
Specifies an ARFF file as input (for command line use)

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the options
Throws:
java.lang.Exception - if options cannot be set

main

public static void main(java.lang.String[] options)
Main method.

Parameters:
options - should contain the options of a Saver.