use of liquibase.Contexts in project liquibase by liquibase.
the class ChangeLogSyncToTagTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
OutputStreamWriter writer = null;
try {
FileResource outputFile = getOutputFile();
if (outputFile != null) {
writer = new OutputStreamWriter(outputFile.getOutputStream(), getOutputEncoding());
liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels());
}
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate sync SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate sync SQL. Error creating output writer.", e);
} catch (LiquibaseException e) {
throw new BuildException("Unable to sync change log: " + e.getMessage(), e);
} finally {
FileUtils.close(writer);
}
}
use of liquibase.Contexts in project liquibase by liquibase.
the class DatabaseRollbackTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Writer writer = null;
Liquibase liquibase = getLiquibase();
try {
FileResource outputFile = getOutputFile();
if (rollbackCount != null) {
if (outputFile != null) {
writer = getOutputFileWriter();
liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels());
}
} else if (rollbackTag != null) {
if (outputFile != null) {
writer = getOutputFileWriter();
liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels());
}
} else if (rollbackDate != null) {
if (outputFile != null) {
writer = getOutputFileWriter();
liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels());
}
} else {
throw new BuildException("Unable to rollback database. No count, tag, or date set.");
}
} catch (LiquibaseException e) {
throw new BuildException("Unable to rollback database: " + e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate rollback SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate rollback SQL. Error creating output writer.", e);
} finally {
FileUtils.close(writer);
}
}
use of liquibase.Contexts in project liquibase by liquibase.
the class DatabaseUpdateTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Writer writer = null;
Liquibase liquibase = getLiquibase();
try {
FileResource outputFile = getOutputFile();
if (outputFile != null) {
writer = getOutputFileWriter();
liquibase.update(toTag, new Contexts(getContexts()), getLabels(), writer);
} else {
if (dropFirst) {
liquibase.dropAll();
}
liquibase.update(toTag, new Contexts(getContexts()), getLabels());
}
} catch (LiquibaseException e) {
throw new BuildException("Unable to update database: " + e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate update SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate update SQL. Error creating output writer.", e);
} finally {
FileUtils.close(writer);
}
}
use of liquibase.Contexts in project liquibase by liquibase.
the class LiquibaseChangeLogSyncMojo method performLiquibaseTask.
@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
super.performLiquibaseTask(liquibase);
liquibase.changeLogSync(new Contexts(contexts), new LabelExpression(labels));
}
use of liquibase.Contexts in project liquibase by liquibase.
the class ChangeLogParametersTest method setParameterValue_rightDBRightContext.
@Test
public void setParameterValue_rightDBRightContext() {
ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
changeLogParameters.setContexts(new Contexts("junit"));
changeLogParameters.set("doubleSet", "originalValue", "junit", "junitLabel", "baddb, h2", true, null);
assertEquals("originalValue", changeLogParameters.getValue("doubleSet", null));
}
Aggregations