use of liquibase.executor.LoggingExecutor 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 = ExecutorService.getInstance().getExecutor(database);
LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), fileWriter, database);
ExecutorService.getInstance().setExecutor(database, loggingExecutor);
try {
if (changesToRun.size() == 0) {
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(ChangeFactory.getInstance().getChangeMetaData(change).getDescription()).append(": ").append(e.getMessage()).append("\n\n");
}
}
fileWriter.append("</pre></code>");
} finally {
ExecutorService.getInstance().setExecutor(database, oldTemplate);
}
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class OfflineChangeLogHistoryServiceTest method createService.
/**
* Create OfflineChangeLogHistoryService and register LoggingExecutor
*/
private OfflineChangeLogHistoryService createService(Writer writer, String outputLiquibaseSql) {
HsqlDatabase database = new HsqlDatabase();
File changeLogCsvFile = new File(temporaryFolder.getRoot(), "changeLog.csv");
OfflineConnection connection = new OfflineConnection("offline:hsqldb?changeLogFile=" + changeLogCsvFile.getAbsolutePath() + "&outputLiquibaseSql=" + outputLiquibaseSql, new ClassLoaderResourceAccessor());
database.setConnection(connection);
connection.attached(database);
OfflineChangeLogHistoryService changeLogHistoryService = (OfflineChangeLogHistoryService) ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database);
LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), writer, database);
ExecutorService.getInstance().setExecutor(database, loggingExecutor);
return changeLogHistoryService;
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method update.
public void update(int changesToApply, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
ExecutorService.getInstance().setExecutor(database, loggingExecutor);
outputHeader("Update " + changesToApply + " Change Sets Database Script");
update(changesToApply, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
resetServices();
ExecutorService.getInstance().setExecutor(database, oldTemplate);
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method rollback.
public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database));
outputHeader("Rollback " + changesToRollback + " Change(s) Script");
rollback(changesToRollback, rollbackScript, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method rollback.
public void rollback(Date dateToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database));
outputHeader("Rollback to " + dateToRollBackTo + " Script");
rollback(dateToRollBackTo, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
Aggregations