use of liquibase.Liquibase in project cals-api by ca-cwds.
the class DatabaseHelper method runScript.
public void runScript(String script, Map<String, Object> parameters, String schema) throws LiquibaseException {
try {
String defaultSchema = getDatabase().getDefaultSchemaName();
getDatabase().setDefaultSchemaName(schema);
Liquibase liquibase = new Liquibase(script, new ClassLoaderResourceAccessor(), getDatabase());
parameters.forEach(liquibase::setChangeLogParameter);
liquibase.update((String) null);
getDatabase().setDefaultSchemaName(defaultSchema);
} catch (Exception e) {
throw new LiquibaseException(e);
}
}
use of liquibase.Liquibase in project dropwizard by dropwizard.
the class DbLocksCommandTest method testFailsWhenNoListOrRelease.
@Test
void testFailsWhenNoListOrRelease() {
final Liquibase liquibase = Mockito.mock(Liquibase.class);
assertThatIllegalArgumentException().isThrownBy(() -> locksCommand.run(new Namespace(Maps.of("list", false, "release", false)), liquibase)).withMessage("Must specify either --list or --force-release");
}
use of liquibase.Liquibase in project dropwizard by dropwizard.
the class DbLocksCommandTest method testFailsWhenBothListAndRelease.
@Test
void testFailsWhenBothListAndRelease() {
final Liquibase liquibase = Mockito.mock(Liquibase.class);
assertThatIllegalArgumentException().isThrownBy(() -> locksCommand.run(new Namespace(Maps.of("list", true, "release", true)), liquibase)).withMessage("Must specify either --list or --force-release");
}
use of liquibase.Liquibase in project liquibase by liquibase.
the class ChangeLogSyncTask 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.Liquibase in project liquibase by liquibase.
the class DropAllTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
try {
if (StringUtil.trimToNull(schemas) != null) {
List<String> schemaNames = StringUtil.splitAndTrim(this.schemas, ",");
List<CatalogAndSchema> schemas = new ArrayList<>();
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.getMessage(), e);
}
}
Aggregations