public class StatementEventsTest extends BaseJDBCTestCase
Modifier and Type | Class and Description |
---|---|
private static class |
StatementEventsTest.SimpleListener
A simple
StatementEventListener that counts the number of
times it has been triggered. |
private static class |
StatementEventsTest.Suite
Test suite class which contains all test cases in
StatementEventsTest for a given configuration. |
Modifier and Type | Field and Description |
---|---|
private boolean |
callable
Type of statement to use.
|
private int |
closedCount
Number of times statementClosed events have been raised.
|
private java.sql.Statement |
closedStatement
The statement that caused the last statementClosed event.
|
private java.sql.Connection |
connection
The connection object to use in the test.
|
private int |
errorCount
Number of times statementError events have been raised.
|
private java.sql.Statement |
errorStatement
The statement that caused the last statementError event.
|
private javax.sql.PooledConnection |
pooledConnection
The pooled connection to use in the test (could also be an XA
connection).
|
private boolean |
xa
Type of data source to use.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
StatementEventsTest(java.lang.String name)
Create a test with the given name.
|
Modifier and Type | Method and Description |
---|---|
private static junit.framework.Test |
baseSuite(java.lang.String name)
Return suite with all tests of the class for all combinations of
pooled/xa connection and prepared/callable statement.
|
java.lang.String |
getName()
Return the name of the test.
|
private java.sql.PreparedStatement |
prepare(java.lang.String sql)
Prepare a statement.
|
private void |
setCallable(boolean callable)
Set whether the test should use
CallableStatement or
PreparedStatement . |
void |
setUp()
Set up the connection to the database and register a statement event
listener.
|
private void |
setXA(boolean xa)
Set whether the test should use
XADataSource or
ConnectionPoolDataSource . |
static junit.framework.Test |
suite()
Create a test suite with all tests in the class.
|
protected void |
tearDown()
Free resources used in the test.
|
void |
testAddListenerFromListener()
Test that adding a listener from a listener works.
|
void |
testAddNullListener()
Test that you don't get a NullPointerException when the listeners are
triggered and one of them is null.
|
void |
testAddRemoveListenerOnClosedObject()
Test how
addStatementEventListener() and
removeStatementEventListener() behave when they are called
on a closed PooledConnection or XAConnection . |
void |
testCloseEvent()
Test that a close event is raised when a statement is closed.
|
void |
testCloseEventOnClosedConnection()
Test whether a close event is raised when a connection is
closed.
|
void |
testDoubleAddListener()
Test how the listener behaves if it is added twice.
|
void |
testErrorEventOnClosedConnection()
Test that an error event is raised when
execute() fails
because the connection is closed. |
void |
testRemoveListenerFromListener()
Test that removing a listener from a listener works.
|
void |
testRemoveListenerNotAddedFirst()
Test that removing a listener that hasn't been added first, doesn't
cause any errors.
|
void |
testRemoveNullListener()
Test that you can call
removeStatementEventListener() with a
null argument. |
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
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, run, run, runTest, setName, toString
private boolean xa
true
, use
XADataSource
; otherwise, use
ConnectionPoolDataSource
.private boolean callable
true
, use
CallableStatement
; otherwise, use
PreparedStatement
.private java.sql.Statement closedStatement
private int closedCount
private java.sql.Statement errorStatement
private int errorCount
private javax.sql.PooledConnection pooledConnection
private java.sql.Connection connection
public StatementEventsTest(java.lang.String name)
name
- name of the test.private void setXA(boolean xa)
XADataSource
or
ConnectionPoolDataSource
.xa
- if true
, use XAprivate void setCallable(boolean callable)
CallableStatement
or
PreparedStatement
.callable
- if true
, use callable statement; otherwise,
use prepared statementpublic java.lang.String getName()
getName
in class junit.framework.TestCase
public void setUp() throws java.sql.SQLException
setUp
in class junit.framework.TestCase
java.sql.SQLException
- if a database error occursprotected void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestCase
java.lang.Exception
- if an error occursprivate static junit.framework.Test baseSuite(java.lang.String name)
name
- name of the test suitepublic static junit.framework.Test suite()
private java.sql.PreparedStatement prepare(java.lang.String sql) throws java.sql.SQLException
sql
- SQL textPreparedStatement
or
CallableStatement
objectjava.sql.SQLException
- if a database error occurspublic void testCloseEvent() throws java.sql.SQLException
java.sql.SQLException
- if a database error occurspublic void testAddNullListener() throws java.sql.SQLException
java.sql.SQLException
public void testRemoveNullListener() throws java.sql.SQLException
removeStatementEventListener()
with a
null
argument.java.sql.SQLException
public void testDoubleAddListener() throws java.sql.SQLException
java.sql.SQLException
public void testCloseEventOnClosedConnection() throws java.sql.SQLException
close()
on its statements. Embedded should not raise a
close event since the connection does not call close()
on
its statements.)java.sql.SQLException
- if a database error occurspublic void testErrorEventOnClosedConnection() throws java.sql.SQLException
execute()
fails
because the connection is closed.java.sql.SQLException
- if a database error occurspublic void testRemoveListenerFromListener() throws java.sql.SQLException
java.sql.SQLException
public void testAddListenerFromListener() throws java.sql.SQLException
java.sql.SQLException
public void testAddRemoveListenerOnClosedObject() throws java.sql.SQLException
addStatementEventListener()
and
removeStatementEventListener()
behave when they are called
on a closed PooledConnection
or XAConnection
.java.sql.SQLException
public void testRemoveListenerNotAddedFirst() throws java.sql.SQLException
java.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.