use of liquibase.database.structure.ForeignKey in project collect by openforis.
the class LiquidbaseDatabaseSnapshotBuilder method createForeignKeys.
protected void createForeignKeys() {
for (org.openforis.collect.relational.model.Table<?> itable : schema.getTables()) {
Table ltable = snapshot.getTable(itable.getName());
List<ReferentialConstraint> ifks = itable.getReferentialContraints();
for (ReferentialConstraint ifk : ifks) {
ForeignKey lfk = new ForeignKey();
lfk.setName(ifk.getName());
// set base table columns
lfk.setForeignKeyTable(ltable);
for (org.openforis.collect.relational.model.Column<?> ifcCol : ifk.getColumns()) {
lfk.addForeignKeyColumn(ifcCol.getName());
}
// set referenced key columns
UniquenessConstraint iReferencedKey = ifk.getReferencedKey();
org.openforis.collect.relational.model.Table<?> iReferencedTable = iReferencedKey.getTable();
Table lReferencedTable = snapshot.getTable(iReferencedTable.getName());
lfk.setPrimaryKeyTable(lReferencedTable);
for (org.openforis.collect.relational.model.Column<?> refCol : iReferencedKey.getColumns()) {
lfk.addPrimaryKeyColumn(refCol.getName());
}
// Add fk
snapshot.getForeignKeys().add(lfk);
}
}
}
Aggregations