db
Class DbInterface

java.lang.Object
  extended by java.lang.Thread
      extended by biocell.BioThread
          extended by db.DbInterface
All Implemented Interfaces:
java.lang.Runnable

public class DbInterface
extends BioThread

Author:
nabhoth TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.sql.Connection conn
          Connection to server, initialized in setUp() Cleaned up in tearDown().
protected  java.lang.String dbClass
          The driver to use
protected static java.lang.String dbUrl
          JDBC URL, initialized from com.mysql.jdbc.testsuite.url system property, or defaults to jdbc:mysql:///test
protected  java.sql.PreparedStatement pstmt
          PreparedStatement to be used in tests, not initialized.
protected  java.sql.ResultSet rs
          ResultSet to be used in tests, not initialized.
protected  java.sql.Statement stmt
          Statement to be used in tests, initialized in setUp().
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DbInterface(java.lang.String name)
          Creates a new BaseTestCase object.
 
Method Summary
protected  void createTable(java.lang.String tableName, java.lang.String columnsAndOtherStuff)
           
protected  void dropTable(java.lang.String tableName)
           
protected  java.sql.Connection getAdminConnection()
           
protected  java.sql.Connection getAdminConnectionWithProps(java.util.Properties props)
           
protected  java.sql.Connection getConnectionWithProps(java.util.Properties props)
          Returns a new connection with the given properties
protected  java.sql.Connection getConnectionWithProps(java.lang.String url, java.util.Properties props)
           
protected  int getInstanceNumber()
          Returns the per-instance counter (for messages when multi-threading stress tests)
protected  java.lang.String getMysqlVariable(java.sql.Connection c, java.lang.String variableName)
           
protected  java.lang.String getMysqlVariable(java.lang.String variableName)
          Returns the named MySQL variable from the currently connected server.
protected  int getRowCount(java.lang.String tableName)
           
protected  java.lang.Object getSingleIndexedValueWithQuery(java.sql.Connection c, int columnIndex, java.lang.String query)
           
protected  java.lang.Object getSingleIndexedValueWithQuery(int columnIndex, java.lang.String query)
           
protected  java.lang.Object getSingleValue(java.lang.String tableName, java.lang.String columnName, java.lang.String whereClause)
           
protected  java.lang.Object getSingleValueWithQuery(java.lang.String query)
           
protected  boolean isAdminConnectionConfigured()
           
 void logDebug(java.lang.String message)
           
protected  boolean runLongTests()
           
protected  boolean runTestIfSysPropDefined(java.lang.String propName)
          Checks whether a certain system property is defined, in order to run/not-run certain tests
 void setUp()
          Creates resources used by all tests.
 void tearDown()
          Destroys resources created during the test case.
protected  boolean versionMeetsMinimum(int major, int minor)
          Checks whether the database we're connected to meets the given version minimum
protected  boolean versionMeetsMinimum(int major, int minor, int subminor)
          Checks whether the database we're connected to meets the given version minimum
 
Methods inherited from class biocell.BioThread
getCurrentmood, getMoodParam, getstate, setMood, stepEnergy
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dbUrl

protected static java.lang.String dbUrl
JDBC URL, initialized from com.mysql.jdbc.testsuite.url system property, or defaults to jdbc:mysql:///test


conn

protected java.sql.Connection conn
Connection to server, initialized in setUp() Cleaned up in tearDown().


pstmt

protected java.sql.PreparedStatement pstmt
PreparedStatement to be used in tests, not initialized. Cleaned up in tearDown().


rs

protected java.sql.ResultSet rs
ResultSet to be used in tests, not initialized. Cleaned up in tearDown().


stmt

protected java.sql.Statement stmt
Statement to be used in tests, initialized in setUp(). Cleaned up in tearDown().


dbClass

protected java.lang.String dbClass
The driver to use

Constructor Detail

DbInterface

public DbInterface(java.lang.String name)
Creates a new BaseTestCase object.

