use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class LiquibaseGenerateChangeLogMojo method performLiquibaseTask.
@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
ClassLoader cl = null;
try {
cl = getClassLoaderIncludingProjectClasspath();
Thread.currentThread().setContextClassLoader(cl);
} catch (MojoExecutionException e) {
throw new LiquibaseException("Could not create the class loader, " + e, e);
}
Database database = liquibase.getDatabase();
getLog().info("Generating Change Log from database " + database.toString());
try {
DiffOutputControl diffOutputControl = new DiffOutputControl(outputDefaultCatalog, outputDefaultSchema, true, null);
if (diffExcludeObjects != null && diffIncludeObjects != null) {
throw new UnexpectedLiquibaseException("Cannot specify both excludeObjects and includeObjects");
}
if (diffExcludeObjects != null) {
diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.EXCLUDE, diffExcludeObjects));
}
if (diffIncludeObjects != null) {
diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.INCLUDE, diffIncludeObjects));
}
CommandLineUtils.doGenerateChangeLog(outputChangeLogFile, database, defaultCatalogName, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataDir), diffOutputControl);
getLog().info("Output written to Change Log file, " + outputChangeLogFile);
} catch (IOException e) {
throw new LiquibaseException(e);
} catch (ParserConfigurationException e) {
throw new LiquibaseException(e);
}
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class DropAllTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
try {
if (StringUtils.trimToNull(schemas) != null) {
List<String> schemaNames = StringUtils.splitAndTrim(this.schemas, ",");
List<CatalogAndSchema> schemas = new ArrayList<CatalogAndSchema>();
for (String name : schemaNames) {
schemas.add(new CatalogAndSchema(catalog, name));
}
liquibase.dropAll(schemas.toArray(new CatalogAndSchema[schemas.size()]));
} else {
liquibase.dropAll();
}
} catch (LiquibaseException e) {
throw new BuildException("Unable to drop all objects from database. " + e.toString(), e);
}
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class MarkNextChangeSetRanTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
Writer writer = null;
try {
FileResource outputFile = getOutputFile();
if (outputFile != null) {
writer = getOutputFileWriter();
liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels());
}
} catch (LiquibaseException e) {
throw new BuildException("Unable to mark next changeset as ran. " + e.toString(), e);
} catch (IOException e) {
throw new BuildException("Unable to mark next changeset as ran. Error creating output writer.", e);
} finally {
FileUtils.close(writer);
}
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method reportUnexpectedChangeSets.
public void reportUnexpectedChangeSets(boolean verbose, Contexts contexts, LabelExpression labelExpression, Writer out) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
try {
Collection<RanChangeSet> unexpectedChangeSets = listUnexpectedChangeSets(contexts, labelExpression);
if (unexpectedChangeSets.size() == 0) {
out.append(getDatabase().getConnection().getConnectionUserName());
out.append("@");
out.append(getDatabase().getConnection().getURL());
out.append(" contains no unexpected changes!");
out.append(StreamUtil.getLineSeparator());
} else {
out.append(String.valueOf(unexpectedChangeSets.size()));
out.append(" unexpected changes were found in ");
out.append(getDatabase().getConnection().getConnectionUserName());
out.append("@");
out.append(getDatabase().getConnection().getURL());
out.append(StreamUtil.getLineSeparator());
if (verbose) {
for (RanChangeSet ranChangeSet : unexpectedChangeSets) {
out.append(" ").append(ranChangeSet.toString()).append(StreamUtil.getLineSeparator());
}
}
}
out.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
}
use of liquibase.exception.LiquibaseException 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);
}
Aggregations