use of liquibase.exception.MigrationFailedException in project liquibase by liquibase.
the class UpdateVisitor method visit.
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (!(executor instanceof LoggingExecutor)) {
Scope.getCurrentScope().getUI().sendMessage("Running Changeset: " + changeSet);
}
ChangeSet.RunStatus runStatus = this.database.getRunStatus(changeSet);
Scope.getCurrentScope().getLog(getClass()).fine("Running Changeset: " + changeSet);
fireWillRun(changeSet, databaseChangeLog, database, runStatus);
ExecType execType = null;
ObjectQuotingStrategy previousStr = this.database.getObjectQuotingStrategy();
try {
execType = changeSet.execute(databaseChangeLog, execListener, this.database);
} catch (MigrationFailedException e) {
fireRunFailed(changeSet, databaseChangeLog, database, e);
throw e;
}
if (!runStatus.equals(ChangeSet.RunStatus.NOT_RAN)) {
execType = ChangeSet.ExecType.RERAN;
}
fireRan(changeSet, databaseChangeLog, database, execType);
// reset object quoting strategy after running changeset
this.database.setObjectQuotingStrategy(previousStr);
this.database.markChangeSetExecStatus(changeSet, execType);
this.database.commit();
}
use of liquibase.exception.MigrationFailedException in project liquibase by liquibase.
the class PendingSQLWriter method writeBody.
@Override
protected void writeBody(Writer fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
Executor oldTemplate = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
LoggingExecutor loggingExecutor = new LoggingExecutor(oldTemplate, fileWriter, database);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("logging", database, loggingExecutor);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, loggingExecutor);
try {
if (changesToRun.isEmpty()) {
fileWriter.append("<b>NONE</b>");
}
fileWriter.append("<code><pre>");
ChangeSet lastRunChangeSet = null;
for (Change change : changesToRun) {
ChangeSet thisChangeSet = change.getChangeSet();
if (thisChangeSet.equals(lastRunChangeSet)) {
continue;
}
lastRunChangeSet = thisChangeSet;
String anchor = thisChangeSet.toString(false).replaceAll("\\W", "_");
fileWriter.append("<a name='").append(anchor).append("'/>");
try {
thisChangeSet.execute(databaseChangeLog, null, this.database);
} catch (MigrationFailedException e) {
fileWriter.append("EXECUTION ERROR: ").append(Scope.getCurrentScope().getSingleton(ChangeFactory.class).getChangeMetaData(change).getDescription()).append(": ").append(e.getMessage()).append("\n\n");
}
}
fileWriter.append("</pre></code>");
} finally {
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, oldTemplate);
}
}
use of liquibase.exception.MigrationFailedException in project liquibase by liquibase.
the class DatabaseTestTemplate method test.
private void test(DatabaseTest test, Set<Database> databasesToTestOn) throws Exception {
for (Database database : databasesToTestOn) {
if (database instanceof SQLiteDatabase) {
//todo: find how to get tests to run correctly on SQLite
continue;
}
JdbcExecutor writeExecutor = new JdbcExecutor();
writeExecutor.setDatabase(database);
ExecutorService.getInstance().setExecutor(database, writeExecutor);
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.reset();
if (database.getConnection() != null) {
lockService.forceReleaseLock();
}
try {
test.performTest(database);
} catch (ComparisonFailure e) {
String newMessage = "Database Test Failure on " + database;
if (e.getMessage() != null) {
newMessage += ": " + e.getMessage();
}
ComparisonFailure newError = new ComparisonFailure(newMessage, e.getExpected(), e.getActual());
newError.setStackTrace(e.getStackTrace());
throw newError;
} catch (AssertionError e) {
e.printStackTrace();
String newMessage = "Database Test Failure on " + database;
if (e.getMessage() != null) {
newMessage += ": " + e.getMessage();
}
AssertionError newError = new AssertionError(newMessage);
newError.setStackTrace(e.getStackTrace());
throw newError;
} catch (MigrationFailedException e) {
e.printStackTrace();
String newMessage = "Database Test Failure on " + database;
if (e.getMessage() != null) {
newMessage += ": " + e.getMessage();
}
AssertionError newError = new AssertionError(newMessage);
newError.setStackTrace(e.getStackTrace());
throw newError;
} catch (Exception e) {
e.printStackTrace();
String newMessage = "Database Test Exception on " + database;
if (e.getMessage() != null) {
newMessage += ": " + e.getMessage();
}
Exception newError = e.getClass().getConstructor(String.class).newInstance(newMessage);
if (e.getCause() == null) {
newError.setStackTrace(e.getStackTrace());
} else {
newError.setStackTrace(e.getCause().getStackTrace());
}
throw newError;
} finally {
if (database.getConnection() != null && !database.getAutoCommitMode()) {
database.rollback();
}
}
}
}
Aggregations