use of liquibase.statement.core.FindForeignKeyConstraintsStatement in project liquibase by liquibase.
the class DropAllForeignKeyConstraintsChange method generateChildren.
private List<DropForeignKeyConstraintChange> generateChildren(Database database) {
// Make a new list
List<DropForeignKeyConstraintChange> childDropChanges = new ArrayList<DropForeignKeyConstraintChange>();
Executor executor = ExecutorService.getInstance().getExecutor(database);
FindForeignKeyConstraintsStatement sql = new FindForeignKeyConstraintsStatement(getBaseTableCatalogName(), getBaseTableSchemaName(), getBaseTableName());
try {
List<Map<String, ?>> results = executor.queryForList(sql);
Set<String> handledConstraints = new HashSet<String>();
if (results != null && results.size() > 0) {
for (Map result : results) {
String baseTableName = (String) result.get(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME);
String constraintName = (String) result.get(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME);
if (DatabaseObjectComparatorFactory.getInstance().isSameObject(new Table().setName(getBaseTableName()), new Table().setName(baseTableName), null, database)) {
if (!handledConstraints.contains(constraintName)) {
DropForeignKeyConstraintChange dropForeignKeyConstraintChange = new DropForeignKeyConstraintChange();
dropForeignKeyConstraintChange.setBaseTableSchemaName(getBaseTableSchemaName());
dropForeignKeyConstraintChange.setBaseTableName(baseTableName);
dropForeignKeyConstraintChange.setConstraintName(constraintName);
childDropChanges.add(dropForeignKeyConstraintChange);
handledConstraints.add(constraintName);
}
} else {
throw new IllegalStateException("Expected to return only foreign keys for base table name: " + getBaseTableName() + " and got results for table: " + baseTableName);
}
}
}
return childDropChanges;
} catch (DatabaseException e) {
throw new UnexpectedLiquibaseException("Failed to find foreign keys for table: " + getBaseTableName(), e);
}
}
Aggregations