Package weka.core.converters
Class DatabaseSaver
java.lang.Object
weka.core.converters.AbstractSaver
weka.core.converters.DatabaseSaver
- All Implemented Interfaces:
Serializable,CapabilitiesHandler,BatchConverter,DatabaseConverter,IncrementalConverter,Saver,OptionHandler,RevisionHandler
public class DatabaseSaver
extends AbstractSaver
implements BatchConverter, IncrementalConverter, DatabaseConverter, OptionHandler
Writes to a database (tested with MySQL, InstantDB, HSQLDB).
Valid options are:
-url <JDBC URL> The JDBC URL to connect to. (default: from DatabaseUtils.props file)
-user <name> The user to connect with to the database. (default: none)
-password <password> The password to connect with to the database. (default: none)
-T <table name> The name of the table. (default: the relation name)
-P
Add an ID column as primary key. The name is specified
in the DatabaseUtils file ('idColumn'). The DatabaseLoader
won't load this column.
-i <input file name> Input file in arff format that should be saved in database.
- Version:
- $Revision: 7499 $
- Author:
- Stefan Mutter (mutter@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Fields inherited from interface weka.core.converters.Saver
BATCH, INCREMENTAL, NONE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the tip text for this property.voidcancel()Cancels the incremental saving process and tries to drop the table if the write mode is CANCEL.voidOpens a connection to the database.booleanGets whether or not a primary key will be generated automatically.Returns the Capabilities of this saver.String[]Gets the setting.Returns the database password.booleanGets whether or not the relation name is used as name of the table.Returns the revision string.Gets the table's name.getUrl()Gets the database URL.getUser()Gets the database user.Returns a string describing this Saver.Lists the available options.static voidMain method.Returns the tip text for this property.Returns the tip text fo this property.voidResets the Saver ready to save a new data set.voidsetAutoKeyGeneration(boolean flag) En/Dis-ables the automatic generation of a primary key.voidSets the database url using the DatabaseUtils file.voidsetDestination(String url) Sets the database url.voidsetDestination(String url, String userName, String password) Sets the database url.voidsetOptions(String[] options) Sets the options.voidsetPassword(String password) Sets the database password.voidsetRelationForTableName(boolean flag) En/Dis-ables that the relation name is used for the name of the table (default enabled).voidsetTableName(String tn) Sets the table's name.voidSets the database URL.voidSets the database user.Returns the tip text for this property.Returns the tip text for this property.Returns the tip text for this property.voidWrites a Batch of instances.voidwriteIncremental(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
-
Constructor Details
-
DatabaseSaver
Constructor.- Throws:
Exception- throws Exception if property file cannot be read
-
-
Method Details
-
resetOptions
public void resetOptions()Resets the Saver ready to save a new data set.- Overrides:
resetOptionsin classAbstractSaver
-
cancel
public void cancel()Cancels the incremental saving process and tries to drop the table if the write mode is CANCEL.- Overrides:
cancelin classAbstractSaver
-
globalInfo
Returns a string describing this Saver.- Returns:
- a description of the Saver suitable for displaying in the explorer/experimenter gui
-
setTableName
Sets the table's name.- Parameters:
tn- the name of the table
-
getTableName
Gets the table's name.- Returns:
- the table's name
-
tableNameTipText
Returns the tip text for this property.- Returns:
- the tip text for this property
-
setAutoKeyGeneration
public void setAutoKeyGeneration(boolean flag) En/Dis-ables the automatic generation of a primary key.- Parameters:
flag- flag for automatic key-genereration
-
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
Returns the tip text for this property.- Returns:
- tip text for 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).- Parameters:
flag- if true the relation name is used as table name
-
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
Returns the tip text fo this property.- Returns:
- the tip text for this property
-
setUrl
Sets the database URL.- Specified by:
setUrlin interfaceDatabaseConverter- Parameters:
url- the URL
-
getUrl
Gets the database URL.- Specified by:
getUrlin interfaceDatabaseConverter- Returns:
- the URL
-
urlTipText
Returns the tip text for this property.- Returns:
- the tip text for this property
-
setUser
Sets the database user.- Specified by:
setUserin interfaceDatabaseConverter- Parameters:
user- the user name
-
getUser
Gets the database user.- Specified by:
getUserin interfaceDatabaseConverter- Returns:
- the user name
-
userTipText
Returns the tip text for this property.- Returns:
- the tip text for this property
-
setPassword
Sets the database password.- Specified by:
setPasswordin interfaceDatabaseConverter- Parameters:
password- the password
-
getPassword
Returns the database password.- Returns:
- the database password
-
passwordTipText
Returns the tip text for this property.- Returns:
- the tip text for this property
-
setDestination
Sets the database url.- Parameters:
url- the database urluserName- the user namepassword- the password
-
setDestination
Sets the database url.- Parameters:
url- the database url
-
setDestination
public void setDestination()Sets the database url using the DatabaseUtils file. -
getCapabilities
Returns the Capabilities of this saver.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Overrides:
getCapabilitiesin classAbstractSaver- Returns:
- the capabilities of this object
- See Also:
-
connectToDatabase
public void connectToDatabase()Opens a connection to the database. -
writeIncremental
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:
writeIncrementalin interfaceSaver- Overrides:
writeIncrementalin classAbstractSaver- Parameters:
inst- the instance to save- Throws:
IOException- throws IOEXception.
-
writeBatch
Writes a Batch of instances.- Specified by:
writeBatchin interfaceSaver- Specified by:
writeBatchin classAbstractSaver- Throws:
IOException- throws IOException
-
getOptions
Gets the setting.- Specified by:
getOptionsin interfaceOptionHandler- Returns:
- the current setting
-
listOptions
Lists the available options.- Specified by:
listOptionsin interfaceOptionHandler- Returns:
- an enumeration of the available options
-
setOptions
Sets the options. Valid options are:-url <JDBC URL> The JDBC URL to connect to. (default: from DatabaseUtils.props file)
-user <name> The user to connect with to the database. (default: none)
-password <password> The password to connect with to the database. (default: none)
-T <table name> The name of the table. (default: the relation name)
-P Add an ID column as primary key. The name is specified in the DatabaseUtils file ('idColumn'). The DatabaseLoader won't load this column.-i <input file name> Input file in arff format that should be saved in database.
- Specified by:
setOptionsin interfaceOptionHandler- Parameters:
options- the options- Throws:
Exception- if options cannot be set
-
getRevision
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
main
Main method.- Parameters:
options- should contain the options of a Saver.
-