use of liquibase.database.structure.Table 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 liquibase.database.structure.Table in project collect by openforis.
the class IdmDatabaseSnapshotBuilder method createDataTable.
private void createDataTable(Transformation xform) throws DatabaseException {
Set<Table> tables = snapshot.getTables();
// EntityDefinition defn = (EntityDefinition) xform.getNodeDefinition();
IdmDataTableBuilder dtb = new IdmDataTableBuilder(xform);
dtb.setTablePrefix(tablePrefix);
dtb.setTableSuffix(dataTableSuffix);
Table table = dtb.toTable();
if (tables.contains(table)) {
throw new DatabaseException("Duplicate table name '" + table.getName() + "' for " + xform.getRowAxis());
}
tables.add(table);
}
use of liquibase.database.structure.Table in project collect by openforis.
the class LiquidbaseDatabaseSnapshotBuilder method createForeignKeys.
protected void createForeignKeys() {
for (org.openforis.collect.relational.model.Table<?> itable : schema.getTables()) {
Table ltable = snapshot.getTable(itable.getName());
List<ReferentialConstraint> ifks = itable.getReferentialContraints();
for (ReferentialConstraint ifk : ifks) {
ForeignKey lfk = new ForeignKey();
lfk.setName(ifk.getName());
// set base table columns
lfk.setForeignKeyTable(ltable);
for (org.openforis.collect.relational.model.Column<?> ifcCol : ifk.getColumns()) {
lfk.addForeignKeyColumn(ifcCol.getName());
}
// set referenced key columns
UniquenessConstraint iReferencedKey = ifk.getReferencedKey();
org.openforis.collect.relational.model.Table<?> iReferencedTable = iReferencedKey.getTable();
Table lReferencedTable = snapshot.getTable(iReferencedTable.getName());
lfk.setPrimaryKeyTable(lReferencedTable);
for (org.openforis.collect.relational.model.Column<?> refCol : iReferencedKey.getColumns()) {
lfk.addPrimaryKeyColumn(refCol.getName());
}
// Add fk
snapshot.getForeignKeys().add(lfk);
}
}
}
use of liquibase.database.structure.Table 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);
}
}
use of liquibase.database.structure.Table in project collect by openforis.
the class AbstractIdmTableBuilder method toTable.
public Table toTable() {
// Create table
String name = getName();
this.table = new Table(name);
createColumns();
return table;
}
Aggregations