Search in sources :

Example 1 with Table

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);
    }
}
Also used : Table(liquibase.database.structure.Table) PrimaryKeyColumn(org.openforis.collect.relational.model.PrimaryKeyColumn) Column(liquibase.database.structure.Column) Index(liquibase.database.structure.Index) PrimaryKeyConstraint(org.openforis.collect.relational.model.PrimaryKeyConstraint)

Example 2 with Table

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);
}
Also used : Table(liquibase.database.structure.Table) DatabaseException(liquibase.exception.DatabaseException)

Example 3 with 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);
        }
    }
}
Also used : Table(liquibase.database.structure.Table) ReferentialConstraint(org.openforis.collect.relational.model.ReferentialConstraint) UniquenessConstraint(org.openforis.collect.relational.model.UniquenessConstraint) ForeignKey(liquibase.database.structure.ForeignKey)

Example 4 with Table

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);
    }
}
Also used : PrimaryKeyColumn(org.openforis.collect.relational.model.PrimaryKeyColumn) Table(liquibase.database.structure.Table) PrimaryKeyColumn(org.openforis.collect.relational.model.PrimaryKeyColumn) Column(liquibase.database.structure.Column) Database(liquibase.database.Database) UnsupportedDatabase(liquibase.database.core.UnsupportedDatabase) PrimaryKey(liquibase.database.structure.PrimaryKey)

Example 5 with Table

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;
}
Also used : Table(liquibase.database.structure.Table)

Aggregations

Table (liquibase.database.structure.Table)6 Column (liquibase.database.structure.Column)2 DatabaseException (liquibase.exception.DatabaseException)2 PrimaryKeyColumn (org.openforis.collect.relational.model.PrimaryKeyColumn)2 Database (liquibase.database.Database)1 UnsupportedDatabase (liquibase.database.core.UnsupportedDatabase)1 ForeignKey (liquibase.database.structure.ForeignKey)1 Index (liquibase.database.structure.Index)1 PrimaryKey (liquibase.database.structure.PrimaryKey)1 PrimaryKeyConstraint (org.openforis.collect.relational.model.PrimaryKeyConstraint)1 ReferentialConstraint (org.openforis.collect.relational.model.ReferentialConstraint)1 UniquenessConstraint (org.openforis.collect.relational.model.UniquenessConstraint)1 CodeList (org.openforis.idm.metamodel.CodeList)1