public class CleanDatabaseTestSetup extends BaseJDBCTestSetup
Tests can extend to provide a decorator that defines
some schema items and then have CleanDatabaseTestSetup
automatically clean them up by implementing the decorateSQL method..
As an example:
return new CleanDatabaseTestSetup(suite) {
protected void decorateSQL(Statement s) throws SQLException {
s.execute("CREATE TABLE T (I INT)");
s.execute("CREATE INDEX TI ON T(I)")
}
};
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
CLEAR_DB_PROPERTIES
Set of database properties that will be set to NULL (unset)
as part of cleaning a database.
|
private static java.lang.String[] |
COMPRESS_DB_OBJECTS
Set of objects that will be compressed as part of cleaning a database.
|
private java.lang.String |
hostName |
private JDBCClient |
jdbcClient |
private int |
portNo |
Constructor and Description |
---|
CleanDatabaseTestSetup(junit.framework.Test test)
Decorator this test with the cleaner
|
CleanDatabaseTestSetup(junit.framework.Test test,
boolean useNetworkClient,
java.lang.String hostName,
int portNo)
Constructor to use when running in a client / server
with the server already started on a given host
and port.
|
Modifier and Type | Method and Description |
---|---|
static void |
cleanDatabase(java.sql.Connection conn,
boolean compress)
Clean a complete database
|
private static void |
clearProperties(java.sql.Connection conn)
Clear all database properties.
|
private static void |
compressObjects(java.sql.Connection conn)
Compress the objects in the database.
|
protected void |
decorateSQL(java.sql.Statement s)
Sub-classes can override this method to execute
SQL statements executed at setUp time once the
database has been cleaned.
|
private static void |
removeObjects(java.sql.Connection conn)
Remove all objects in all schemas from the database.
|
private static void |
removeRoles(java.sql.Connection conn) |
private static void |
removeUsers(java.sql.Connection conn)
Drop all credentials stored in SYSUSERS
|
protected void |
setUp()
Clean the default database using the default connection
and calls the decorateSQL to allow sub-classes to
initialize their schema requirments.
|
protected void |
tearDown()
Clean the default database using the default connection.
|
clearConnection, getConnection, getTestConfiguration, println
run
basicRun, countTestCases, getTest, toString
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, fail, fail, failNotEquals, failNotSame, failSame, format
private JDBCClient jdbcClient
private java.lang.String hostName
private int portNo
private static final java.lang.String[] CLEAR_DB_PROPERTIES
private static final java.lang.String[] COMPRESS_DB_OBJECTS
public CleanDatabaseTestSetup(junit.framework.Test test)
public CleanDatabaseTestSetup(junit.framework.Test test, boolean useNetworkClient, java.lang.String hostName, int portNo)
protected void setUp() throws java.lang.Exception
setUp
in class junit.extensions.TestSetup
java.lang.Exception
protected void decorateSQL(java.sql.Statement s) throws java.sql.SQLException
java.sql.SQLException
protected void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestSetup
java.lang.Exception
public static void cleanDatabase(java.sql.Connection conn, boolean compress) throws java.sql.SQLException
conn
- Connection to be used, must not be in auto-commit mode.compress
- True if selected system tables are to be compressed
to avoid potential ordering differences in test output.java.sql.SQLException
- database errorprivate static void clearProperties(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
private static void removeObjects(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
private static void removeRoles(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
private static void removeUsers(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
private static void compressObjects(java.sql.Connection conn) throws java.sql.SQLException
conn
- the db connectionjava.sql.SQLException
- database errorApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.