use of org.openforis.collect.relational.model.UniquenessConstraint in project collect by openforis.
the class Mondrian4SchemaGenerator method generatePhysicalSchema.
// private String getDateFieldLevelType(String fieldName) {
// if (DateAttributeDefinition.YEAR_FIELD_NAME.equals(fieldName)) {
// return "TimeYears";
// } else if (DateAttributeDefinition.MONTH_FIELD_NAME.equals(fieldName)) {
// return "TimeMonths";
// } else if(DateAttributeDefinition.DAY_FIELD_NAME.equals(fieldName)) {
// return "TimeDays";
// } else {
// throw new IllegalArgumentException("Unexpected date attribute field name: " + fieldName);
// }
// }
private PhysicalSchema generatePhysicalSchema() {
PhysicalSchema physicalSchema = new PhysicalSchema();
for (org.openforis.collect.relational.model.Table<?> rdbTable : rdbSchema.getTables()) {
Table table = new Table();
table.name = rdbTable.getName();
PrimaryKeyConstraint pkConstraint = rdbTable.getPrimaryKeyConstraint();
table.keyColumn = pkConstraint.getPrimaryKeyColumn().getName();
physicalSchema.children.add(table);
// add foreign keys
for (ReferentialConstraint referentialConstraint : rdbTable.getReferentialContraints()) {
UniquenessConstraint referencedKey = referentialConstraint.getReferencedKey();
org.openforis.collect.relational.model.Table<?> referencedRdbTable = referencedKey.getTable();
Link link = new Link();
link.source = rdbTable.getName();
link.target = referencedRdbTable.getName();
ForeignKey foreignKey = new ForeignKey();
for (org.openforis.collect.relational.model.Column<?> referencedRdbColumn : referencedKey.getColumns()) {
Column fkColumn = new Column();
fkColumn.name = referencedRdbColumn.getName();
foreignKey.list().add(fkColumn);
}
link.foreignKey = foreignKey;
physicalSchema.children.add(link);
}
}
return physicalSchema;
}
use of org.openforis.collect.relational.model.UniquenessConstraint in project collect by openforis.
the class SqlSchemaWriter method writeForeignKeyConstraint.
private void writeForeignKeyConstraint(ReferentialConstraint fk) throws IOException {
writer.write(" FOREIGN KEY ");
writer.write('(');
writeColumnNameSet(fk.getColumns());
writer.write(')');
writer.write(" REFERENCES ");
UniquenessConstraint referencedKey = fk.getReferencedKey();
Table<?> referencedTable = referencedKey.getTable();
writer.write(getQualifiedTableName(referencedTable));
PrimaryKeyConstraint referencedTablePK = referencedTable.getPrimaryKeyConstraint();
writer.write('(');
writeColumnNameSet(referencedTablePK.getColumns());
writer.write(")");
}
use of org.openforis.collect.relational.model.UniquenessConstraint 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);
}
}
}
use of org.openforis.collect.relational.model.UniquenessConstraint in project collect by openforis.
the class RDBSchemaPrintTask method writeForeignKeyConstraint.
private void writeForeignKeyConstraint(ReferentialConstraint fk) throws IOException {
writer.write(" FOREIGN KEY ");
writer.write('(');
writeColumnNameSet(fk.getColumns());
writer.write(')');
writer.write(" REFERENCES ");
UniquenessConstraint referencedKey = fk.getReferencedKey();
Table<?> referencedTable = referencedKey.getTable();
writer.write(getQualifiedTableName(referencedTable));
PrimaryKeyConstraint referencedTablePK = referencedTable.getPrimaryKeyConstraint();
writer.write('(');
writeColumnNameSet(referencedTablePK.getColumns());
writer.write(")");
}
Aggregations