use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class CDILiquibase method performUpdate.
private void performUpdate() throws LiquibaseException {
Connection c = null;
Liquibase liquibase = null;
try {
c = dataSource.getConnection();
liquibase = createLiquibase(c);
liquibase.getDatabase();
liquibase.update(new Contexts(config.getContexts()), new LabelExpression(config.getLabels()));
updateSuccessful = true;
} catch (SQLException e) {
throw new DatabaseException(e);
} catch (LiquibaseException ex) {
updateSuccessful = false;
throw ex;
} finally {
if (liquibase != null && liquibase.getDatabase() != null) {
liquibase.getDatabase().close();
} else if (c != null) {
try {
c.rollback();
c.close();
} catch (SQLException e) {
//nothing to do
}
}
}
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method markNextChangeSetRan.
public void markNextChangeSetRan(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
LoggingExecutor outputTemplate = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, outputTemplate);
outputHeader("SQL to add all changesets to database history table");
markNextChangeSetRan(contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method generateDocumentation.
public void generateDocumentation(String outputDirectory, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
log.info("Generating Database Documentation");
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
try {
DatabaseChangeLog changeLog = getDatabaseChangeLog();
checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database, contexts, labelExpression);
ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new DbmsChangeSetFilter(database));
DBDocVisitor visitor = new DBDocVisitor(database);
logIterator.run(visitor, new RuntimeEnvironment(database, contexts, labelExpression));
visitor.writeHTML(new File(outputDirectory), resourceAccessor);
} catch (IOException e) {
throw new LiquibaseException(e);
} finally {
try {
lockService.releaseLock();
} catch (LockException e) {
log.severe("Could not release lock", e);
}
}
// try {
// if (!LockService.getExecutor(database).waitForLock()) {
// return;
// }
//
// DBDocChangeLogHandler changeLogHandler = new DBDocChangeLogHandler(outputDirectory, this, changeLogFile,resourceAccessor);
// runChangeLogs(changeLogHandler);
//
// changeLogHandler.writeHTML(this);
// } finally {
// releaseLock();
// }
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method rollback.
public void rollback(String tagToRollBackTo, 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 '" + tagToRollBackTo + "' Script");
rollback(tagToRollBackTo, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class MarkChangeSetRanGenerator method generateSql.
@Override
public Sql[] generateSql(MarkChangeSetRanStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String dateValue = database.getCurrentDateTimeFunction();
ChangeSet changeSet = statement.getChangeSet();
SqlStatement runStatement;
try {
if (statement.getExecType().equals(ChangeSet.ExecType.FAILED) || statement.getExecType().equals(ChangeSet.ExecType.SKIPPED)) {
//don't mark
return new Sql[0];
}
String tag = null;
for (Change change : changeSet.getChanges()) {
if (change instanceof TagDatabaseChange) {
TagDatabaseChange tagChange = (TagDatabaseChange) change;
tag = tagChange.getTag();
}
}
if (statement.getExecType().ranBefore) {
runStatement = new UpdateStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()).addNewColumnValue("DATEEXECUTED", new DatabaseFunction(dateValue)).addNewColumnValue("ORDEREXECUTED", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getNextSequenceValue()).addNewColumnValue("MD5SUM", changeSet.generateCheckSum().toString()).addNewColumnValue("EXECTYPE", statement.getExecType().value).addNewColumnValue("DEPLOYMENT_ID", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getDeploymentId()).setWhereClause(database.escapeObjectName("ID", Column.class) + " = ? " + "AND " + database.escapeObjectName("AUTHOR", Column.class) + " = ? " + "AND " + database.escapeObjectName("FILENAME", Column.class) + " = ?").addWhereParameters(changeSet.getId(), changeSet.getAuthor(), changeSet.getFilePath());
if (tag != null) {
((UpdateStatement) runStatement).addNewColumnValue("TAG", tag);
}
} else {
runStatement = new InsertStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()).addColumnValue("ID", changeSet.getId()).addColumnValue("AUTHOR", changeSet.getAuthor()).addColumnValue("FILENAME", changeSet.getFilePath()).addColumnValue("DATEEXECUTED", new DatabaseFunction(dateValue)).addColumnValue("ORDEREXECUTED", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getNextSequenceValue()).addColumnValue("MD5SUM", changeSet.generateCheckSum().toString()).addColumnValue("DESCRIPTION", limitSize(changeSet.getDescription())).addColumnValue("COMMENTS", limitSize(StringUtils.trimToEmpty(changeSet.getComments()))).addColumnValue("EXECTYPE", statement.getExecType().value).addColumnValue("CONTEXTS", changeSet.getContexts() == null || changeSet.getContexts().isEmpty() ? null : changeSet.getContexts().toString()).addColumnValue("LABELS", changeSet.getLabels() == null || changeSet.getLabels().isEmpty() ? null : changeSet.getLabels().toString()).addColumnValue("LIQUIBASE", LiquibaseUtil.getBuildVersion().replaceAll("SNAPSHOT", "SNP")).addColumnValue("DEPLOYMENT_ID", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getDeploymentId());
if (tag != null) {
((InsertStatement) runStatement).addColumnValue("TAG", tag);
}
}
} catch (LiquibaseException e) {
throw new UnexpectedLiquibaseException(e);
}
return SqlGeneratorFactory.getInstance().generateSql(runStatement, database);
}
Aggregations