All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.experiment.DatabaseUtils

java.lang.Object
   |
   +----weka.experiment.DatabaseUtils

public class DatabaseUtils
extends Object
implements Serializable
DatabaseUtils provides utility functions for accessing the experiment database. The jdbc driver and database to be used default to "jdbc.idbDriver" and "jdbc:idb=experiments.prp". These may be changed by creating a java properties file called DatabaseUtils.props in user.home or the current directory. eg:

 jdbcDriver=jdbc.idbDriver
 jdbcURL=jdbc:idb=experiments.prp
 

Version:
$Revision: 1.5 $
Author:
Len Trigg (trigg@cs.waikato.ac.nz)

Variable Index

 o EXP_INDEX_TABLE
The name of the table containing the index to experiments
 o EXP_RESULT_COL
The name of the column containing the results table name
 o EXP_RESULT_PREFIX
The prefix for result table names
 o EXP_SETUP_COL
The name of the column containing the experiment setup (parameters)
 o EXP_TYPE_COL
The name of the column containing the experiment type (ResultProducer)

Constructor Index

 o DatabaseUtils()
Sets up the database drivers

Method Index

 o arrayToString(Object[])
Converts an array of objects to a string by inserting a space between each element.
 o connectToDatabase()
Opens a connection to the database
 o createExperimentIndex()
Attempts to create the experiment index table
 o createExperimentIndexEntry(ResultProducer)
Attempts to insert a results entry for the table into the experiment index.
 o createResultsTable(ResultProducer, String)
Creates a results table for the supplied result producer.
 o disconnectFromDatabase()
Closes the connection to the database.
 o execute(String)
Executes a SQL query.
 o experimentIndexExists()
Returns true if the experiment index exists.
 o getDatabaseURL()
Get the value of DatabaseURL.
 o getResultFromTable(String, ResultProducer, Object[])
Executes a database query to extract a result for the supplied key from the database.
 o getResultSet()
Gets the results generated by a previous query.
 o getResultsTableName(ResultProducer)
Gets the name of the experiment table that stores results from a particular ResultProducer.
 o isConnected()
Returns true if a database connection is active.
 o putResultInTable(String, ResultProducer, Object[], Object[])
Executes a database query to insert a result for the supplied key into the database.
 o setDatabaseURL(String)
Set the value of DatabaseURL.
 o tableExists(String)
Checks that a given table exists.
 o typeName(int)
Returns the name associated with a SQL type.

Variables

 o EXP_INDEX_TABLE
 public static final String EXP_INDEX_TABLE
The name of the table containing the index to experiments

 o EXP_TYPE_COL
 public static final String EXP_TYPE_COL
The name of the column containing the experiment type (ResultProducer)

 o EXP_SETUP_COL
 public static final String EXP_SETUP_COL
The name of the column containing the experiment setup (parameters)

 o EXP_RESULT_COL
 public static final String EXP_RESULT_COL
The name of the column containing the results table name

 o EXP_RESULT_PREFIX
 public static final String EXP_RESULT_PREFIX
The prefix for result table names

Constructors

 o DatabaseUtils
 public DatabaseUtils() throws Exception
Sets up the database drivers

Throws: Exception
if an error occurs

Methods

 o arrayToString
 public static String arrayToString(Object array[])
Converts an array of objects to a string by inserting a space between each element. Null elements are printed as ?

Parameters:
array - the array of objects
Returns:
a value of type 'String'
 o typeName
 public static String typeName(int type)
Returns the name associated with a SQL type.

Parameters:
type - the SQL type
Returns:
the name of the type
 o getDatabaseURL
 public String getDatabaseURL()
Get the value of DatabaseURL.

Returns:
Value of DatabaseURL.
 o setDatabaseURL
 public void setDatabaseURL(String newDatabaseURL)
Set the value of DatabaseURL.

Parameters:
newDatabaseURL - Value to assign to DatabaseURL.
 o connectToDatabase
 public void connectToDatabase() throws Exception
Opens a connection to the database

Throws: Exception
if an error occurs
 o disconnectFromDatabase
 public void disconnectFromDatabase() throws Exception
Closes the connection to the database.

Throws: Exception
if an error occurs
 o isConnected
 public boolean isConnected()
Returns true if a database connection is active.

Returns:
a value of type 'boolean'
 o execute
 public boolean execute(String query) throws SQLException
Executes a SQL query.

Parameters:
query - the SQL query
Returns:
true if the query generated results
Throws: SQLException
if an error occurs
 o getResultSet
 public ResultSet getResultSet() throws SQLException
Gets the results generated by a previous query.

Returns:
the result set.
Throws: SQLException
if an error occurs
 o tableExists
 public boolean tableExists(String tableName) throws Exception
Checks that a given table exists.

Parameters:
tableName - the name of the table to look for.
Returns:
true if the table exists.
Throws: Exception
if an error occurs.
 o getResultFromTable
 public Object[] getResultFromTable(String tableName,
                                    ResultProducer rp,
                                    Object key[]) throws Exception
Executes a database query to extract a result for the supplied key from the database.

Parameters:
tableName - the name of the table where the result is stored
rp - the ResultProducer who will generate the result if required
key - the key for the result
Returns:
true if the result with that key is in the database already
Throws: Exception
if an error occurs
 o putResultInTable
 public void putResultInTable(String tableName,
                              ResultProducer rp,
                              Object key[],
                              Object result[]) throws Exception
Executes a database query to insert a result for the supplied key into the database.

Parameters:
tableName - the name of the table where the result is stored
rp - the ResultProducer who will generate the result if required
key - the key for the result
result - the result to store
Returns:
true if the result with that key is in the database already
Throws: Exception
if an error occurs
 o experimentIndexExists
 public boolean experimentIndexExists() throws Exception
Returns true if the experiment index exists.

Returns:
true if the index exists
Throws: Exception
if an error occurs
 o createExperimentIndex
 public void createExperimentIndex() throws Exception
Attempts to create the experiment index table

Throws: Exception
if an error occurs.
 o createExperimentIndexEntry
 public String createExperimentIndexEntry(ResultProducer rp) throws Exception
Attempts to insert a results entry for the table into the experiment index.

Parameters:
rp - the ResultProducer generating the results
Returns:
the name of the created results table
Throws: Exception
if an error occurs.
 o getResultsTableName
 public String getResultsTableName(ResultProducer rp) throws Exception
Gets the name of the experiment table that stores results from a particular ResultProducer.

Parameters:
rp - the ResultProducer
Returns:
the name of the table where the results for this ResultProducer are stored, or null if there is no table for this ResultProducer.
Throws: Exception
if an error occurs
 o createResultsTable
 public String createResultsTable(ResultProducer rp,
                                  String tableName) throws Exception
Creates a results table for the supplied result producer.

Parameters:
rp - the ResultProducer generating the results
tableName - the name of the resultsTable
Returns:
the name of the created results table
Throws: Exception
if an error occurs.

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home