Search in sources :

Example 1 with CollectCreateIndexStep

use of org.jooq.CollectCreateIndexStep 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

CollectCreateIndexStep (org.jooq.CollectCreateIndexStep)1 Record (org.jooq.Record)1 CodeListCodeColumn (org.openforis.collect.relational.model.CodeListCodeColumn)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1