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.
| Modifier and Type | Field and Description |
|---|---|
protected int |
m_count
counts the rows and used as a primary key value.
|
protected java.lang.String |
m_createDate
The database specific type for a date (read in from the properties file).
|
protected java.lang.String |
m_createDouble
The database specific type for a double (read in from the properties file).
|
protected java.lang.String |
m_createInt
The database specific type for an int (read in from the properties file).
|
protected java.lang.String |
m_createText
The database specific type for a string (read in from the properties file).
|
protected java.io.File |
m_CustomPropsFile
the custom props file to use instead of default one.
|
protected DatabaseConnection |
m_DataBaseConnection
The database connection.
|
protected java.text.SimpleDateFormat |
m_DateFormat
For converting the date value into a database string.
|
protected Environment |
m_env
Environment variables to use
|
protected boolean |
m_id
Flag indicating if a primary key column should be added.
|
protected java.lang.String |
m_idColumn
The name of the primary key column that will be automatically generated (if
enabled).
|
protected java.lang.String |
m_inputFile
An input arff file (for command line use).
|
protected java.lang.String |
m_Password
the password for the database.
|
protected java.lang.String |
m_resolvedTableName
Table name with any environment variables resolved
|
protected java.lang.String |
m_tableName
The name of the table in which the instances should be stored.
|
protected boolean |
m_tabName
Flag indicating whether the default name of the table is the relaion name
or not.
|
protected boolean |
m_truncate
Whether to truncate (i.e. drop and then recreate) the table if it already
exists
|
protected java.lang.String |
m_URL
the database URL.
|
protected java.lang.String |
m_Username
the user name for the database.
|
CANCEL, m_DoNotCheckCapabilities, m_retrieval, STRUCTURE_READY, WAIT, WRITEBATCH, INCREMENTAL, NONE| Constructor and Description |
|---|
DatabaseSaver()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.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.
|
java.lang.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.
|
java.io.File |
getCustomPropsFile()
Returns the custom properties file in use, if any.
|
java.lang.String[] |
getOptions()
Gets the setting.
|
java.lang.String |
getPassword()
Returns the database password.
|
boolean |
getRelationForTableName()
Gets whether or not the relation name is used as name of the table.
|
java.lang.String |
getRevision()
Returns the revision string.
|
java.lang.String |
getTableName()
Gets the table's name.
|
boolean |
getTruncate()
Get whether to truncate (i.e. drop and recreate) the table if it already
exits.
|
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<Option> |
listOptions()
Lists the available options.
|
static void |
main(java.lang.String[] options)
Main method.
|
protected DatabaseConnection |
newDatabaseConnection()
Initializes a new DatabaseConnection object, either default one or from
custom props file.
|
java.lang.String |
passwordTipText()
Returns the tip text for 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 |
setCustomPropsFile(java.io.File value)
Sets the custom properties file to use.
|
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 |
setEnvironment(Environment env)
Set the environment variables to use.
|
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 |
setTruncate(boolean t)
Set whether to truncate (i.e. drop and recreate) the table if it already
exits.
|
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 for this property.
|
java.lang.String |
truncateTipText()
Returns the tip text for this property.
|
java.lang.String |
urlTipText()
Returns the tip text for this property.
|
java.lang.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, getRetrieval, getWriteMode, resetStructure, retrieveDir, setDestination, setDestination, setDir, setDirAndPrefix, setDoNotCheckCapabilities, setFile, setFilePrefix, setInstances, setRetrieval, setStructure, setWriteModeprotected DatabaseConnection m_DataBaseConnection
protected java.lang.String m_tableName
protected java.lang.String m_resolvedTableName
protected java.lang.String m_inputFile
protected java.lang.String m_createText
protected java.lang.String m_createDouble
protected java.lang.String m_createInt
protected java.lang.String m_createDate
protected java.text.SimpleDateFormat m_DateFormat
protected java.lang.String m_idColumn
protected int m_count
protected boolean m_id
protected boolean m_tabName
protected java.lang.String m_URL
protected java.lang.String m_Username
protected java.lang.String m_Password
protected java.io.File m_CustomPropsFile
protected boolean m_truncate
protected transient Environment m_env
public DatabaseSaver()
throws java.lang.Exception
java.lang.Exception - throws Exception if property file cannot be readpublic static void main(java.lang.String[] options)
options - should contain the options of a Saver.public void setEnvironment(Environment env)
setEnvironment in interface EnvironmentHandlerenv - the environment variables to useprotected DatabaseConnection newDatabaseConnection() throws java.lang.Exception
java.lang.Exceptionm_CustomPropsFilepublic void resetOptions()
resetOptions in class AbstractSaverpublic void cancel()
cancel in class AbstractSaverpublic java.lang.String globalInfo()
@OptionMetadata(displayName="Table name", description="Sets the name of the table", displayOrder=4) public java.lang.String getTableName()
public void setTableName(java.lang.String tn)
tn - the name of the tablepublic java.lang.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 java.lang.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 java.lang.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 java.lang.String relationForTableNameTipText()
@OptionMetadata(displayName="Database URL", description="The URL of the database", displayOrder=1) public java.lang.String getUrl()
getUrl in interface DatabaseConverterpublic void setUrl(java.lang.String url)
setUrl in interface DatabaseConverterurl - the URLpublic java.lang.String urlTipText()
public java.lang.String getUser()
getUser in interface DatabaseConverter@OptionMetadata(displayName="Username", description="The user name for the database", displayOrder=2) public void setUser(java.lang.String user)
setUser in interface DatabaseConverteruser - the user namepublic java.lang.String userTipText()
@OptionMetadata(displayName="Password", description="The database password", displayOrder=3) @PasswordProperty public java.lang.String getPassword()
public void setPassword(java.lang.String password)
setPassword in interface DatabaseConverterpassword - the passwordpublic java.lang.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 java.io.File getCustomPropsFile()
public void setCustomPropsFile(java.io.File value)
value - the custom props file to load database parameters from, use
null or directory to disable custom properties.public java.lang.String customPropsFileTipText()
public void setDestination(java.lang.String url,
java.lang.String userName,
java.lang.String password)
url - the database urluserName - the user namepassword - the passwordpublic void setDestination(java.lang.String url)
url - the database urlpublic void setDestination()
public Capabilities getCapabilities()
getCapabilities in interface CapabilitiesHandlergetCapabilities in class AbstractSaverCapabilitiespublic void connectToDatabase()
public void writeIncremental(Instance inst) throws java.io.IOException
writeIncremental in interface SaverwriteIncremental in class AbstractSaverinst - the instance to savejava.io.IOException - throws IOEXception.public void writeBatch()
throws java.io.IOException
writeBatch in interface SaverwriteBatch in class AbstractSaverjava.io.IOException - throws IOExceptionpublic java.lang.String[] getOptions()
getOptions in interface OptionHandlerpublic void setOptions(java.lang.String[] options)
throws java.lang.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 OptionHandleroptions - the optionsjava.lang.Exception - if options cannot be setpublic java.util.Enumeration<Option> listOptions()
listOptions in interface OptionHandlerpublic java.lang.String getRevision()
getRevision in interface RevisionHandler