public abstract class AbstractDatabaseDiffTask extends BaseLiquibaseTask {
private DatabaseType referenceDatabaseType;
private String diffTypes;
protected DiffResult getDiffResult() {
Liquibase liquibase = getLiquibase();
Database targetDatabase = liquibase.getDatabase();
Database referenceDatabase = createDatabaseFromType(referenceDatabaseType);
CatalogAndSchema targetCatalogAndSchema = buildCatalogAndSchema(targetDatabase);
CatalogAndSchema referenceCatalogAndSchema = buildCatalogAndSchema(referenceDatabase);
CompareControl.SchemaComparison[] schemaComparisons = {
new CompareControl.SchemaComparison(referenceCatalogAndSchema, targetCatalogAndSchema)
};
SnapshotGeneratorFactory snapshotGeneratorFactory = SnapshotGeneratorFactory.getInstance();
DatabaseSnapshot referenceSnapshot;
try {
referenceSnapshot = snapshotGeneratorFactory.createSnapshot(referenceDatabase.getDefaultSchema(),
referenceDatabase, new SnapshotControl(referenceDatabase, diffTypes));
} catch (LiquibaseException e) {
throw new BuildException("Unable to create a DatabaseSnapshot.", e);
}
CompareControl compareControl = new CompareControl(schemaComparisons, referenceSnapshot.getSnapshotControl().getTypesToInclude());
try {
return liquibase.diff(referenceDatabase, targetDatabase, compareControl);
} catch (LiquibaseException e) {
throw new BuildException("Unable to diff databases.", e);
}
}