/** * Implementation delegates logic to the {@link * liquibase.sqlgenerator.SqlGenerator#warn(liquibase.statement.SqlStatement, * liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)} method on the {@link * SqlStatement} objects returned by {@link #generateStatements }. If a generated statement is not * supported for the given database, no warning will be added since that is a validation error. If * no or null SqlStatements are returned by generateStatements then this method returns no * warnings. */ @Override public Warnings warn(Database database) { Warnings warnings = new Warnings(); if (generateStatementsVolatile(database)) { return warnings; } SqlStatement[] statements = generateStatements(database); if (statements == null) { return warnings; } for (SqlStatement statement : statements) { if (SqlGeneratorFactory.getInstance().supports(statement, database)) { warnings.addAll(SqlGeneratorFactory.getInstance().warn(statement, database)); } else if (statement.skipOnUnsupported()) { warnings.addWarning( statement.getClass().getName() + " is not supported on " + database.getShortName() + ", but " + ChangeFactory.getInstance().getChangeMetaData(this).getName() + " will still execute"); } } return warnings; }
/* * Executes the statements passed * * @param statements an array containing the SQL statements to be issued * @param sqlVisitors a list of {@link SqlVisitor} objects to be applied to the executed statements * @throws DatabaseException if there were problems issuing the statements */ @Override public void execute(final SqlStatement[] statements, final List<SqlVisitor> sqlVisitors) throws LiquibaseException { for (SqlStatement statement : statements) { if (statement.skipOnUnsupported() && !SqlGeneratorFactory.getInstance().supports(statement, this)) { continue; } LogFactory.getLogger().debug("Executing Statement: " + statement); ExecutorService.getInstance().getExecutor(this).execute(statement, sqlVisitors); } }
/** * Implementation checks the ChangeParameterMetaData for declared required fields and also * delegates logic to the {@link * liquibase.sqlgenerator.SqlGenerator#validate(liquibase.statement.SqlStatement, * liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)} method on the {@link * SqlStatement} objects returned by {@link #generateStatements }. If no or null SqlStatements are * returned by generateStatements then this method returns no errors. If there are no parameters * than this method returns no errors */ @Override public ValidationErrors validate(Database database) { ValidationErrors changeValidationErrors = new ValidationErrors(); for (ChangeParameterMetaData param : ChangeFactory.getInstance().getChangeMetaData(this).getParameters().values()) { if (param.isRequiredFor(database) && param.getCurrentValue(this) == null) { changeValidationErrors.addError( param.getParameterName() + " is required for " + ChangeFactory.getInstance().getChangeMetaData(this).getName() + " on " + database.getShortName()); } } if (changeValidationErrors.hasErrors()) { return changeValidationErrors; } String unsupportedWarning = ChangeFactory.getInstance().getChangeMetaData(this).getName() + " is not supported on " + database.getShortName(); if (!this.supports(database)) { changeValidationErrors.addError(unsupportedWarning); } else if (!generateStatementsVolatile(database)) { boolean sawUnsupportedError = false; SqlStatement[] statements; statements = generateStatements(database); if (statements != null) { for (SqlStatement statement : statements) { boolean supported = SqlGeneratorFactory.getInstance().supports(statement, database); if (!supported && !sawUnsupportedError) { if (!statement.skipOnUnsupported()) { changeValidationErrors.addError(unsupportedWarning); sawUnsupportedError = true; } } else { changeValidationErrors.addAll( SqlGeneratorFactory.getInstance().validate(statement, database)); } } } } return changeValidationErrors; }
public ValidationErrors validate(Database database) { ValidationErrors changeValidationErrors = new ValidationErrors(); for (SqlStatement statement : generateStatements(database)) { boolean supported = SqlGeneratorFactory.getInstance().supports(statement, database); if (!supported) { if (statement.skipOnUnsupported()) { LogFactory.getLogger() .info( getChangeMetaData().getName() + " is not supported on " + database.getTypeName() + " but will continue"); } else { changeValidationErrors.addError( getChangeMetaData().getName() + " is not supported on " + database.getTypeName()); } } else { changeValidationErrors.addAll( SqlGeneratorFactory.getInstance().validate(statement, database)); } } return changeValidationErrors; }
private void outputStatement(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException { try { if (SqlGeneratorFactory.getInstance().generateStatementsVolatile(sql, database)) { throw new DatabaseException( sql.getClass().getSimpleName() + " requires access to up to date database metadata which is not available in SQL output mode"); } for (String statement : applyVisitors(sql, sqlVisitors)) { if (statement == null) { continue; } output.write(statement); if (database instanceof MSSQLDatabase || database instanceof SybaseDatabase || database instanceof SybaseASADatabase) { output.write(StreamUtil.getLineSeparator()); output.write("GO"); // } else if (database instanceof OracleDatabase) { // output.write(StreamUtil.getLineSeparator()); // output.write("/"); } else { String endDelimiter = ";"; if (sql instanceof RawSqlStatement) { endDelimiter = ((RawSqlStatement) sql).getEndDelimiter(); } if (!statement.endsWith(endDelimiter)) { output.write(endDelimiter); } } output.write(StreamUtil.getLineSeparator()); output.write(StreamUtil.getLineSeparator()); } } catch (IOException e) { throw new DatabaseException(e); } }