Parameters:
name - The name of the JUnit test case
Method Detail

setUp

public void setUp()
           throws java.lang.Exception
Creates resources used by all tests.

Throws:
java.lang.Exception - if an error occurs.

tearDown

public void tearDown()
              throws java.lang.Exception
Destroys resources created during the test case.

Throws:
java.lang.Exception - DOCUMENT ME!

getAdminConnection

protected java.sql.Connection getAdminConnection()
                                          throws java.sql.SQLException
Throws:
java.sql.SQLException

isAdminConnectionConfigured

protected boolean isAdminConnectionConfigured()

getAdminConnectionWithProps

protected java.sql.Connection getAdminConnectionWithProps(java.util.Properties props)
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getConnectionWithProps

protected java.sql.Connection getConnectionWithProps(java.util.Properties props)
                                              throws java.sql.SQLException
Returns a new connection with the given properties

Parameters:
props - the properties to use (the URL will come from the standard for this testcase).
Returns:
a new connection using the given properties.
Throws:
java.sql.SQLException - DOCUMENT ME!

getInstanceNumber

protected int getInstanceNumber()
Returns the per-instance counter (for messages when multi-threading stress tests)

Returns:
int the instance number

getMysqlVariable

protected java.lang.String getMysqlVariable(java.lang.String variableName)
                                     throws java.sql.SQLException
Returns the named MySQL variable from the currently connected server.

Parameters:
variableName - the name of the variable to return
Returns:
the value of the given variable, or NULL if it doesn't exist
Throws:
java.sql.SQLException - if an error occurs

getMysqlVariable

protected java.lang.String getMysqlVariable(java.sql.Connection c,
                                            java.lang.String variableName)
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

getRowCount

protected int getRowCount(java.lang.String tableName)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getSingleIndexedValueWithQuery

protected java.lang.Object getSingleIndexedValueWithQuery(int columnIndex,
                                                          java.lang.String query)
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getSingleIndexedValueWithQuery

protected java.lang.Object getSingleIndexedValueWithQuery(java.sql.Connection c,
                                                          int columnIndex,
                                                          java.lang.String query)
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getSingleValue

protected java.lang.Object getSingleValue(java.lang.String tableName,
                                          java.lang.String columnName,
                                          java.lang.String whereClause)
                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getSingleValueWithQuery

protected java.lang.Object getSingleValueWithQuery(java.lang.String query)
                                            throws java.sql.SQLException
Throws:
java.sql.SQLException

runTestIfSysPropDefined

protected boolean runTestIfSysPropDefined(java.lang.String propName)
Checks whether a certain system property is defined, in order to run/not-run certain tests

Parameters:
propName - the property name to check for
Returns:
true if the property is defined.

versionMeetsMinimum

protected boolean versionMeetsMinimum(int major,
                                      int minor)
                               throws java.sql.SQLException
Checks whether the database we're connected to meets the given version minimum

Parameters:
major - the major version to meet
minor - the minor version to meet
Returns:
boolean if the major/minor is met
Throws:
java.sql.SQLException - if an error occurs.

versionMeetsMinimum

protected boolean versionMeetsMinimum(int major,
                                      int minor,
                                      int subminor)
                               throws java.sql.SQLException
Checks whether the database we're connected to meets the given version minimum

Parameters:
major - the major version to meet
minor - the minor version to meet
Returns:
boolean if the major/minor is met
Throws:
java.sql.SQLException - if an error occurs.

createTable

protected void createTable(java.lang.String tableName,
                           java.lang.String columnsAndOtherStuff)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

dropTable

protected void dropTable(java.lang.String tableName)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

logDebug

public void logDebug(java.lang.String message)

runLongTests

protected final boolean runLongTests()

getConnectionWithProps

protected java.sql.Connection getConnectionWithProps(java.lang.String url,
                                                     java.util.Properties props)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException