public class DatabaseSaver extends AbstractSaver implements BatchConverter, IncrementalConverter, DatabaseConverter, OptionHandler, EnvironmentHandler
-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)
-truncate Truncate (i.e. delete any data) in table before inserting
-P Add an ID column as primary key. The name is specified in the DatabaseUtils file ('idColumn'). The DatabaseLoader won't load this column.
-custom-props <file> The custom properties file to use instead of default ones, containing the database parameters. (default: none)
-i <input file name> Input file in arff format that should be saved in database.
BATCH, INCREMENTAL, NONE
Constructor and Description |
---|
DatabaseSaver()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
autoKeyGenerationTipText()
Returns the tip text for 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.
|
String |
customPropsFileTipText()
The tip text for this property.
|
boolean |
getAutoKeyGeneration()
Gets whether or not a primary key will be generated automatically.
|
Capabilities |
getCapabilities()
Returns the Capabilities of this saver.
|
File |
getCustomPropsFile()
Returns the custom properties file in use, if any.
|
String[] |
getOptions()
Gets the setting.
|
String |
getPassword()
Returns the database password.
|
boolean |
getRelationForTableName()
Gets whether or not the relation name is used as name of the table.
|
String |
getRevision()
Returns the revision string.
|
String |
getTableName()
Gets the table's name.
|
boolean |
getTruncate()
Get whether to truncate (i.e.
|
String |
getUrl()
Gets the database URL.
|
String |
getUser()
Gets the database user.
|
String |
globalInfo()
Returns a string describing this Saver.
|
Enumeration<Option> |
listOptions()
Lists the available options.
|
static void |
main(String[] options)
Main method.
|
String |
passwordTipText()
Returns the tip text for this property.
|
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 |
setCustomPropsFile(File value)
Sets the custom properties file to use.
|
void |
setDestination()
Sets the database url using the DatabaseUtils file.
|
void |
setDestination(String url)
Sets the database url.
|
void |
setDestination(String url,
String userName,
String password)
Sets the database url.
|
void |
setEnvironment(Environment env)
Set the environment variables to use.
|
void |
setOptions(String[] options)
Sets the options.
|
void |
setPassword(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(String tn)
Sets the table's name.
|
void |
setTruncate(boolean t)
Set whether to truncate (i.e.
|
void |
setUrl(String url)
Sets the database URL.
|
void |
setUser(String user)
Sets the database user.
|
String |
tableNameTipText()
Returns the tip text for this property.
|
String |
truncateTipText()
Returns the tip text for this property.
|
String |
urlTipText()
Returns the tip text for this property.
|
String |
userTipText()
Returns the tip text for this property.
|
void |
writeBatch()
Writes a Batch of instances.
|
void |
writeIncremental(Instance inst)
Saves an instances incrementally.
|
doNotCheckCapabilitiesTipText, filePrefix, getDoNotCheckCapabilities, getFileExtension, getInstances, getWriteMode, resetStructure, retrieveDir, setDestination, setDestination, setDir, setDirAndPrefix, setDoNotCheckCapabilities, setFile, setFilePrefix, setInstances, setRetrieval, setStructure
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
makeCopy
public static void main(String[] options)
options
- should contain the options of a Saver.public void setEnvironment(Environment env)
setEnvironment
in interface EnvironmentHandler
env
- the environment variables to usepublic void resetOptions()
resetOptions
in class AbstractSaver
public void cancel()
cancel
in class AbstractSaver
public String globalInfo()
@OptionMetadata(displayName="Table name", description="Sets the name of the table", displayOrder=4) public String getTableName()
public void setTableName(String tn)
tn
- the name of the tablepublic String tableNameTipText()
@OptionMetadata(displayName="Truncate table", description="Truncate (i.e. drop and recreate) table if it already exists", displayOrder=6) public boolean getTruncate()
public void setTruncate(boolean t)
t
- true if the table should be truncated first (if it exists).public String truncateTipText()
@OptionMetadata(displayName="Automatic primary key", description="If set to true, a primary key column is generated automatically (containing the row number as INTEGER). The name of the key is read from DatabaseUtils (idColumn) This primary key can be used for incremental loading (requires an unique key). This primary key will not be loaded as an attribute.", displayOrder=7) public boolean getAutoKeyGeneration()
public void setAutoKeyGeneration(boolean flag)
flag
- flag for automatic key-genererationpublic String autoKeyGenerationTipText()
@OptionMetadata(displayName="Use relation name", description="If set to true, the relation name will be used as name for the database table. Otherwise the user has to provide a table name.", displayOrder=5) public boolean getRelationForTableName()
public void setRelationForTableName(boolean flag)
flag
- if true the relation name is used as table namepublic String relationForTableNameTipText()
@OptionMetadata(displayName="Database URL", description="The URL of the database", displayOrder=1) public String getUrl()
getUrl
in interface DatabaseConverter
public void setUrl(String url)
setUrl
in interface DatabaseConverter
url
- the URLpublic String urlTipText()
public String getUser()
getUser
in interface DatabaseConverter
@OptionMetadata(displayName="Username", description="The user name for the database", displayOrder=2) public void setUser(String user)
setUser
in interface DatabaseConverter
user
- the user namepublic String userTipText()
@OptionMetadata(displayName="Password", description="The database password", displayOrder=3) @PasswordProperty public String getPassword()
public void setPassword(String password)
setPassword
in interface DatabaseConverter
password
- the passwordpublic String passwordTipText()
@OptionMetadata(displayName="DB config file", description="The custom properties that the user can use to override the default ones.", displayOrder=8) @FilePropertyMetadata(fileChooserDialogType=0, directoriesOnly=false) public File getCustomPropsFile()
public void setCustomPropsFile(File value)
value
- the custom props file to load database parameters from, use
null or directory to disable custom properties.public String customPropsFileTipText()
public void setDestination(String url, String userName, String password)
url
- the database urluserName
- the user namepassword
- the passwordpublic void setDestination(String url)
url
- the database urlpublic void setDestination()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
getCapabilities
in class AbstractSaver
Capabilities
public void connectToDatabase()
public void writeIncremental(Instance inst) throws IOException
writeIncremental
in interface Saver
writeIncremental
in class AbstractSaver
inst
- the instance to saveIOException
- throws IOEXception.public void writeBatch() throws IOException
writeBatch
in interface Saver
writeBatch
in class AbstractSaver
IOException
- throws IOExceptionpublic String[] getOptions()
getOptions
in interface OptionHandler
public void setOptions(String[] options) throws Exception
-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)
-truncate Truncate (i.e. delete any data) in table before inserting
-P Add an ID column as primary key. The name is specified in the DatabaseUtils file ('idColumn'). The DatabaseLoader won't load this column.
-custom-props <file> The custom properties file to use instead of default ones, containing the database parameters. (default: none)
-i <input file name> Input file in arff format that should be saved in database.
setOptions
in interface OptionHandler
options
- the optionsException
- if options cannot be setpublic Enumeration<Option> listOptions()
listOptions
in interface OptionHandler
public String getRevision()
getRevision
in interface RevisionHandler
Copyright © 2020 University of Waikato, Hamilton, NZ. All rights reserved.