Search in sources :

Example 1 with CodeListCodeColumn

use of org.openforis.collect.relational.model.CodeListCodeColumn in project collect by openforis.

the class CodeTableDataExtractor method createDefaultCodeRow.

protected Row createDefaultCodeRow() {
    Row row = new Row(table);
    List<Column<?>> columns = table.getColumns();
    for (int i = 0; i < columns.size(); i++) {
        @SuppressWarnings("rawtypes") Column col = columns.get(i);
        Object val;
        if (col instanceof CodePrimaryKeyColumn) {
            val = DEFAULT_CODE_ROW_ID;
        } else if (col instanceof CodeListCodeColumn) {
            val = table.getDefaultCode();
        } else if (col instanceof CodeLabelColumn) {
            val = table.getDefaultCodeLabel(((CodeLabelColumn) col).getLanguageCode());
        } else {
            val = null;
        }
        row.setValue(i, val);
    }
    return row;
}
Also used : CodeLabelColumn(org.openforis.collect.relational.model.CodeLabelColumn) CodeListDescriptionColumn(org.openforis.collect.relational.model.CodeListDescriptionColumn) CodeParentKeyColumn(org.openforis.collect.relational.model.CodeParentKeyColumn) CodePrimaryKeyColumn(org.openforis.collect.relational.model.CodePrimaryKeyColumn) Column(org.openforis.collect.relational.model.Column) CodeListCodeColumn(org.openforis.collect.relational.model.CodeListCodeColumn) CodeListCodeColumn(org.openforis.collect.relational.model.CodeListCodeColumn) Row(org.openforis.collect.relational.data.Row) CodePrimaryKeyColumn(org.openforis.collect.relational.model.CodePrimaryKeyColumn) CodeLabelColumn(org.openforis.collect.relational.model.CodeLabelColumn)

Example 2 with CodeListCodeColumn

use of org.openforis.collect.relational.model.CodeListCodeColumn in project collect by openforis.

the class JooqRelationalSchemaCreator method addCodeListsCodeIndexes.

private void addCodeListsCodeIndexes(RelationalSchema schema, CollectDSLContext dsl) {
    for (Table<?> table : schema.getTables()) {
        if (table instanceof CodeTable) {
            CodeTable codeTable = (CodeTable) table;
            org.jooq.Table<Record> jooqTable = jooqTable(schema, table, !dsl.isSchemaLess());
            CodeListCodeColumn codeColumn = codeTable.getCodeColumn();
            CollectCreateIndexStep createIndexStep = dsl.createIndex(table.getName() + "_code_idx");
            if (codeTable.getLevelIdx() == null || codeTable.getLevelIdx() == 0) {
                // unique index only for first level or when the code scope is 'scheme'
                createIndexStep.unique();
            }
            createIndexStep.on(jooqTable, field(codeColumn.getName())).execute();
        }
    }
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) CodeListCodeColumn(org.openforis.collect.relational.model.CodeListCodeColumn) CollectCreateIndexStep(org.jooq.CollectCreateIndexStep) Record(org.jooq.Record)

Aggregations

CodeListCodeColumn (org.openforis.collect.relational.model.CodeListCodeColumn)2 CollectCreateIndexStep (org.jooq.CollectCreateIndexStep)1 Record (org.jooq.Record)1 Row (org.openforis.collect.relational.data.Row)1 CodeLabelColumn (org.openforis.collect.relational.model.CodeLabelColumn)1 CodeListDescriptionColumn (org.openforis.collect.relational.model.CodeListDescriptionColumn)1 CodeParentKeyColumn (org.openforis.collect.relational.model.CodeParentKeyColumn)1 CodePrimaryKeyColumn (org.openforis.collect.relational.model.CodePrimaryKeyColumn)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 Column (org.openforis.collect.relational.model.Column)1