Search in sources :

Example 1 with PrimaryKeyColumn

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

Aggregations

Database (liquibase.database.Database)1 UnsupportedDatabase (liquibase.database.core.UnsupportedDatabase)1 Column (liquibase.database.structure.Column)1 PrimaryKey (liquibase.database.structure.PrimaryKey)1 Table (liquibase.database.structure.Table)1 PrimaryKeyColumn (org.openforis.collect.relational.model.PrimaryKeyColumn)1