use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class PrimaryKeyComparator method findDifferences.
@Override
public ObjectDifferences findDifferences(DatabaseObject databaseObject1, DatabaseObject databaseObject2, Database accordingTo, CompareControl compareControl, DatabaseObjectComparatorChain chain, Set<String> exclude) {
exclude.add("name");
exclude.add("backingIndex");
exclude.add("columns");
ObjectDifferences differences = chain.findDifferences(databaseObject1, databaseObject2, accordingTo, compareControl, exclude);
differences.compare("columns", databaseObject1, databaseObject2, new ObjectDifferences.CompareFunction() {
@Override
public boolean areEqual(Object referenceValue, Object compareToValue) {
List<Column> referenceList = (List) referenceValue;
List<Column> compareList = (List) compareToValue;
if (referenceList.size() != compareList.size()) {
return false;
}
for (int i = 0; i < referenceList.size(); i++) {
if (!StringUtil.trimToEmpty((referenceList.get(i)).getName()).equalsIgnoreCase(StringUtil.trimToEmpty(compareList.get(i).getName()))) {
return false;
}
}
return true;
}
});
return differences;
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class StringSnapshotSerializerReadable method outputObjects.
protected void outputObjects(List objects, Class type, StringBuilder catalogBuffer) {
List<? extends DatabaseObject> databaseObjects = sort(objects);
if (!databaseObjects.isEmpty()) {
catalogBuffer.append(type.getName()).append(":\n");
StringBuilder typeBuffer = new StringBuilder();
for (DatabaseObject databaseObject : databaseObjects) {
typeBuffer.append(databaseObject.getName()).append("\n");
typeBuffer.append(StringUtil.indent(serialize(databaseObject, null), INDENT_LENGTH)).append("\n");
}
catalogBuffer.append(StringUtil.indent(typeBuffer.toString(), INDENT_LENGTH)).append("\n");
}
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class DiffToChangeLogTest method getOrderedOutputTypes_isConsistant.
@Test
public void getOrderedOutputTypes_isConsistant() throws Exception {
MySQLDatabase database = new MySQLDatabase();
DiffToChangeLog obj = new DiffToChangeLog(new DiffResult(new EmptyDatabaseSnapshot(database), new EmptyDatabaseSnapshot(database), new CompareControl()), null);
for (Class<? extends ChangeGenerator> type : new Class[] { UnexpectedObjectChangeGenerator.class, MissingObjectChangeGenerator.class, ChangedObjectChangeGenerator.class }) {
List<Class<? extends DatabaseObject>> orderedOutputTypes = obj.getOrderedOutputTypes(type);
for (int i = 0; i < 50; i++) {
assertThat("Error checking " + type.getName(), orderedOutputTypes, contains(obj.getOrderedOutputTypes(type).toArray()));
}
}
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class AbstractChange method getAffectedDatabaseObjects.
/**
* Implementation delegates logic to the
* {@link liquibase.sqlgenerator.SqlGeneratorFactory#getAffectedDatabaseObjects(liquibase.statement.SqlStatement,
* liquibase.database.Database)} method on the {@link SqlStatement} objects returned by {@link #generateStatements }
* Returns empty set if change is not supported for the passed database
*/
@Override
public Set<DatabaseObject> getAffectedDatabaseObjects(Database database) {
if (this.generateStatementsVolatile(database)) {
return new HashSet<>();
}
Set<DatabaseObject> affectedObjects = new HashSet<>();
SqlStatement[] statements = generateStatements(database);
if (statements != null) {
for (SqlStatement statement : statements) {
affectedObjects.addAll(SqlGeneratorFactory.getInstance().getAffectedDatabaseObjects(statement, database));
}
}
return affectedObjects;
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class DiffToReport method print.
public void print() throws DatabaseException {
final DatabaseObjectComparator comparator = new DatabaseObjectComparator();
out.println("Reference Database: " + diffResult.getReferenceSnapshot().getDatabase());
out.println("Comparison Database: " + diffResult.getComparisonSnapshot().getDatabase());
CompareControl.SchemaComparison[] schemas = diffResult.getCompareControl().getSchemaComparisons();
if ((schemas != null) && (schemas.length > 0)) {
out.println("Compared Schemas: " + StringUtil.join(Arrays.asList(schemas), ", ", new StringUtil.StringUtilFormatter<CompareControl.SchemaComparison>() {
@Override
public String toString(CompareControl.SchemaComparison obj) {
String referenceName;
String comparisonName;
Database referenceDatabase = diffResult.getReferenceSnapshot().getDatabase();
Database comparisonDatabase = diffResult.getComparisonSnapshot().getDatabase();
if (referenceDatabase.supportsSchemas()) {
referenceName = obj.getReferenceSchema().getSchemaName();
if (referenceName == null) {
referenceName = referenceDatabase.getDefaultSchemaName();
}
} else if (referenceDatabase.supportsCatalogs()) {
referenceName = obj.getReferenceSchema().getCatalogName();
if (referenceName == null) {
referenceName = referenceDatabase.getDefaultCatalogName();
}
} else {
return "";
}
if (comparisonDatabase.supportsSchemas()) {
comparisonName = obj.getComparisonSchema().getSchemaName();
if (comparisonName == null) {
comparisonName = comparisonDatabase.getDefaultSchemaName();
}
} else if (comparisonDatabase.supportsCatalogs()) {
comparisonName = obj.getComparisonSchema().getCatalogName();
if (comparisonName == null) {
comparisonName = comparisonDatabase.getDefaultCatalogName();
}
} else {
return "";
}
if (referenceName == null) {
referenceName = StringUtil.trimToEmpty(referenceDatabase.getDefaultSchemaName());
}
if (comparisonName == null) {
comparisonName = StringUtil.trimToEmpty(comparisonDatabase.getDefaultSchemaName());
}
if (referenceName.equalsIgnoreCase(comparisonName)) {
return referenceName;
} else {
return referenceName + " -> " + comparisonName;
}
}
}, true));
}
printComparison("Product Name", diffResult.getProductNameDiff(), out);
printComparison("Product Version", diffResult.getProductVersionDiff(), out);
TreeSet<Class<? extends DatabaseObject>> types = new TreeSet<>(new Comparator<Class<? extends DatabaseObject>>() {
@Override
public int compare(Class<? extends DatabaseObject> o1, Class<? extends DatabaseObject> o2) {
return o1.getSimpleName().compareTo(o2.getSimpleName());
}
});
types.addAll(diffResult.getCompareControl().getComparedTypes());
for (Class<? extends DatabaseObject> type : types) {
if (type.equals(Schema.class) && !diffResult.getComparisonSnapshot().getDatabase().supportsSchemas()) {
continue;
}
printSetComparison("Missing " + getTypeName(type), diffResult.getMissingObjects(type, comparator), out);
printSetComparison("Unexpected " + getTypeName(type), diffResult.getUnexpectedObjects(type, comparator), out);
printChangedComparison("Changed " + getTypeName(type), diffResult.getChangedObjects(type, comparator), out);
}
// printColumnComparison(diffResult.getColumns().getChanged(), out);
}
Aggregations