public abstract class BaseJDBCTestCase extends BaseTestCase
Modifier and Type | Field and Description |
---|---|
private java.sql.Connection |
conn
Maintain a single connection to the default
database, opened at the first call to getConnection.
|
private java.util.List<java.sql.Connection> |
connections
Maintain a list of connection objects that
were returned by utility methods and close
them at teardown.
|
private static boolean |
ORDERED |
private java.util.List<java.sql.Statement> |
statements
Maintain a list of statement objects that
were returned by utility methods and close
them at teardown.
|
private static boolean |
UNORDERED |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
BaseJDBCTestCase(java.lang.String name)
Create a test case with the given name.
|
Modifier and Type | Method and Description |
---|---|
private void |
addConnection(java.sql.Connection c)
Add connection to the list.
|
private void |
addStatement(java.sql.Statement s)
Add a statement into the list we will close
at tearDown.
|
void |
assertCallError(java.lang.String expectedSE,
java.lang.String callSQL)
Executes the Callable statement that is expected to fail and verifies
that it throws the expected SQL exception.
|
void |
assertCheckTable(java.lang.String table)
Check the table using SYSCS_UTIL.SYSCS_CHECK_TABLE.
|
static void |
assertCommitError(java.lang.String sqlState,
java.sql.Connection c)
Assert that that a commit fails with the given error
|
void |
assertCompileError(java.lang.String sqlState,
java.lang.String sql)
Assert that the SQL statement does not compile and throws
a SQLException with the expected state.
|
static void |
assertEquals(java.sql.Blob b1,
java.sql.Blob b2)
Assert equality between two
Blob objects. |
static void |
assertEquals(java.sql.Clob c1,
java.sql.Clob c2)
Assert equality between two
Clob objects. |
static void |
assertEquals(java.lang.String msg,
java.sql.Time t1,
java.sql.Time t2)
Assert equality between two
java.sql.Time objects. |
static void |
assertEquivalentDataType(int expectedType,
int type)
Compares two JDBC types to see if they are equivalent.
|
static void |
assertErrorCode(int expected,
java.sql.SQLException exception)
Assert that the error code is as expected.
|
private void |
assertEscapedTableRowCount(java.lang.String escapedTableName,
int rowCount)
Assert that the number of rows in a table is an expected value.
|
static void |
assertGetIntError(int position,
java.lang.String sqlState,
java.sql.ResultSet rs)
Perform getInt(position) with expected error
|
static void |
assertNextError(java.lang.String sqlState,
java.sql.ResultSet rs)
Perform a fetch on the ResultSet with an expected failure
|
static void |
assertPreparedStatementError(java.lang.String sqlState,
java.sql.PreparedStatement ps)
Assert that the query fails (either in execution, or retrieval of
results--doesn't matter) and throws a SQLException with the expected
state and error code
Parameters must have been already bound, if any.
|
protected void |
assertResults(java.sql.Connection conn,
java.lang.String query,
java.lang.String[][] rows,
boolean trimResults)
Assert that the statement returns the correct results.
|
protected void |
assertResults(java.sql.ResultSet rs,
java.lang.String[][] rows,
boolean trimResults)
Assert that the ResultSet returns the desired rows.
|
static void |
assertSQLExceptionEquals(java.sql.SQLException se1,
java.sql.SQLException se2)
Assert that the two (2) passed-in SQLException's are equals and
not just '=='.
|
static void |
assertSQLState(java.lang.String expected,
java.sql.SQLException exception)
Assert that SQLState is as expected.
|
static void |
assertSQLState(java.lang.String message,
java.lang.String expected,
java.sql.SQLException exception)
Assert that SQLState is as expected.
|
static void |
assertStatementError(java.lang.String[] sqlStates,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails (either in compilation,
execution, or retrieval of results--doesn't matter)
and throws a SQLException with the expected states.
|
static void |
assertStatementError(java.lang.String sqlState,
int errorCode,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails (either in compilation,
execution, or retrieval of results--doesn't matter)
and throws a SQLException with the expected state
and error code
Assumption is that 'query' does *not* have parameters
that need binding and thus can be executed using a
simple Statement.execute() call.
|
static void |
assertStatementError(java.lang.String sqlState,
java.sql.PreparedStatement pSt)
Assert that execution of the received PreparedStatement
object fails (either in execution or when retrieving
results) and throws a SQLException with the expected
state.
|
static void |
assertStatementError(java.lang.String sqlState,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails with a single error
|
private static void |
assertStatementErrorMinion(java.lang.String[] sqlStates,
boolean orderedStates,
java.sql.Statement st,
java.lang.String query)
Asserts that the given statement fails (compilation, execution or
retrieval of results) and throws an
SQLException with the
expected (chained) states. |
static void |
assertStatementErrorUnordered(java.lang.String[] sqlStates,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails (either in compilation,
execution, or retrieval of results--doesn't matter)
and throws a SQLException with the expected states.
|
protected void |
assertTableRowCount(java.lang.String table,
int rowCount)
Assert that the number of rows in a table is an expected value.
|
static void |
assertUpdateCount(java.sql.PreparedStatement pSt,
int expectedRC)
Assert that a call to "executeUpdate()" on the received
PreparedStatement object returns a row count that matches
the received row count.
|
static void |
assertUpdateCount(java.sql.Statement st,
int expectedRC,
java.lang.String sql)
Take a Statement object and a SQL statement, execute it
via the "executeUpdate()" method, and assert that the
resultant row count matches the received row count.
|
static void |
assertWarning(java.sql.Connection conn,
java.lang.String expected)
Assert that a warning is chained to the connection.
|
protected java.sql.PreparedStatement |
chattyPrepare(java.sql.Connection conn,
java.lang.String text)
Prepare a statement and report its sql text.
|
protected java.sql.CallableStatement |
chattyPrepareCall(java.sql.Connection conn,
java.lang.String text)
Prepare a callable statement and report its sql text.
|
protected void |
checkAllConsistency(java.sql.Connection conn)
Check consistency of all tables
|
static void |
checkEstimatedRowCount(java.sql.Connection conn,
double expectedCount)
Return estimated row count for runtime statistics.
|
void |
closeStatement(java.sql.Statement s)
Close a statement and remove it from the list of statements to close
at tearDown().
|
void |
commit()
Utility method to commit using the connection
returned by getConnection.
|
java.sql.Statement |
createStatement()
Utility method to create a Statement using the connection
returned by getConnection.
|
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
Utility method to create a Statement using the connection
returned by getConnection.
|
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a Statement using the connection
returned by getConnection.
|
static void |
dropTable(java.sql.Connection conn,
java.lang.String tableName)
Execute a DROP TABLE command using the passed in tableName as-is.
|
void |
dropTable(java.lang.String tableName)
Execute a DROP TABLE command using the passed in tableName as-is
and the default connection.
|
static void |
dropView(java.sql.Connection conn,
java.lang.String viewName)
Execute a DROP VIEW command using the passed in viewName as-is.
|
void |
dropView(java.lang.String viewName)
Execute a DROP VIEW command using the passed in viewName as-is
and the default connection.
|
static void |
dumpRs(java.sql.ResultSet s) |
protected static void |
dumpRs(java.sql.ResultSet s,
java.io.PrintStream out) |
protected void |
emptyStatementCache()
Clear the contents of the statement cache.
|
protected static java.sql.ResultSet |
executeQuery(java.sql.Statement stmt,
java.lang.String text) |
protected void |
expectCompilationError(java.sql.Connection conn,
java.lang.String sqlState,
java.lang.String query)
Assert that the statement text, when compiled, raises an exception
|
protected void |
expectCompilationError(java.lang.String sqlState,
java.lang.String query)
Assert that the statement text, when compiled, raises an exception
|
protected void |
expectExecutionError(java.sql.Connection conn,
java.lang.String sqlState,
java.lang.String query)
Assert that the statement text, when executed, raises an error.
|
private static void |
fetchAndDiscardAllResults(java.sql.Statement st,
boolean haveRS)
Take the received Statement--on which a query has been
executed--and fetch all rows of all result sets (if any)
returned from execution.
|
static int |
getClientTransactionID(java.sql.Connection conn)
Attempts to obtain the client-side transaction counter from the given
connection, which is internal state information.
|
java.sql.Connection |
getConnection()
Obtain the connection to the default database.
|
java.lang.String |
getDatabaseProperty(java.lang.String propertyName)
Get the value of a database property using the default connection
|
private static java.lang.Object |
getLanguageConnectionContext(java.sql.Connection conn)
Gets the LanguageConnectionContext for this connection.
|
java.sql.SQLException |
getLastSQLException(java.sql.SQLException sqle)
Get the last SQLException in chain.
|
protected void |
goodStatement(java.sql.Connection conn,
java.lang.String command)
Run good DDL.
|
protected void |
goodUpdate(java.sql.Connection conn,
java.lang.String update,
int expectedRowCount)
Run a good update statement with an expected row count.
|
protected void |
initializeConnection(java.sql.Connection conn)
Allow a sub-class to initialize a connection to provide
consistent connection state for its tests.
|
java.sql.Connection |
openConnection(java.lang.String databaseName)
Open a connection to the specified database.
|
java.sql.Connection |
openDefaultConnection()
Open a connection to the default database.
|
java.sql.Connection |
openDefaultConnection(java.lang.String user,
java.lang.String password)
Open a connection to the current default database using the
specified user name and password.
|
java.sql.Connection |
openDefaultConnection(TestConfiguration tc)
Open a connection to the default database for the given configuration.
|
java.sql.Connection |
openUserConnection(java.lang.String user)
Open a connection to the current default database using the
specified user name.
|
java.sql.CallableStatement |
prepareCall(java.lang.String sql)
Utility method to create a CallableStatement using the connection
returned by getConnection.
|
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
Utility method to create a CallableStatement using the connection
returned by getConnection.
|
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a CallableStatement using the connection
returned by getConnection.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql)
Utility method to create a PreparedStatement using the connection
returned by getConnection.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
Utility method to create a PreparedStatement using the connection
returned by getConnection and a flag that signals the driver whether
the auto-generated keys produced by this Statement object should be
made available for retrieval.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes)
Utility method to create a PreparedStatement using the connection
returned by getConnection and an array of column indexes that
indicates which auto-generated keys produced by this Statement
object should be made available for retrieval.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
Utility method to create a PreparedStatement using the connection
returned by getConnection with result set type and concurrency.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a PreparedStatement using the connection
returned by getConnection with result set type and concurrency.
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames)
Utility method to create a PreparedStatement using the connection
returned by getConnection and an array of column names that
indicates which auto-generated keys produced by this Statement
object should be made available for retrieval.
|
void |
rollback()
Utility method to rollback using the connection
returned by getConnection.
|
void |
runBare()
Run the bare test, including
setUp() and tearDown() ,
and finally verify that the cached connection has been released. |
protected void |
runBareOverridable()
Run the bare test, including
setUp() and tearDown() . |
int |
runScript(java.io.InputStream script,
java.lang.String encoding)
Run a SQL script through ij discarding the output
using this object's default connection.
|
int |
runScript(java.lang.String resource,
java.lang.String encoding)
Run a SQL script through ij discarding the output
using this object's default connection.
|
int |
runSQLCommands(java.lang.String sqlCommands)
Run a set of SQL commands from a String discarding the output.
|
void |
setAutoCommit(boolean commit)
Utility method to set auto commit behaviour.
|
protected void |
tearDown()
Tear down this fixture, sub-classes should call
super.tearDown().
|
static boolean |
usingDB2Client()
Tell if the client is DB2Client.
|
static boolean |
usingDerbyNetClient()
Tell if the client is DerbyNetClient.
|
static boolean |
usingEmbedded()
Tell if the client is embedded.
|
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, toString
private static final boolean ORDERED
private static final boolean UNORDERED
private java.sql.Connection conn
getConnection()
private java.util.List<java.sql.Statement> statements
private java.util.List<java.sql.Connection> connections
public BaseJDBCTestCase(java.lang.String name)
name
- of the test case.public java.sql.Connection getConnection() throws java.sql.SQLException
The tearDown method will close the connection if
it is open.
The connection will be initialized by calling initializeConnection.
A sub-class may provide an implementation of initializeConnection
to ensure its connections are in a consistent state that is different
to the default.
java.sql.SQLException
openDefaultConnection()
protected void initializeConnection(java.sql.Connection conn) throws java.sql.SQLException
conn
- Connection to be intializedjava.sql.SQLException
- Error setting the initial state.public java.sql.Statement createStatement() throws java.sql.SQLException
java.sql.SQLException
private void addStatement(java.sql.Statement s)
private void addConnection(java.sql.Connection c)
c
- public void closeStatement(java.sql.Statement s) throws java.sql.SQLException
s
- the statement to close and forgetjava.sql.SQLException
- if closing the statement failspublic java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
java.sql.SQLException
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
java.sql.SQLException
public void setAutoCommit(boolean commit) throws java.sql.SQLException
commit
- false if autoCommit should be disabled.java.sql.SQLException
public void commit() throws java.sql.SQLException
java.sql.SQLException
public void rollback() throws java.sql.SQLException
java.sql.SQLException
protected void runBareOverridable() throws java.lang.Throwable
Run the bare test, including setUp()
and tearDown()
.
Subclasses that want to override runBare()
, should override
this method instead. Overriding this method shouldn't be necessary
except in very special cases. Override setUp()
and
tearDown()
instead if possible.
The overridden method would typically want to call
super.runBareOverridable()
to actually run the test.
java.lang.Throwable
public final void runBare() throws java.lang.Throwable
Run the bare test, including setUp()
and tearDown()
,
and finally verify that the cached connection has been released.
This method is final to prevent subclasses from accidentally bypassing
the assert that checks if the cached connection has been released.
Subclasses that want to override the method, should override
runBareOverridable()
instead.
runBare
in class BaseTestCase
java.lang.Throwable
protected void tearDown() throws java.lang.Exception
tearDown
in class junit.framework.TestCase
java.lang.Exception
public java.sql.Connection openDefaultConnection() throws java.sql.SQLException
java.sql.SQLException
TestConfiguration.openDefaultConnection()
,
initializeConnection(Connection)
public java.sql.Connection openDefaultConnection(TestConfiguration tc) throws java.sql.SQLException
tc
- test configuration to usejava.sql.SQLException
TestConfiguration.openDefaultConnection()
,
initializeConnection(Connection)
public java.sql.Connection openDefaultConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
java.sql.SQLException
initializeConnection(Connection)
public java.sql.Connection openUserConnection(java.lang.String user) throws java.sql.SQLException
java.sql.SQLException
DatabasePropertyTestSetup.builtinAuthentication(Test, String[], String)
,
TestConfiguration.sqlAuthorizationDecorator(Test, String[], String)
,
initializeConnection(Connection)
public java.sql.Connection openConnection(java.lang.String databaseName) throws java.sql.SQLException
java.sql.SQLException
TestConfiguration.additionalDatabaseDecorator(Test, String)
,
initializeConnection(Connection)
public int runScript(java.io.InputStream script, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.sql.SQLException
java.io.UnsupportedEncodingException
java.sql.SQLException
public int runScript(java.lang.String resource, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.sql.SQLException, java.security.PrivilegedActionException, java.io.IOException
java.io.UnsupportedEncodingException
java.security.PrivilegedActionException
java.sql.SQLException
java.io.IOException
public int runSQLCommands(java.lang.String sqlCommands) throws java.io.UnsupportedEncodingException, java.sql.SQLException
sqlCommands
- java.io.UnsupportedEncodingException
java.sql.SQLException
public static boolean usingEmbedded()
true
if using the embedded client
false
otherwise.public static boolean usingDerbyNetClient()
true
if using the DerbyNetClient client
false
otherwise.public static boolean usingDB2Client()
true
if using the DB2 client driver,
false
otherwise.public java.lang.String getDatabaseProperty(java.lang.String propertyName) throws java.sql.SQLException
propertyName
- Property keyjava.sql.SQLException
public static void assertEquals(java.sql.Blob b1, java.sql.Blob b2) throws java.io.IOException, java.sql.SQLException
Blob
objects.
If both input references are null
, they are considered
equal. The same is true if both blobs have null
-streams.b1
- first Blob
.b2
- second Blob
.junit.framework.AssertionFailedError
- if blobs are not equal.java.io.IOException
- if reading or closing a stream failsjava.sql.SQLException
- if obtaining a stream failspublic static void assertEquals(java.sql.Clob c1, java.sql.Clob c2) throws java.io.IOException, java.sql.SQLException
Clob
objects.
If both input references are null
, they are considered
equal. The same is true if both clobs have null
-streams.c1
- first Clob
.c2
- second Clob
.junit.framework.AssertionFailedError
- if clobs are not equal.java.io.IOException
- if reading or closing a stream failsjava.sql.SQLException
- if obtaining a stream failspublic static void assertEquals(java.lang.String msg, java.sql.Time t1, java.sql.Time t2)
java.sql.Time
objects.
If both input references are null
, they are considered
equal.msg
- String with message to supply with AssertionFailedErrort1
- first java.sql.Time object.t2
- second java.sql.Time object.junit.framework.AssertionFailedError
- if Time objects are not equal.public static void assertSQLState(java.lang.String message, java.lang.String expected, java.sql.SQLException exception)
message
- message to print on failure.expected
- the expected SQLState.exception
- the exception to check the SQLState of.public static void assertWarning(java.sql.Connection conn, java.lang.String expected) throws java.sql.SQLException
conn
- the connectionexpected
- the expected SQLState of the warningjava.sql.SQLException
public static void assertSQLState(java.lang.String expected, java.sql.SQLException exception)
expected
- the expected SQLState.exception
- the exception to check the SQLState of.public static void assertErrorCode(int expected, java.sql.SQLException exception)
expected
- the expected error codeexception
- the exception to checkjunit.framework.AssertionFailedError
- if the error code is wrongpublic void assertCompileError(java.lang.String sqlState, java.lang.String sql)
sqlState
- expected sql state.sql
- the SQL to compile.public void assertCheckTable(java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
protected void assertTableRowCount(java.lang.String table, int rowCount) throws java.sql.SQLException
table
- Name of table in current schema, will be quotedrowCount
- Number of rows expected in the tablejava.sql.SQLException
- Error accessing the database.private void assertEscapedTableRowCount(java.lang.String escapedTableName, int rowCount) throws java.sql.SQLException
escapedTableName
- Escaped name of table, will be used as-is.rowCount
- Number of rows expected in the tablejava.sql.SQLException
- Error accessing the database.protected final void emptyStatementCache() throws java.sql.SQLException
java.sql.SQLException
- if a database error happenspublic final void dropTable(java.lang.String tableName) throws java.sql.SQLException
tableName
- Table to be dropped.java.sql.SQLException
public static void dropTable(java.sql.Connection conn, java.lang.String tableName) throws java.sql.SQLException
conn
- Connection to execute the DROP TABLEtableName
- Table to be dropped.java.sql.SQLException
public final void dropView(java.lang.String viewName) throws java.sql.SQLException
viewName
- Table to be dropped.java.sql.SQLException
public static void dropView(java.sql.Connection conn, java.lang.String viewName) throws java.sql.SQLException
conn
- Connection to execute the DROP VIEWviewName
- Table to be dropped.java.sql.SQLException
public static void assertStatementError(java.lang.String[] sqlStates, java.sql.Statement st, java.lang.String query)
sqlStates
- expected sql states.st
- Statement object on which to execute.query
- the query to compile and execute.public static void assertStatementErrorUnordered(java.lang.String[] sqlStates, java.sql.Statement st, java.lang.String query)
sqlStates
- expected sql states.st
- Statement object on which to execute.query
- the query to compile and execute.private static void assertStatementErrorMinion(java.lang.String[] sqlStates, boolean orderedStates, java.sql.Statement st, java.lang.String query)
SQLException
with the
expected (chained) states.sqlStates
- the expected statesorderedStates
- whether or not the states are expected in the
specified order or notst
- the statement used to execute the queryquery
- the query to executepublic static void assertStatementError(java.lang.String sqlState, java.sql.Statement st, java.lang.String query)
sqlState
- Expected SQLState of exceptionst
- query
- assertStatementError(String[], Statement, String)
public static void assertCommitError(java.lang.String sqlState, java.sql.Connection c)
sqlState
- statec
- the connectionpublic static void assertStatementError(java.lang.String sqlState, int errorCode, java.sql.Statement st, java.lang.String query)
sqlState
- expected sql state.errorCode
- expected error code.st
- Statement object on which to execute.query
- the query to compile and execute.public static void assertPreparedStatementError(java.lang.String sqlState, java.sql.PreparedStatement ps)
sqlState
- expected sql state.ps
- PreparedStatement query object to execute.public static void assertStatementError(java.lang.String sqlState, java.sql.PreparedStatement pSt)
sqlState
- expected sql state.pSt
- A PreparedStatement or CallableStatement on
which to call "execute()".public void assertCallError(java.lang.String expectedSE, java.lang.String callSQL) throws java.sql.SQLException
expectedSE
- The expected SQL exceptioncallSQL
- The SQL to executejava.sql.SQLException
public static void assertNextError(java.lang.String sqlState, java.sql.ResultSet rs)
sqlState
- Expected SQLStaters
- ResultSet upon which next() will be calledpublic static void assertGetIntError(int position, java.lang.String sqlState, java.sql.ResultSet rs)
position
- position argument to pass to getIntsqlState
- sqlState of expected errorrs
- ResultSet upon which to call getInt(position)public static void assertUpdateCount(java.sql.Statement st, int expectedRC, java.lang.String sql) throws java.sql.SQLException
st
- Statement object on which to execute.expectedRC
- Expected row count.sql
- SQL to execute.java.sql.SQLException
public static void assertUpdateCount(java.sql.PreparedStatement pSt, int expectedRC) throws java.sql.SQLException
pSt
- The PreparedStatement on which to execute.expectedRC
- The expected row count.java.sql.SQLException
public java.sql.SQLException getLastSQLException(java.sql.SQLException sqle)
sqle
- SQLException
private static void fetchAndDiscardAllResults(java.sql.Statement st, boolean haveRS) throws java.sql.SQLException
st
- An already-executed statement from which
we get the result set to process (if there is one).haveRS
- Whether or not the the statement's
first result is a result set (as opposed to an
update count).java.sql.SQLException
public static void assertSQLExceptionEquals(java.sql.SQLException se1, java.sql.SQLException se2)
se1
- first SQLException to comparese2
- second SQLException to comparepublic static void assertEquivalentDataType(int expectedType, int type)
expectedType
- Expected jdbctype from java.sql.Typestype
- Actual type from metadatapublic static int getClientTransactionID(java.sql.Connection conn) throws java.sql.SQLException
NOTE: Use with care, accesses internal state.
conn
- the connectionjava.sql.SQLException
- if the given connection is an embedded connection,
or if invoking the required method failspublic static void checkEstimatedRowCount(java.sql.Connection conn, double expectedCount) throws java.sql.SQLException
conn
- expectedCount
- java.sql.SQLException
protected void checkAllConsistency(java.sql.Connection conn) throws java.sql.SQLException
conn
- java.sql.SQLException
protected static void dumpRs(java.sql.ResultSet s, java.io.PrintStream out) throws java.sql.SQLException
java.sql.SQLException
public static void dumpRs(java.sql.ResultSet s) throws java.sql.SQLException
java.sql.SQLException
protected void goodStatement(java.sql.Connection conn, java.lang.String command) throws java.sql.SQLException
java.sql.SQLException
protected void goodUpdate(java.sql.Connection conn, java.lang.String update, int expectedRowCount) throws java.sql.SQLException
java.sql.SQLException
protected void assertResults(java.sql.Connection conn, java.lang.String query, java.lang.String[][] rows, boolean trimResults) throws java.sql.SQLException
java.sql.SQLException
protected void assertResults(java.sql.ResultSet rs, java.lang.String[][] rows, boolean trimResults) throws java.sql.SQLException
java.sql.SQLException
protected static java.sql.ResultSet executeQuery(java.sql.Statement stmt, java.lang.String text) throws java.sql.SQLException
java.sql.SQLException
protected java.sql.PreparedStatement chattyPrepare(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
java.sql.SQLException
protected java.sql.CallableStatement chattyPrepareCall(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
java.sql.SQLException
protected void expectCompilationError(java.lang.String sqlState, java.lang.String query)
protected void expectCompilationError(java.sql.Connection conn, java.lang.String sqlState, java.lang.String query)
protected void expectExecutionError(java.sql.Connection conn, java.lang.String sqlState, java.lang.String query) throws java.lang.Exception
java.lang.Exception
private static java.lang.Object getLanguageConnectionContext(java.sql.Connection conn)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.