liquibase.diff.compare.CompareControl Maven / Gradle / Ivy
package liquibase.diff.compare;
import liquibase.CatalogAndSchema;
import liquibase.database.Database;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.DatabaseObjectFactory;
import liquibase.util.StringUtils;
import java.util.*;
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) {
if (schemaComparison != null && schemaComparison.length > 0) {
this.schemaComparisons = schemaComparison;
} else {
this.schemaComparisons = new SchemaComparison[]{new SchemaComparison(new CatalogAndSchema(null, null), new CatalogAndSchema(null, null))};
}
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 schemaComparisons = new ArrayList();
List referenceSchemas = new ArrayList();
List targetSchemas = new ArrayList();
List splitReferenceSchemaNames = StringUtils.splitAndTrim(referenceSchemaNames, ",");
List splitSchemaNames = StringUtils.splitAndTrim(schemaNames, ",");
List splitOutputSchemaNames = StringUtils.splitAndTrim(StringUtils.trimToNull(outputSchemaNames), ",");
if (splitReferenceSchemaNames.size() != splitSchemaNames.size()) {
throw new UnexpectedLiquibaseException("You must specify the same number of schemas in --schemas and --referenceSchemas");
}
if (splitOutputSchemaNames != null && splitOutputSchemaNames.size() != splitSchemaNames.size()) {
throw new UnexpectedLiquibaseException("You must specify the same number of schemas in --schemas and --outputSchemasAs");
}
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy