use of liquibase.structure.core.View in project liquibase by liquibase.
the class RenameViewChange method checkStatus.
@Override
public ChangeStatus checkStatus(Database database) {
try {
ChangeStatus changeStatus = new ChangeStatus();
View newView = SnapshotGeneratorFactory.getInstance().createSnapshot(new View(getCatalogName(), getSchemaName(), getNewViewName()), database);
View oldView = SnapshotGeneratorFactory.getInstance().createSnapshot(new View(getCatalogName(), getSchemaName(), getOldViewName()), database);
if (newView == null && oldView == null) {
return changeStatus.unknown("Neither view exists");
}
if (newView != null && oldView != null) {
return changeStatus.unknown("Both views exist");
}
changeStatus.assertComplete(newView != null, "New view does not exist");
return changeStatus;
} catch (Exception e) {
return new ChangeStatus().unknown(e);
}
}
use of liquibase.structure.core.View in project liquibase by liquibase.
the class MissingViewChangeGenerator method fixMissing.
@Override
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, final Database comparisonDatabase, ChangeGeneratorChain chain) {
View view = (View) missingObject;
CreateViewChange change = createViewChange();
change.setViewName(view.getName());
if (control.getIncludeCatalog()) {
change.setCatalogName(view.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(view.getSchema().getName());
}
String selectQuery = view.getDefinition();
boolean fullDefinitionOverridden = false;
if (selectQuery == null) {
selectQuery = "COULD NOT DETERMINE VIEW QUERY";
} else if (comparisonDatabase instanceof OracleDatabase && view.getColumns() != null && view.getColumns().size() > 0) {
String viewName;
if (change.getCatalogName() == null && change.getSchemaName() == null) {
viewName = comparisonDatabase.escapeObjectName(change.getViewName(), View.class);
} else {
viewName = comparisonDatabase.escapeViewName(change.getCatalogName(), change.getSchemaName(), change.getViewName());
}
selectQuery = "CREATE OR REPLACE FORCE VIEW " + viewName + " (" + StringUtils.join(view.getColumns(), ", ", new StringUtils.StringUtilsFormatter() {
@Override
public String toString(Object obj) {
if (((Column) obj).getComputed() != null && ((Column) obj).getComputed()) {
return ((Column) obj).getName();
} else {
return comparisonDatabase.escapeColumnName(null, null, null, ((Column) obj).getName(), false);
}
}
}) + ") AS " + selectQuery;
change.setFullDefinition(true);
fullDefinitionOverridden = true;
}
change.setSelectQuery(selectQuery);
if (!fullDefinitionOverridden) {
change.setFullDefinition(view.getContainsFullDefinition());
}
return new Change[] { change };
}
use of liquibase.structure.core.View in project liquibase by liquibase.
the class UnexpectedViewChangeGenerator method fixUnexpected.
@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
View view = (View) unexpectedObject;
DropViewChange change = new DropViewChange();
change.setViewName(view.getName());
if (control.getIncludeCatalog()) {
change.setCatalogName(view.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(view.getSchema().getName());
}
for (Column column : view.getColumns()) {
control.setAlreadyHandledUnexpected(column);
}
;
return new Change[] { change };
}
use of liquibase.structure.core.View in project liquibase by liquibase.
the class ChangedViewChangeGenerator method fixChanged.
@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, final Database comparisonDatabase, ChangeGeneratorChain chain) {
View view = (View) changedObject;
CreateViewChange change = createViewChange();
change.setViewName(view.getName());
change.setReplaceIfExists(true);
if (control.getIncludeCatalog()) {
change.setCatalogName(view.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(view.getSchema().getName());
}
String selectQuery = view.getDefinition();
boolean fullDefinitionOverridden = false;
if (selectQuery == null) {
selectQuery = "COULD NOT DETERMINE VIEW QUERY";
} else if (comparisonDatabase instanceof OracleDatabase && view.getColumns() != null && view.getColumns().size() > 0) {
String viewName;
if (change.getCatalogName() == null && change.getSchemaName() == null) {
viewName = comparisonDatabase.escapeObjectName(change.getViewName(), View.class);
} else {
viewName = comparisonDatabase.escapeViewName(change.getCatalogName(), change.getSchemaName(), change.getViewName());
}
selectQuery = "CREATE OR REPLACE FORCE VIEW " + viewName + " (" + StringUtils.join(view.getColumns(), ", ", new StringUtils.StringUtilsFormatter() {
@Override
public String toString(Object obj) {
if (((Column) obj).getComputed() != null && ((Column) obj).getComputed()) {
return ((Column) obj).getName();
} else {
return comparisonDatabase.escapeColumnName(null, null, null, ((Column) obj).getName(), false);
}
}
}) + ") AS " + selectQuery;
change.setFullDefinition(true);
fullDefinitionOverridden = true;
}
change.setSelectQuery(selectQuery);
if (!fullDefinitionOverridden) {
change.setFullDefinition(view.getContainsFullDefinition());
}
return new Change[] { change };
}
use of liquibase.structure.core.View in project liquibase by liquibase.
the class CreateViewGeneratorInformix method generateSql.
@Override
public Sql[] generateSql(CreateViewStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String viewName = database.escapeViewName(statement.getCatalogName(), statement.getSchemaName(), statement.getViewName());
String createClause = "CREATE VIEW " + viewName + " AS SELECT * FROM (" + statement.getSelectQuery() + ") AS v";
if (statement.isReplaceIfExists()) {
return new Sql[] { new UnparsedSql("DROP VIEW IF EXISTS " + viewName), new UnparsedSql(createClause, new View().setName(viewName).setSchema(statement.getCatalogName(), statement.getViewName())) };
}
return new Sql[] { new UnparsedSql(createClause) };
}
Aggregations