Search in sources :

Example 1 with UniquenessConstraint

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;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) Table(mondrian.olap.MondrianDef.Table) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) ForeignKey(mondrian.olap.MondrianDef.ForeignKey) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint) PhysicalSchema(mondrian.olap.MondrianDef.PhysicalSchema) Column(mondrian.olap.MondrianDef.Column) CodeValueFKColumn(org.openforis.collect.relational.model.CodeValueFKColumn) DataColumn(org.openforis.collect.relational.model.DataColumn) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint) Link(mondrian.olap.MondrianDef.Link) DimensionLink(mondrian.olap.MondrianDef.DimensionLink) ForeignKeyLink(mondrian.olap.MondrianDef.ForeignKeyLink) FactLink(mondrian.olap.MondrianDef.FactLink) NoLink(mondrian.olap.MondrianDef.NoLink)

Example 2 with UniquenessConstraint

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(")");
}
Also used : UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint)

Example 3 with UniquenessConstraint

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);
        }
    }
}
Also used : Table(liquibase.database.structure.Table) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint) ForeignKey(liquibase.database.structure.ForeignKey)

Example 4 with UniquenessConstraint

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(")");
}
Also used : UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint)

Aggregations

UniquenessConstraint (org.openforis.collect.relational.model.UniquenessConstraint)4 PrimaryKeyConstraint (org.openforis.collect.relational.model.PrimaryKeyConstraint)3 ReferentialConstraint (org.openforis.collect.relational.model.ReferentialConstraint)2 ForeignKey (liquibase.database.structure.ForeignKey)1 Table (liquibase.database.structure.Table)1 Column (mondrian.olap.MondrianDef.Column)1 DimensionLink (mondrian.olap.MondrianDef.DimensionLink)1 FactLink (mondrian.olap.MondrianDef.FactLink)1 ForeignKey (mondrian.olap.MondrianDef.ForeignKey)1 ForeignKeyLink (mondrian.olap.MondrianDef.ForeignKeyLink)1 Link (mondrian.olap.MondrianDef.Link)1 NoLink (mondrian.olap.MondrianDef.NoLink)1 PhysicalSchema (mondrian.olap.MondrianDef.PhysicalSchema)1 Table (mondrian.olap.MondrianDef.Table)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 DataTable (org.openforis.collect.relational.model.DataTable)1