}
}
// populate the db
if (sqlScript != null) {
DataStore ds = null;
Connection conn = null;
Statement st = null;
BufferedReader reader = null;
try {
ds = DataStoreFinder.getDataStore(filters);
if (ds == null) {
final String warning = "Disabling online test based on '" + fixtureId + "', "
+ "could not find a data store compatible "
+ "with the following connection properties: " + filters;
disableTest(warning);
return;
}
if (ds instanceof JDBCDataStore) {
conn = ((JDBCDataStore) ds).getConnection(Transaction.AUTO_COMMIT);
}
// TODO: add a way to extract a connection from the new JDBC
// datastores
if (conn == null) {
final String warning = "Disabling online test based on '" + fixtureId + "', "
+ "could not extract a JDBC connection from the datastore '"
+ ds.getClass() + " obtained using the following "
+ "connection properties: " + filters;
disableTest(warning);
return;
}
// read the script and run the setup commands
reader = new BufferedReader(new FileReader(sqlScript));
st = conn.createStatement();
String command = null;
while ((command = reader.readLine()) != null) {
command = command.trim();
// skip comments and empty lines
if ("".equals(command) || command.startsWith("--") || command.startsWith("#"))
continue;
// execute but do not complain, only log the failures
try {
st.execute(command);
} catch (SQLException e) {
LOGGER.warning("Error executing \"" + command + "\": " + e.getMessage());
}
}
} finally {
JDBCUtils.close(st);
JDBCUtils.close(conn, null, null);
// very important, or we'll leak connection pools during
// execution
if (ds != null)
ds.dispose();
if (reader != null)
reader.close();
}
}