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');
}
}
}
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');
}
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');
}
}
}
Aggregations