use of liquibase.command.CommandResult in project liquibase by liquibase.
the class ConvertCommand method run.
@Override
protected CommandResult run() throws Exception {
List<ResourceAccessor> openers = new ArrayList<ResourceAccessor>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(classpath));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(outFile);
try {
outSerializer.write(changeLog.getChangeSets(), outputStream);
} finally {
outputStream.flush();
outputStream.close();
}
return new CommandResult("Converted successfully");
}
use of liquibase.command.CommandResult in project liquibase by liquibase.
the class DiffCommand method run.
@Override
protected CommandResult run() throws Exception {
DiffResult diffResult = createDiffResult();
new DiffToReport(diffResult, outputStream).print();
return new CommandResult("OK");
}
use of liquibase.command.CommandResult in project liquibase by liquibase.
the class DiffToChangeLogCommand method run.
@Override
protected CommandResult run() throws Exception {
DiffResult diffResult = createDiffResult();
PrintStream outputStream = this.getOutputStream();
if (outputStream == null) {
outputStream = System.out;
}
if (StringUtils.trimToNull(changeLogFile) == null) {
createDiffToChangeLogObject(diffResult).print(outputStream);
} else {
createDiffToChangeLogObject(diffResult).print(changeLogFile);
}
return new CommandResult("OK");
}
use of liquibase.command.CommandResult in project liquibase by liquibase.
the class DropAllCommand method run.
@Override
protected CommandResult run() throws Exception {
try {
LockServiceFactory.getInstance().getLockService(database).waitForLock();
for (CatalogAndSchema schema : schemas) {
log.info("Dropping Database Objects in schema: " + schema);
checkLiquibaseTables(false, null, new Contexts(), new LabelExpression());
database.dropDatabaseObjects(schema);
}
} catch (DatabaseException e) {
throw e;
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
LockServiceFactory.getInstance().getLockService(database).destroy();
resetServices();
}
return new CommandResult("All objects dropped from " + database.getConnection().getConnectionUserName() + "@" + database.getConnection().getURL());
}
use of liquibase.command.CommandResult in project liquibase by liquibase.
the class ExecuteSqlCommand method run.
@Override
protected CommandResult run() throws Exception {
Executor executor = ExecutorService.getInstance().getExecutor(database);
String sqlText;
if (sqlFile == null) {
sqlText = sql;
} else {
File file = new File(sqlFile);
if (!file.exists()) {
throw new LiquibaseException(String.format("The file '%s' does not exist", file.getCanonicalPath()));
}
sqlText = FileUtil.getContents(file);
}
String out = "";
String[] sqlStrings = StringUtils.processMutliLineSQL(sqlText, true, true, delimiter);
for (String sql : sqlStrings) {
if (sql.toLowerCase().matches("\\s*select .*")) {
List<Map<String, ?>> rows = executor.queryForList(new RawSqlStatement(sql));
out += "Output of " + sql + ":\n";
if (rows.size() == 0) {
out += "-- Empty Resultset --\n";
} else {
SortedSet<String> keys = new TreeSet<String>();
for (Map<String, ?> row : rows) {
keys.addAll(row.keySet());
}
out += StringUtils.join(keys, " | ") + " |\n";
for (Map<String, ?> row : rows) {
for (String key : keys) {
out += row.get(key) + " | ";
}
out += "\n";
}
}
} else {
executor.execute(new RawSqlStatement(sql));
out += "Successfully Executed: " + sql + "\n";
}
out += "\n";
}
database.commit();
return new CommandResult(out.trim());
}
Aggregations