liquibase.diff.compare.CompareControl Maven / Gradle / Ivy
package liquibase.diff.compare;
import liquibase.CatalogAndSchema;
import liquibase.database.Database;
import liquibase.diff.ObjectDifferences;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.logging.LogFactory;
import liquibase.servicelocator.ServiceLocator;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.DatabaseObjectFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class CompareControl {
private CompareControl.SchemaComparison[] schemaComparisons;
private Set> compareTypes = new HashSet>();
private Map, Set> suppressedFields = new HashMap, Set>();
public static CompareControl STANDARD = new CompareControl();
public CompareControl() {
this(null);
}
public CompareControl(Set> compareTypes) {
schemaComparisons = new SchemaComparison[]{new SchemaComparison(new CatalogAndSchema(null, null), new CatalogAndSchema(null, null))};
setTypes(compareTypes);
}
public CompareControl(SchemaComparison[] schemaComparison, Set> compareTypes) {
this.schemaComparisons = schemaComparison;
setTypes(compareTypes);
}
public CompareControl(SchemaComparison[] schemaComparison, String compareTypes) {
this.schemaComparisons = schemaComparison;
setTypes(DatabaseObjectFactory.getInstance().parseTypes(compareTypes));
}
public CompareControl(String[] referenceVsComparisonSchemas, Set> compareTypes) {
String[] splitReferenceSchemas = referenceVsComparisonSchemas[0].split(",");
String[] splitComparisonSchemas = referenceVsComparisonSchemas[1].split(",");
this.schemaComparisons = new SchemaComparison[splitReferenceSchemas.length];
for (int i = 0; i < splitReferenceSchemas.length; i++) {
String referenceCatalogName = null;
String referenceSchemaName = splitReferenceSchemas[i];
if (referenceSchemaName.contains(".")) {
referenceCatalogName = referenceSchemaName.split(".", 2)[0];
referenceSchemaName = referenceSchemaName.split(".", 2)[1];
}
String comparisonCatalogName = null;
String comparisonSchemaName = splitComparisonSchemas[i];
if (comparisonSchemaName.contains(".")) {
comparisonCatalogName = comparisonSchemaName.split(".", 2)[0];
comparisonSchemaName = comparisonSchemaName.split(".", 2)[1];
}
CatalogAndSchema referenceSchema = new CatalogAndSchema(referenceCatalogName, referenceSchemaName);
CatalogAndSchema comparisonSchema = new CatalogAndSchema(comparisonCatalogName, comparisonSchemaName);
this.schemaComparisons[i] = new SchemaComparison(referenceSchema, comparisonSchema);
setTypes(compareTypes);
}
}
protected void setTypes(Set> types) {
if (types == null || types.size() == 0) {
types = DatabaseObjectFactory.getInstance().getStandardTypes();
}
this.compareTypes = types;
}
public Set> getComparedTypes() {
return compareTypes;
}
public CompareControl addSuppressedField(Class extends DatabaseObject> type, String field) {
if (!suppressedFields.containsKey(type)) {
suppressedFields.put(type, new HashSet());
}
suppressedFields.get(type).add(field);
return this;
}
public boolean isSuppressedField(Class extends DatabaseObject> type, String field) {
if (!suppressedFields.containsKey(type)) {
return false;
}
return suppressedFields.get(type).contains(field);
}
public SchemaComparison[] getSchemaComparisons() {
return schemaComparisons;
}
public CatalogAndSchema[] getSchemas(DatabaseRole databaseRole) {
CatalogAndSchema[] schemas = new CatalogAndSchema[schemaComparisons.length];
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy