use of org.openforis.collect.relational.model.PrimaryKeyConstraint 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.PrimaryKeyConstraint in project collect by openforis.
the class LiquidbaseDatabaseSnapshotBuilder method createPKIndexes.
private void createPKIndexes() {
for (org.openforis.collect.relational.model.Table<?> itable : schema.getTables()) {
Table ltable = snapshot.getTable(itable.getName());
PrimaryKeyConstraint pkConstraint = itable.getPrimaryKeyConstraint();
Index index = new Index();
index.setTable(ltable);
index.setName(pkConstraint.getName() + "_idx");
List<org.openforis.collect.relational.model.Column<?>> columns = pkConstraint.getColumns();
for (org.openforis.collect.relational.model.Column<?> column : columns) {
index.addAssociatedWith(Index.MARK_PRIMARY_KEY);
index.getColumns().add(column.getName());
}
snapshot.getIndexes().add(index);
}
}
use of org.openforis.collect.relational.model.PrimaryKeyConstraint 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.PrimaryKeyConstraint in project collect by openforis.
the class JooqRelationalSchemaCreator method addPKConstraints.
private void addPKConstraints(RelationalSchema schema, CollectDSLContext dsl) {
for (Table<?> table : schema.getTables()) {
org.jooq.Table<Record> jooqTable = jooqTable(schema, table, !dsl.isSchemaLess());
PrimaryKeyConstraint pkConstraint = table.getPrimaryKeyConstraint();
String pkColumnName = pkConstraint.getPrimaryKeyColumn().getName();
String pkConstraintName = table.getName() + "_pk";
dsl.alterTable(jooqTable).add(constraint(pkConstraintName).primaryKey(pkColumnName)).execute();
}
}
use of org.openforis.collect.relational.model.PrimaryKeyConstraint in project collect by openforis.
the class JooqRelationalSchemaCreator method addPKIndexes.
private void addPKIndexes(RelationalSchema schema, CollectDSLContext dsl) {
for (Table<?> table : schema.getTables()) {
org.jooq.Table<Record> jooqTable = jooqTable(schema, table, !dsl.isSchemaLess());
// For SQLite it creates an index on the primary key, for POSTGRESQL it will alter the table to set the primary key columns
PrimaryKeyConstraint pkConstraint = table.getPrimaryKeyConstraint();
String pkColumnName = pkConstraint.getPrimaryKeyColumn().getName();
String pkConstraintName = table.getName() + "_pk";
dsl.createIndex(pkConstraintName).unique().on(jooqTable, field(pkColumnName)).execute();
}
}
Aggregations