Search in sources :

Example 1 with CommentStatement

use of liquibase.statement.core.CommentStatement in project liquibase by liquibase.

the class ExecuteShellCommandChange method generateStatements.

@Override
public SqlStatement[] generateStatements(final Database database) {
    boolean shouldRun = true;
    if (os != null && os.size() > 0) {
        String currentOS = System.getProperty("os.name");
        if (!os.contains(currentOS)) {
            shouldRun = false;
            LogFactory.getLogger().info("Not executing on os " + currentOS + " when " + os + " was specified");
        }
    }
    // check if running under not-executed mode (logging output)
    boolean nonExecutedMode = false;
    Executor executor = ExecutorService.getInstance().getExecutor(database);
    if (executor instanceof LoggingExecutor) {
        nonExecutedMode = true;
    }
    this.finalCommandArray = createFinalCommandArray(database);
    if (shouldRun && !nonExecutedMode) {
        return new SqlStatement[] { new RuntimeStatement() {

            @Override
            public Sql[] generate(Database database) {
                try {
                    executeCommand(database);
                } catch (Exception e) {
                    throw new UnexpectedLiquibaseException("Error executing command: " + e.getLocalizedMessage(), e);
                }
                return null;
            }
        } };
    }
    if (nonExecutedMode) {
        try {
            return new SqlStatement[] { new CommentStatement(getCommandString()) };
        } finally {
            nonExecutedCleanup();
        }
    }
    return new SqlStatement[0];
}
Also used : SqlStatement(liquibase.statement.SqlStatement) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) CommentStatement(liquibase.statement.core.CommentStatement) LoggingExecutor(liquibase.executor.LoggingExecutor) Database(liquibase.database.Database) RuntimeStatement(liquibase.statement.core.RuntimeStatement) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) Sql(liquibase.sql.Sql)

Aggregations

Database (liquibase.database.Database)1 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)1 Executor (liquibase.executor.Executor)1 LoggingExecutor (liquibase.executor.LoggingExecutor)1 ParsedNodeException (liquibase.parser.core.ParsedNodeException)1 Sql (liquibase.sql.Sql)1 SqlStatement (liquibase.statement.SqlStatement)1 CommentStatement (liquibase.statement.core.CommentStatement)1 RuntimeStatement (liquibase.statement.core.RuntimeStatement)1