public class DatabaseLoader extends AbstractLoader 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)
-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 FormLoader.StructureNotReadyException| Modifier and Type | Field and Description |
|---|---|
protected boolean |
m_checkForTable
If true it checks whether or not the table exists in the database before
loading depending on jdbc metadata information.
|
protected int |
m_choice
Decides which SQL statement to limit the number of rows should be used.
|
protected int |
m_counter
Indicates how many rows has already been loaded incrementally
|
protected boolean |
m_CreateSparseData
Determines whether sparse data is created
|
protected java.io.File |
m_CustomPropsFile
the custom props file to use instead of default one.
|
protected DatabaseConnection |
m_DataBaseConnection
The database connection
|
protected Instances |
m_datasetPseudoInc
Used in pseudoincremental mode.
|
protected Environment |
m_env
Environment variables
|
protected boolean |
m_firstTime
Flag indicating that incremental process wants to read first instance
|
protected java.lang.String |
m_idColumn
Name of the primary key column that will allow unique ordering necessary
for incremental loading.
|
protected boolean |
m_inc
Flag indicating that incremental mode is chosen (for command line use only)
|
protected java.lang.String |
m_Keys
the keys for unique ordering
|
protected java.util.Hashtable<java.lang.String,java.lang.Double>[] |
m_nominalIndexes
Stores the index of a nominal value
|
protected java.util.ArrayList<java.lang.String>[] |
m_nominalStrings
Stores the nominal value
|
protected int |
m_nominalToStringLimit
Limit when an attribute is treated as string attribute and not as a nominal
one because it has to many values.
|
protected Instances |
m_oldStructure
Set of instances that equals m_structure except that the auto_generated_id
column is not included as an attribute
|
protected java.util.ArrayList<java.lang.String> |
m_orderBy
Contains the name of the columns that uniquely define a row in the
ResultSet.
|
protected java.lang.String |
m_Password
the database password to use
|
protected boolean |
m_pseudoIncremental
Flag indicating that pseudo incremental mode is used (all instances load at
once into main memeory and then incrementally from main memory instead of
the database)
|
protected java.lang.String |
m_query
The user defined query to load instances.
|
protected int |
m_rowCount
The number of rows obtained by m_query, eg the size of the ResultSet to
load
|
protected Instances |
m_structure
The header information that is retrieved in the beginning of incremental
loading
|
protected java.lang.String |
m_URL
the JDBC URL to use
|
protected java.lang.String |
m_User
the database user to use
|
m_retrievalBATCH, INCREMENTAL, NONE| Constructor and Description |
|---|
DatabaseLoader()
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
connectToDatabase()
Opens a connection to the database
|
java.lang.String |
customPropsFileTipText()
The tip text for this property.
|
java.io.File |
getCustomPropsFile()
Returns the custom properties file in use, if any.
|
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.
|
boolean |
getSparseData()
Gets whether data is to be returned as a set of sparse instances
|
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<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()
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 using set options
|
void |
resetOptions()
Resets the Loader to the settings in either the default DatabaseUtils.props
or any property file that the user has specified via setCustomPropsFile().
|
void |
resetStructure()
Resets the structure of instances
|
void |
setCustomPropsFile(java.io.File value)
Sets the custom properties file to use.
|
void |
setEnvironment(Environment env)
Set the environment variables to use.
|
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 |
setSparseData(boolean s)
Sets whether data should be encoded as sparse instances
|
void |
setUrl(java.lang.String url)
Sets the database URL
|
void |
setUser(java.lang.String user)
Sets the database user
|
java.lang.String |
sparseDataTipText()
Returns the tip text for this property
|
java.lang.String |
urlTipText()
the tip text for this property
|
java.lang.String |
userTipText()
the tip text for this property
|
getRetrieval, setRetrieval, setSource, setSourceprotected Instances m_structure
protected Instances m_datasetPseudoInc
protected Instances m_oldStructure
protected DatabaseConnection m_DataBaseConnection
protected java.lang.String m_query
protected boolean m_pseudoIncremental
protected boolean m_checkForTable
protected int m_nominalToStringLimit
protected int m_rowCount
protected int m_counter
protected int m_choice
protected boolean m_firstTime
protected boolean m_inc
protected java.util.ArrayList<java.lang.String> m_orderBy
protected java.util.Hashtable<java.lang.String,java.lang.Double>[] m_nominalIndexes
protected java.util.ArrayList<java.lang.String>[] m_nominalStrings
protected java.lang.String m_idColumn
protected java.lang.String m_URL
protected java.lang.String m_User
protected java.lang.String m_Password
protected java.lang.String m_Keys
protected java.io.File m_CustomPropsFile
protected boolean m_CreateSparseData
protected transient Environment m_env
public DatabaseLoader()
throws java.lang.Exception
java.lang.Exception - if initialization failspublic java.lang.String globalInfo()
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()
public void reset()
reset in interface Loaderreset in class AbstractLoaderjava.lang.Exception - if an error occurs while disconnecting from the databasepublic void resetStructure()
public void setQuery(java.lang.String q)
q - the query to execute@OptionMetadata(displayName="Query", description="The query to execute", displayOrder=4) public 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.@OptionMetadata(displayName="Key columns", description="Specific key columns to use if a primary key cannot be automatically detected. Used in incremental loading.", displayOrder=5) public java.lang.String getKeys()
public java.lang.String keysTipText()
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.@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 java.lang.String customPropsFileTipText()
public void setUrl(java.lang.String url)
setUrl in interface DatabaseConverterurl - string with the database URL@OptionMetadata(displayName="Database URL", description="The URL of the database", displayOrder=1) public java.lang.String getUrl()
getUrl in interface DatabaseConverterpublic java.lang.String urlTipText()
public void setUser(java.lang.String user)
setUser in interface DatabaseConverteruser - the database user name@OptionMetadata(displayName="Username", description="The user name for the database", displayOrder=2) public java.lang.String getUser()
getUser in interface DatabaseConverterpublic java.lang.String userTipText()
public void setPassword(java.lang.String password)
setPassword in interface DatabaseConverterpassword - the password@OptionMetadata(displayName="Password", description="The database password", displayOrder=3) @PasswordProperty public java.lang.String getPassword()
public java.lang.String passwordTipText()
public java.lang.String sparseDataTipText()
public void setSparseData(boolean s)
s - true if data should be encoded as a set of sparse instances@OptionMetadata(displayName="Create sparse instances", description="Return sparse rather than normal instances", displayOrder=6) public boolean getSparseData()
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 LoadergetStructure in class AbstractLoaderjava.io.IOException - if an error occurspublic Instances getDataSet() throws java.io.IOException
getDataSet in interface LoadergetDataSet in class AbstractLoaderjava.io.IOException - if there is no source or parsing failspublic Instance getNextInstance(Instances structure) throws java.io.IOException
getNextInstance in interface LoadergetNextInstance in class AbstractLoaderstructure - 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 OptionHandlerpublic java.util.Enumeration<Option> listOptions()
listOptions 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)
-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 OptionHandleroptions - the optionsjava.lang.Exception - if options cannot be setpublic java.lang.String getRevision()
getRevision in interface RevisionHandlerpublic static void main(java.lang.String[] options)
options - the options