|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.experiment.DatabaseUtils
public class DatabaseUtils
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
| Field Summary | |
|---|---|
static int |
BOOL
Type mapping for BOOL used for reading experiment results. |
static int |
BYTE
Type mapping for BYTE used for reading experiment results. |
static int |
DATE
Type mapping for DATE used for reading experiment results. |
static int |
DOUBLE
Type mapping for DOUBLE used for reading experiment results. |
static String |
EXP_INDEX_TABLE
The name of the table containing the index to experiments. |
static String |
EXP_RESULT_COL
The name of the column containing the results table name. |
static String |
EXP_RESULT_PREFIX
The prefix for result table names. |
static String |
EXP_SETUP_COL
The name of the column containing the experiment setup (parameters). |
static String |
EXP_TYPE_COL
The name of the column containing the experiment type (ResultProducer). |
static int |
FLOAT
Type mapping for FLOAT used for reading experiment results. |
static int |
INTEGER
Type mapping for INTEGER used for reading experiment results. |
static int |
LONG
Type mapping for LONG used for reading experiment results. |
static String |
PROPERTY_FILE
The name of the properties file. |
static int |
SHORT
Type mapping for SHORT used for reading experiment results. |
static int |
STRING
Type mapping for STRING used for reading experiment results. |
static int |
TEXT
Type mapping for TEXT used for reading, e.g., text blobs. |
static int |
TIME
Type mapping for TIME used for reading TIME columns. |
| Constructor Summary | |
|---|---|
DatabaseUtils()
Reads properties and sets up the database drivers. |
|
DatabaseUtils(File propsFile)
Reads the properties from the specified file and sets up the database drivers. |
|
DatabaseUtils(Properties props)
Uses the specified properties to set up the database drivers. |
|
| Method Summary | |
|---|---|
static String |
arrayToString(Object[] array)
Converts an array of objects to a string by inserting a space between each element. |
String |
attributeCaseFix(String columnName)
returns key column headings in their original case. |
void |
close()
closes the m_PreparedStatement to avoid memory leaks. |
void |
close(ResultSet rs)
closes the ResultSet and the statement that generated the ResultSet to avoid memory leaks in JDBC drivers - in contrast to the JDBC specs, a lot of JDBC drives don't clean up correctly. |
void |
connectToDatabase()
Opens a connection to the database. |
void |
createExperimentIndex()
Attempts to create the experiment index table. |
String |
createExperimentIndexEntry(ResultProducer rp)
Attempts to insert a results entry for the table into the experiment index. |
String |
createResultsTable(ResultProducer rp,
String tableName)
Creates a results table for the supplied result producer. |
String |
databaseURLTipText()
Returns the tip text for this property. |
String |
debugTipText()
Returns the tip text for this property. |
void |
disconnectFromDatabase()
Closes the connection to the database. |
boolean |
execute(String query)
Executes a SQL query. |
boolean |
experimentIndexExists()
Returns true if the experiment index exists. |
String |
getDatabaseURL()
Get the value of DatabaseURL. |
boolean |
getDebug()
Gets whether there should be printed some debugging output to stderr or not. |
String |
getKeywords()
Returns the currently stored keywords (as comma-separated list). |
String |
getKeywordsMaskChar()
Returns the currently set mask character. |
String |
getPassword()
Get the database password. |
Object[] |
getResultFromTable(String tableName,
ResultProducer rp,
Object[] key)
Executes a database query to extract a result for the supplied key from the database. |
ResultSet |
getResultSet()
Gets the results generated by a previous query. |
String |
getResultsTableName(ResultProducer rp)
Gets the name of the experiment table that stores results from a particular ResultProducer. |
String |
getRevision()
Returns the revision string. |
int |
getSupportedCursorScrollType()
Returns the type of scrolling that the cursor supports, -1 if not supported or not connected. |
String |
getUsername()
Get the database username. |
void |
initialize(File propsFile)
Initializes the database connection. |
void |
initialize(Properties props)
Initializes the database connection. |
boolean |
isConnected()
Returns true if a database connection is active. |
boolean |
isCursorScrollable()
Checks whether cursors are scrollable in general, false otherwise (also if not connected). |
boolean |
isCursorScrollSensitive()
Returns whether the cursors only support forward movement or are scroll sensitive (with ResultSet.CONCUR_READ_ONLY concurrency). |
boolean |
isKeyword(String s)
Checks whether the given string is a reserved keyword. |
String |
maskKeyword(String s)
If the given string is a keyword, then the mask character will be appended and returned. |
String |
passwordTipText()
Returns the tip text for this property. |
static String |
processKeyString(String s)
processes the string in such a way that it can be stored in the database, i.e., it changes backslashes into slashes and doubles single quotes. |
void |
putResultInTable(String tableName,
ResultProducer rp,
Object[] key,
Object[] result)
Executes a database query to insert a result for the supplied key into the database. |
ResultSet |
select(String query)
Executes a SQL SELECT query that returns a ResultSet. |
void |
setDatabaseURL(String newDatabaseURL)
Set the value of DatabaseURL. |
void |
setDebug(boolean d)
Sets whether there should be printed some debugging output to stderr or not. |
void |
setKeywords(String value)
Sets the keywords (comma-separated list) to use. |
void |
setKeywordsMaskChar(String value)
Sets the mask character to append to table or attribute names that are a reserved keyword. |
void |
setPassword(String password)
Set the database password. |
void |
setUsername(String username)
Set the database username. |
boolean |
tableExists(String tableName)
Checks that a given table exists. |
int |
translateDBColumnType(String type)
translates the column data type string to an integer value that indicates which data type / get()-Method to use in order to retrieve values from the database (see DatabaseUtils.Properties, InstanceQuery()). |
static String |
typeName(int type)
Returns the name associated with a SQL type. |
int |
update(String query)
Executes a SQL DDL query or an INSERT, DELETE or UPDATE. |
String |
usernameTipText()
Returns the tip text for this property. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String EXP_INDEX_TABLE
public static final String EXP_TYPE_COL
public static final String EXP_SETUP_COL
public static final String EXP_RESULT_COL
public static final String EXP_RESULT_PREFIX
public static final String PROPERTY_FILE
public static final int STRING
public static final int BOOL
public static final int DOUBLE
public static final int BYTE
public static final int SHORT
public static final int INTEGER
public static final int LONG
public static final int FLOAT
public static final int DATE
public static final int TEXT
public static final int TIME
| Constructor Detail |
|---|
public DatabaseUtils()
throws Exception
Exception - if an error occurs
public DatabaseUtils(File propsFile)
throws Exception
propsFile - the props file to load, ignored if null or pointing
to a directory
Exception - if an error occurs
public DatabaseUtils(Properties props)
throws Exception
props - the properties to use, ignored if null
Exception - if an error occurs| Method Detail |
|---|
public void initialize(File propsFile)
propsFile - the props file to load, ignored if null or pointing
to a directorypublic void initialize(Properties props)
props - the properties to obtain the parameters from,
ignored if nullpublic String attributeCaseFix(String columnName)
columnName - the column to retrieve the original case for
public int translateDBColumnType(String type)
type - the column type as retrieved with
java.sql.MetaData.getColumnTypeName(int)
public static String arrayToString(Object[] array)
array - the array of objects
public static String typeName(int type)
type - the SQL type
public String databaseURLTipText()
public String getDatabaseURL()
public void setDatabaseURL(String newDatabaseURL)
newDatabaseURL - Value to assign to DatabaseURL.public String debugTipText()
public void setDebug(boolean d)
d - true if output should be printedpublic boolean getDebug()
public String usernameTipText()
public void setUsername(String username)
username - Username for Database.public String getUsername()
public String passwordTipText()
public void setPassword(String password)
password - Password for Database.public String getPassword()
public void connectToDatabase()
throws Exception
Exception - if an error occurs
public void disconnectFromDatabase()
throws Exception
Exception - if an error occurspublic boolean isConnected()
public boolean isCursorScrollSensitive()
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLYpublic boolean isCursorScrollable()
getSupportedCursorScrollType()public int getSupportedCursorScrollType()
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.TYPE_SCROLL_INSENSITIVE
public boolean execute(String query)
throws SQLException
close().
query - the SQL query
SQLException - if an error occursclose()
public ResultSet getResultSet()
throws SQLException
close(ResultSet). Returns null if object has
been deserialized.
SQLException - if an error occursclose(ResultSet)
public int update(String query)
throws SQLException
query - the SQL DDL query
SQLException - if an error occurs
public ResultSet select(String query)
throws SQLException
query - the SQL query
SQLException - if an error occurspublic void close(ResultSet rs)
rs - the ResultSet to clean uppublic void close()
public boolean tableExists(String tableName)
throws Exception
tableName - the name of the table to look for.
Exception - if an error occurs.public static String processKeyString(String s)
s - the string to work on
public Object[] getResultFromTable(String tableName,
ResultProducer rp,
Object[] key)
throws Exception
tableName - the name of the table where the result is storedrp - the ResultProducer who will generate the result if
requiredkey - the key for the result
Exception - if an error occurs
public void putResultInTable(String tableName,
ResultProducer rp,
Object[] key,
Object[] result)
throws Exception
tableName - the name of the table where the result is storedrp - the ResultProducer who will generate the result if
requiredkey - the key for the resultresult - the result to store
Exception - if an error occurs
public boolean experimentIndexExists()
throws Exception
Exception - if an error occurs
public void createExperimentIndex()
throws Exception
Exception - if an error occurs.
public String createExperimentIndexEntry(ResultProducer rp)
throws Exception
rp - the ResultProducer generating the results
Exception - if an error occurs.
public String getResultsTableName(ResultProducer rp)
throws Exception
rp - the ResultProducer
Exception - if an error occurs
public String createResultsTable(ResultProducer rp,
String tableName)
throws Exception
rp - the ResultProducer generating the resultstableName - the name of the resultsTable
Exception - if an error occurs.public void setKeywords(String value)
value - the list of keywordspublic String getKeywords()
public void setKeywordsMaskChar(String value)
value - the new characterpublic String getKeywordsMaskChar()
public boolean isKeyword(String s)
s - the string to check
m_Keywordspublic String maskKeyword(String s)
s - the string to check
m_KeywordsMaskChar,
isKeyword(String)public String getRevision()
getRevision in interface RevisionHandler
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||