use of org.openforis.collect.relational.model.PrimaryKeyColumn in project collect by openforis.
the class LiquidbaseDatabaseSnapshotBuilder method createTables.
private void createTables() {
// Create table
for (org.openforis.collect.relational.model.Table<?> itable : schema.getTables()) {
Table ltable = new Table(itable.getName());
Database db = snapshot.getDatabase();
ltable.setDatabase(db);
ltable.setSchema(schema.getName());
ltable.setRawSchemaName(schema.getName());
// Create columns
for (org.openforis.collect.relational.model.Column<?> icolumn : itable.getColumns()) {
Column lcolumn = new Column();
lcolumn.setTable(ltable);
lcolumn.setName(icolumn.getName());
lcolumn.setNullable(icolumn.isNullable());
lcolumn.setDataType(icolumn.getType());
lcolumn.setTypeName(icolumn.getTypeName());
if (icolumn.getLength() != null) {
lcolumn.setColumnSize(icolumn.getLength());
}
// Set PK
if (icolumn instanceof PrimaryKeyColumn) {
lcolumn.setPrimaryKey(true);
lcolumn.setUnique(true);
// Add PK constraint
PrimaryKey lpk = new PrimaryKey();
lpk.setTable(ltable);
lpk.setName(itable.getPrimaryKeyConstraint().getName());
lpk.getColumnNamesAsList().add(lcolumn.getName());
snapshot.getPrimaryKeys().add(lpk);
}
// Add column
ltable.getColumns().add(lcolumn);
}
// Add table
snapshot.getTables().add(ltable);
}
}
Aggregations