use of liquibase.statement.core.DropViewStatement in project liquibase by liquibase.
the class CreateViewChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
List<SqlStatement> statements = new ArrayList<>();
boolean replaceIfExists = false;
if ((getReplaceIfExists() != null) && getReplaceIfExists()) {
replaceIfExists = true;
}
boolean fullDefinition = false;
if (this.fullDefinition != null) {
fullDefinition = this.fullDefinition;
}
String selectQuery;
String path = getPath();
if (path == null) {
selectQuery = StringUtil.trimToNull(getSelectQuery());
} else {
try {
InputStream stream = openSqlStream();
if (stream == null) {
throw new IOException(FileUtil.getFileNotFoundMessage(path));
}
selectQuery = StreamUtil.readStreamAsString(stream, encoding);
if (getChangeSet() != null) {
ChangeLogParameters parameters = getChangeSet().getChangeLogParameters();
if (parameters != null) {
selectQuery = parameters.expandExpressions(selectQuery, getChangeSet().getChangeLog());
}
}
} catch (IOException e) {
throw new UnexpectedLiquibaseException(e);
}
}
if (!supportsReplaceIfExistsOption(database) && replaceIfExists) {
statements.add(new DropViewStatement(getCatalogName(), getSchemaName(), getViewName()));
statements.add(createViewStatement(getCatalogName(), getSchemaName(), getViewName(), selectQuery, false).setFullDefinition(fullDefinition));
} else {
statements.add(createViewStatement(getCatalogName(), getSchemaName(), getViewName(), selectQuery, replaceIfExists).setFullDefinition(fullDefinition));
}
if ((database instanceof OracleDatabase) && (StringUtil.trimToNull(remarks) != null)) {
SetTableRemarksStatement remarksStatement = new SetTableRemarksStatement(catalogName, schemaName, viewName, remarks);
if (SqlGeneratorFactory.getInstance().supports(remarksStatement, database)) {
statements.add(remarksStatement);
}
}
return statements.toArray(new SqlStatement[statements.size()]);
}
Aggregations