Fix test database use with multiple test classes

This commit is contained in:
Travis Burtrum 2017-05-18 14:59:16 -04:00
parent efd1d44808
commit 5d859c49d7
1 changed files with 25 additions and 15 deletions

View File

@ -59,11 +59,14 @@ public class QueryMapperTest {
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = ?";
public static Connection getConnection() throws Throwable {
static {
// load db once
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
final Connection conn = DriverManager.getConnection("jdbc:derby:memory:derbyDB;create=true");
Connection conn = null;
QueryMapper qm = null;
try {
conn = getConnection();
qm = new QueryMapper(conn);
qm.executeUpdate("CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date TIMESTAMP)");
qm.executeUpdate("CREATE TABLE boss (person_no NUMERIC, department VARCHAR(40))");
@ -75,8 +78,15 @@ public class QueryMapperTest {
}
} finally {
tryClose(qm);
tryClose(conn);
}
return conn;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static Connection getConnection() throws Throwable {
return DriverManager.getConnection("jdbc:derby:memory:derbyDB;create=true");
}
@BeforeClass