Search in sources :

Example 6 with ReferentialConstraint

use of org.openforis.collect.relational.model.ReferentialConstraint in project collect by openforis.

the class RDBSchemaPrintTask method writeAddForeignKeysWithAlterTable.

private void writeAddForeignKeysWithAlterTable() throws IOException {
    for (Table<?> table : schema.getTables()) {
        List<ReferentialConstraint> fks = table.getReferentialContraints();
        if (!fks.isEmpty()) {
            writer.write("ALTER TABLE ");
            writer.write(getQualifiedTableName(table));
            writer.write('\n');
            for (int i = 0; i < fks.size(); i++) {
                ReferentialConstraint fk = fks.get(i);
                writer.write('\t');
                writer.write(" ADD CONSTRAINT ");
                writer.write(fk.getName());
                writeForeignKeyConstraint(fk);
                if (i < fks.size() - 1) {
                    writer.write(", \n");
                } else {
                    writer.write(";");
                }
            }
            writer.write('\n');
        }
    }
}
Also used : ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint)

Example 7 with ReferentialConstraint

use of org.openforis.collect.relational.model.ReferentialConstraint in project collect by openforis.

the class RDBSchemaPrintTask method writeTable.

private void writeTable(Table<?> table) throws IOException {
    writer.write("CREATE TABLE ");
    if (!isSchemaless()) {
        writer.write(doubleQuote(schema.getName()));
        writer.write('.');
    }
    writer.write(doubleQuote(table.getName()));
    writer.write(" (");
    writer.write('\n');
    List<Column<?>> columns = table.getColumns();
    for (int i = 0; i < columns.size(); i++) {
        if (i > 0) {
            writer.write(',');
            writer.write('\n');
        }
        Column<?> column = columns.get(i);
        writeColumn(column);
    }
    if (includeForeignKeysInCreateTable && !table.getReferentialContraints().isEmpty()) {
        writer.write(',');
        writer.write('\n');
        List<ReferentialConstraint> fks = table.getReferentialContraints();
        for (int i = 0; i < fks.size(); i++) {
            ReferentialConstraint fk = fks.get(i);
            writer.write('\t');
            writeForeignKeyConstraint(fk);
            if (i < fks.size() - 1) {
                writer.write(", \n");
            }
        }
    }
    writer.write('\n');
    writer.write(");");
    writer.write('\n');
}
Also used : Column(org.openforis.collect.relational.model.Column) PrimaryKeyColumn(org.openforis.collect.relational.model.PrimaryKeyColumn) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint)

Example 8 with ReferentialConstraint

use of org.openforis.collect.relational.model.ReferentialConstraint in project collect by openforis.

the class SqlSchemaWriter method writeAddForeignKeysWithAlterTable.

private void writeAddForeignKeysWithAlterTable() throws IOException {
    for (Table<?> table : schema.getTables()) {
        List<ReferentialConstraint> fks = table.getReferentialContraints();
        if (!fks.isEmpty()) {
            writer.write("ALTER TABLE ");
            writer.write(getQualifiedTableName(table));
            writer.write('\n');
            for (int i = 0; i < fks.size(); i++) {
                ReferentialConstraint fk = fks.get(i);
                writer.write('\t');
                writer.write(" ADD CONSTRAINT ");
                writer.write(fk.getName());
                writeForeignKeyConstraint(fk);
                if (i < fks.size() - 1) {
                    writer.write(", \n");
                } else {
                    writer.write(";");
                }
            }
            writer.write('\n');
        }
    }
}
Also used : ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint)

Aggregations

ReferentialConstraint (org.openforis.collect.relational.model.ReferentialConstraint)8 PrimaryKeyConstraint (org.openforis.collect.relational.model.PrimaryKeyConstraint)6 UniquenessConstraint (org.openforis.collect.relational.model.UniquenessConstraint)6 Column (org.openforis.collect.relational.model.Column)3 Record (org.jooq.Record)2 DataTable (org.openforis.collect.relational.model.DataTable)2 PrimaryKeyColumn (org.openforis.collect.relational.model.PrimaryKeyColumn)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 Field (org.jooq.Field)1 DSL.constraint (org.jooq.impl.DSL.constraint)1