Fix test database use with multiple test classes
This commit is contained in:
parent
efd1d44808
commit
5d859c49d7
@ -59,11 +59,14 @@ public class QueryMapperTest {
|
|||||||
"JOIN boss b ON p.person_no = b.person_no " +
|
"JOIN boss b ON p.person_no = b.person_no " +
|
||||||
"WHERE p.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();
|
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;
|
QueryMapper qm = null;
|
||||||
try {
|
try {
|
||||||
|
conn = getConnection();
|
||||||
qm = new QueryMapper(conn);
|
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 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))");
|
qm.executeUpdate("CREATE TABLE boss (person_no NUMERIC, department VARCHAR(40))");
|
||||||
@ -75,8 +78,15 @@ public class QueryMapperTest {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tryClose(qm);
|
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
|
@BeforeClass
|
||||||
|
Loading…
Reference in New Issue
Block a user