public class DatabaseUtils extends java.lang.Object implements java.io.Serializable, RevisionHandler
jdbcDriver=jdbc.idbDriver
jdbcURL=jdbc:idb=experiments.prp
Modifier and Type | Field and Description |
---|---|
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 java.lang.String |
EXP_INDEX_TABLE
The name of the table containing the index to experiments.
|
static java.lang.String |
EXP_RESULT_COL
The name of the column containing the results table name.
|
static java.lang.String |
EXP_RESULT_PREFIX
The prefix for result table names.
|
static java.lang.String |
EXP_SETUP_COL
The name of the column containing the experiment setup (parameters).
|
static java.lang.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 java.lang.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.
|
static int |
TIMESTAMP
Type mapping for TIMESTAMP used for reading java.sql.Timestamp columns
|
Constructor and Description |
---|
DatabaseUtils()
Reads properties and sets up the database drivers.
|
DatabaseUtils(java.io.File propsFile)
Reads the properties from the specified file and sets up the database
drivers.
|
DatabaseUtils(java.util.Properties props)
Uses the specified properties to set up the database drivers.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
arrayToString(java.lang.Object[] array)
Converts an array of objects to a string by inserting a space between each
element.
|
java.lang.String |
attributeCaseFix(java.lang.String columnName)
returns key column headings in their original case.
|
void |
close()
closes the m_PreparedStatement to avoid memory leaks.
|
void |
close(java.sql.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.
|
java.lang.String |
createExperimentIndexEntry(ResultProducer rp)
Attempts to insert a results entry for the table into the experiment index.
|
java.lang.String |
createResultsTable(ResultProducer rp,
java.lang.String tableName)
Creates a results table for the supplied result producer.
|
java.lang.String |
databaseURLTipText()
Returns the tip text for this property.
|
java.lang.String |
debugTipText()
Returns the tip text for this property.
|
void |
disconnectFromDatabase()
Closes the connection to the database.
|
boolean |
execute(java.lang.String query)
Executes a SQL query.
|
boolean |
experimentIndexExists()
Returns true if the experiment index exists.
|
java.lang.String |
getDatabaseURL()
Get the value of DatabaseURL.
|
boolean |
getDebug()
Gets whether there should be printed some debugging output to stderr or
not.
|
java.lang.String |
getKeywords()
Returns the currently stored keywords (as comma-separated list).
|
java.lang.String |
getKeywordsMaskChar()
Returns the currently set mask character.
|
java.lang.String |
getPassword()
Get the database password.
|
java.lang.Object[] |
getResultFromTable(java.lang.String tableName,
ResultProducer rp,
java.lang.Object[] key)
Executes a database query to extract a result for the supplied key from the
database.
|
java.sql.ResultSet |
getResultSet()
Gets the results generated by a previous query.
|
java.lang.String |
getResultsTableName(ResultProducer rp)
Gets the name of the experiment table that stores results from a particular
ResultProducer.
|
java.lang.String |
getRevision()
Returns the revision string.
|
int |
getSupportedCursorScrollType()
Returns the type of scrolling that the cursor supports, -1 if not supported
or not connected.
|
java.lang.String |
getUsername()
Get the database username.
|
void |
initialize(java.io.File propsFile)
Initializes the database connection.
|
void |
initialize(java.util.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(java.lang.String s)
Checks whether the given string is a reserved keyword.
|
java.lang.String |
maskKeyword(java.lang.String s)
If the given string is a keyword, then the mask character will be appended
and returned.
|
java.lang.String |
passwordTipText()
Returns the tip text for this property.
|
static java.lang.String |
processKeyString(java.lang.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(java.lang.String tableName,
ResultProducer rp,
java.lang.Object[] key,
java.lang.Object[] result)
Executes a database query to insert a result for the supplied key into the
database.
|
java.sql.ResultSet |
select(java.lang.String query)
Executes a SQL SELECT query that returns a ResultSet.
|
void |
setDatabaseURL(java.lang.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(java.lang.String value)
Sets the keywords (comma-separated list) to use.
|
void |
setKeywordsMaskChar(java.lang.String value)
Sets the mask character to append to table or attribute names that are a
reserved keyword.
|
void |
setPassword(java.lang.String password)
Set the database password.
|
void |
setUsername(java.lang.String username)
Set the database username.
|
boolean |
tableExists(java.lang.String tableName)
Checks that a given table exists.
|
int |
translateDBColumnType(java.lang.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 java.lang.String |
typeName(int type)
Returns the name associated with a SQL type.
|
int |
update(java.lang.String query)
Executes a SQL DDL query or an INSERT, DELETE or UPDATE.
|
java.lang.String |
usernameTipText()
Returns the tip text for this property.
|
public static final java.lang.String EXP_INDEX_TABLE
public static final java.lang.String EXP_TYPE_COL
public static final java.lang.String EXP_SETUP_COL
public static final java.lang.String EXP_RESULT_COL
public static final java.lang.String EXP_RESULT_PREFIX
public static final java.lang.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
public static final int TIMESTAMP
public DatabaseUtils() throws java.lang.Exception
java.lang.Exception
- if an error occurspublic DatabaseUtils(java.io.File propsFile) throws java.lang.Exception
propsFile
- the props file to load, ignored if null or pointing to a
directoryjava.lang.Exception
- if an error occurspublic DatabaseUtils(java.util.Properties props) throws java.lang.Exception
props
- the properties to use, ignored if nulljava.lang.Exception
- if an error occurspublic void initialize(java.io.File propsFile)
propsFile
- the props file to load, ignored if null or pointing to a
directorypublic void initialize(java.util.Properties props)
props
- the properties to obtain the parameters from, ignored if nullpublic java.lang.String attributeCaseFix(java.lang.String columnName)
columnName
- the column to retrieve the original case forpublic int translateDBColumnType(java.lang.String type)
type
- the column type as retrieved with
java.sql.MetaData.getColumnTypeName(int)public static java.lang.String arrayToString(java.lang.Object[] array)
array
- the array of objectspublic static java.lang.String typeName(int type)
type
- the SQL typepublic java.lang.String databaseURLTipText()
public java.lang.String getDatabaseURL()
public void setDatabaseURL(java.lang.String newDatabaseURL)
newDatabaseURL
- Value to assign to DatabaseURL.public java.lang.String debugTipText()
public void setDebug(boolean d)
d
- true if output should be printedpublic boolean getDebug()
public java.lang.String usernameTipText()
public void setUsername(java.lang.String username)
username
- Username for Database.public java.lang.String getUsername()
public java.lang.String passwordTipText()
public void setPassword(java.lang.String password)
password
- Password for Database.public java.lang.String getPassword()
public void connectToDatabase() throws java.lang.Exception
java.lang.Exception
- if an error occurspublic void disconnectFromDatabase() throws java.lang.Exception
java.lang.Exception
- if an error occurspublic boolean isConnected()
public boolean isCursorScrollSensitive()
ResultSet.TYPE_SCROLL_SENSITIVE
,
ResultSet.TYPE_FORWARD_ONLY
,
ResultSet.CONCUR_READ_ONLY
public boolean isCursorScrollable()
getSupportedCursorScrollType()
public int getSupportedCursorScrollType()
ResultSet.TYPE_SCROLL_SENSITIVE
,
ResultSet.TYPE_SCROLL_INSENSITIVE
public boolean execute(java.lang.String query) throws java.sql.SQLException
close()
.query
- the SQL queryjava.sql.SQLException
- if an error occursclose()
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
close(ResultSet)
. Returns null if object has
been deserialized.java.sql.SQLException
- if an error occursclose(ResultSet)
public int update(java.lang.String query) throws java.sql.SQLException
query
- the SQL DDL queryjava.sql.SQLException
- if an error occurspublic java.sql.ResultSet select(java.lang.String query) throws java.sql.SQLException
query
- the SQL queryjava.sql.SQLException
- if an error occurspublic void close(java.sql.ResultSet rs)
rs
- the ResultSet to clean uppublic void close()
public boolean tableExists(java.lang.String tableName) throws java.lang.Exception
tableName
- the name of the table to look for.java.lang.Exception
- if an error occurs.public static java.lang.String processKeyString(java.lang.String s)
s
- the string to work onpublic java.lang.Object[] getResultFromTable(java.lang.String tableName, ResultProducer rp, java.lang.Object[] key) throws java.lang.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 resultjava.lang.Exception
- if an error occurspublic void putResultInTable(java.lang.String tableName, ResultProducer rp, java.lang.Object[] key, java.lang.Object[] result) throws java.lang.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 storejava.lang.Exception
- if an error occurspublic boolean experimentIndexExists() throws java.lang.Exception
java.lang.Exception
- if an error occurspublic void createExperimentIndex() throws java.lang.Exception
java.lang.Exception
- if an error occurs.public java.lang.String createExperimentIndexEntry(ResultProducer rp) throws java.lang.Exception
rp
- the ResultProducer generating the resultsjava.lang.Exception
- if an error occurs.public java.lang.String getResultsTableName(ResultProducer rp) throws java.lang.Exception
rp
- the ResultProducerjava.lang.Exception
- if an error occurspublic java.lang.String createResultsTable(ResultProducer rp, java.lang.String tableName) throws java.lang.Exception
rp
- the ResultProducer generating the resultstableName
- the name of the resultsTablejava.lang.Exception
- if an error occurs.public void setKeywords(java.lang.String value)
value
- the list of keywordspublic java.lang.String getKeywords()
public void setKeywordsMaskChar(java.lang.String value)
value
- the new characterpublic java.lang.String getKeywordsMaskChar()
public boolean isKeyword(java.lang.String s)
s
- the string to checkm_Keywords
public java.lang.String maskKeyword(java.lang.String s)
s
- the string to checkm_KeywordsMaskChar
,
isKeyword(String)
public java.lang.String getRevision()
getRevision
in interface RevisionHandler