Search in sources :

Example 1 with ForeignKey

use of mondrian.olap.MondrianDef.ForeignKey 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)

Aggregations

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 PrimaryKeyConstraint (org.openforis.collect.relational.model.PrimaryKeyConstraint)1 ReferentialConstraint (org.openforis.collect.relational.model.ReferentialConstraint)1 UniquenessConstraint (org.openforis.collect.relational.model.UniquenessConstraint)1