TSK-152 fix problem with drop table if exists
This commit is contained in:
parent
51eba86d8f
commit
429b2327e4
|
@ -11,13 +11,13 @@ import javax.sql.DataSource;
|
|||
import org.apache.ibatis.jdbc.ScriptRunner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pro.taskana.configuration.DbSchemaCreator;
|
||||
|
||||
/**
|
||||
* This class cleans the complete database. Only to be used in Unittest
|
||||
*/
|
||||
public class DBCleaner {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DbSchemaCreator.class);
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DBCleaner.class);
|
||||
private static final String DB_CLEAR_SCRIPT = "/sql/clear-db.sql";
|
||||
private static final String DB_DROP_TABLES_SCRIPT = "/sql/drop-tables.sql";
|
||||
|
||||
|
@ -26,10 +26,11 @@ public class DBCleaner {
|
|||
private StringWriter errorWriter = new StringWriter();
|
||||
private PrintWriter errorLogWriter = new PrintWriter(errorWriter);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the db.
|
||||
* @param dropTables if true drop tables, else clean tables
|
||||
*
|
||||
* @param dropTables
|
||||
* if true drop tables, else clean tables
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clearDb(DataSource dataSource, boolean dropTables) throws SQLException {
|
||||
|
@ -37,7 +38,7 @@ public class DBCleaner {
|
|||
ScriptRunner runner = new ScriptRunner(connection);
|
||||
LOGGER.debug(connection.getMetaData().toString());
|
||||
|
||||
runner.setStopOnError(true);
|
||||
runner.setStopOnError(false);
|
||||
runner.setLogWriter(logWriter);
|
||||
runner.setErrorLogWriter(errorLogWriter);
|
||||
if (dropTables) {
|
||||
|
@ -50,7 +51,9 @@ public class DBCleaner {
|
|||
LOGGER.error("caught Exception " + e);
|
||||
}
|
||||
LOGGER.debug(outWriter.toString());
|
||||
if (!errorWriter.toString().trim().isEmpty()) {
|
||||
String errorMsg = errorWriter.toString().trim();
|
||||
|
||||
if (!errorMsg.isEmpty() && errorMsg.indexOf("SQLCODE=-204, SQLSTATE=42704") == -1) {
|
||||
LOGGER.error(errorWriter.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue