public class DatabaseLoader extends AbstractLoader implements BatchConverter, IncrementalConverter, DatabaseConverter, OptionHandler
-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)
-Q <query> SQL query of the form SELECT <list of columns>|* FROM <table> [WHERE] to execute. (default: Select * From Results0)
-P <list of column names> List of column names uniquely defining a DB row (separated by ', '). Used for incremental loading. If not specified, the key will be determined automatically, if possible with the used JDBC driver. The auto ID column created by the DatabaseSaver won't be loaded.
-I Sets incremental loading
Loader
,
Serialized FormBATCH, INCREMENTAL, NONE
Constructor and Description |
---|
DatabaseLoader()
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
connectToDatabase()
Opens a connection to the database
|
Instances |
getDataSet()
Return the full data set in batch mode (header and all intances at once).
|
java.lang.String |
getKeys()
Gets the key columns' name
|
Instance |
getNextInstance(Instances structure)
Read the data set incrementally---get the next instance in the data
set or returns null if there are no
more instances to get.
|
java.lang.String[] |
getOptions()
Gets the setting
|
java.lang.String |
getPassword()
Returns the database password
|
java.lang.String |
getQuery()
Gets the query to execute against the database
|
java.lang.String |
getRevision()
Returns the revision string.
|
Instances |
getStructure()
Determines and returns (if possible) the structure (internally the
header) of the data set as an empty set of instances.
|
java.lang.String |
getUrl()
Gets the URL
|
java.lang.String |
getUser()
Gets the user name
|
java.lang.String |
globalInfo()
Returns a string describing this Loader
|
java.lang.String |
keysTipText()
the tip text for this property
|
java.util.Enumeration |
listOptions()
Lists the available options
|
static void |
main(java.lang.String[] options)
Main method.
|
java.lang.String |
passwordTipText()
the tip text for this property
|
java.lang.String |
queryTipText()
the tip text for this property
|
void |
reset()
Resets the Loader ready to read a new data set
|
void |
resetStructure()
Resets the structure of instances
|
void |
setKeys(java.lang.String keys)
Sets the key columns of a database table
|
void |
setOptions(java.lang.String[] options)
Sets the options.
|
void |
setPassword(java.lang.String password)
Sets user password for the database
|
void |
setQuery(java.lang.String q)
Sets the query to execute against the database
|
void |
setSource()
Sets the database url using the DatabaseUtils file
|
void |
setSource(java.lang.String url)
Sets the database url
|
void |
setSource(java.lang.String url,
java.lang.String userName,
java.lang.String password)
Sets the database url, user and pw
|
void |
setUrl(java.lang.String url)
Sets the database URL
|
void |
setUser(java.lang.String user)
Sets the database user
|
java.lang.String |
urlTipText()
the tip text for this property
|
java.lang.String |
userTipText()
the tip text for this property
|
setRetrieval, setSource, setSource
public DatabaseLoader() throws java.lang.Exception
java.lang.Exception
- if initialization failspublic java.lang.String globalInfo()
public void reset() throws java.lang.Exception
reset
in interface Loader
reset
in class AbstractLoader
java.lang.Exception
- if an error occurs while disconnecting from the databasepublic void resetStructure()
public void setQuery(java.lang.String q)
q
- the query to executepublic java.lang.String getQuery()
public java.lang.String queryTipText()
public void setKeys(java.lang.String keys)
keys
- a String containing the key columns in a comma separated list.public java.lang.String getKeys()
public java.lang.String keysTipText()
public void setUrl(java.lang.String url)
setUrl
in interface DatabaseConverter
url
- string with the database URLpublic java.lang.String getUrl()
getUrl
in interface DatabaseConverter
public java.lang.String urlTipText()
public void setUser(java.lang.String user)
setUser
in interface DatabaseConverter
user
- the database user namepublic java.lang.String getUser()
getUser
in interface DatabaseConverter
public java.lang.String userTipText()
public void setPassword(java.lang.String password)
setPassword
in interface DatabaseConverter
password
- the passwordpublic java.lang.String getPassword()
public java.lang.String passwordTipText()
public void setSource(java.lang.String url, java.lang.String userName, java.lang.String password)
url
- the database urluserName
- the user namepassword
- the passwordpublic void setSource(java.lang.String url)
url
- the database urlpublic void setSource() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic void connectToDatabase()
public Instances getStructure() throws java.io.IOException
getStructure
in interface Loader
getStructure
in class AbstractLoader
java.io.IOException
- if an error occurspublic Instances getDataSet() throws java.io.IOException
getDataSet
in interface Loader
getDataSet
in class AbstractLoader
java.io.IOException
- if there is no source or parsing failspublic Instance getNextInstance(Instances structure) throws java.io.IOException
getNextInstance
in interface Loader
getNextInstance
in class AbstractLoader
structure
- the dataset header information, will get updated in
case of string or relational attributesjava.io.IOException
- if there is an error during parsingpublic java.lang.String[] getOptions()
getOptions
in interface OptionHandler
public java.util.Enumeration listOptions()
listOptions
in interface OptionHandler
public 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)
-Q <query> SQL query of the form SELECT <list of columns>|* FROM <table> [WHERE] to execute. (default: Select * From Results0)
-P <list of column names> List of column names uniquely defining a DB row (separated by ', '). Used for incremental loading. If not specified, the key will be determined automatically, if possible with the used JDBC driver. The auto ID column created by the DatabaseSaver won't be loaded.
-I Sets incremental loading
setOptions
in interface OptionHandler
options
- the optionsjava.lang.Exception
- if options cannot be setpublic java.lang.String getRevision()
getRevision
in interface RevisionHandler
public static void main(java.lang.String[] options)
options
- the options