Search in sources :

Example 1 with OfcCodeListRecord

use of org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord in project collect by openforis.

the class CodeListItemDao method insert.

/**
 * Inserts the items in batch.
 *
 * @param items
 */
public void insert(List<PersistedCodeListItem> items) {
    if (items != null && items.size() > 0) {
        PersistedCodeListItem firstItem = items.get(0);
        CodeList list = firstItem.getCodeList();
        JooqDSLContext jf = dsl(list);
        int nextId = jf.nextId();
        int maxId = nextId;
        Insert<OfcCodeListRecord> query = jf.createInsertStatement();
        BatchBindStep batch = jf.batch(query);
        for (PersistedCodeListItem item : items) {
            Integer id = item.getSystemId();
            if (id == null) {
                id = nextId++;
                item.setSystemId(id);
            }
            List<Object> values = jf.extractValues(item);
            batch.bind(values.toArray(new Object[values.size()]));
            maxId = Math.max(maxId, id);
        }
        batch.execute();
        jf.restartSequence(maxId + 1);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) BatchBindStep(org.jooq.BatchBindStep) SurveyObject(org.openforis.idm.metamodel.SurveyObject) OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 2 with OfcCodeListRecord

use of org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord in project collect by openforis.

the class CodeListItemDao method removeLabels.

public void removeLabels(CollectSurvey survey, int fromLanguagePosition) {
    JooqDSLContext jf = dsl(null);
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList codeList : codeLists) {
        int codeListId = codeList.getId();
        Map<TableField<OfcCodeListRecord, String>, String> updateFields = new HashMap<TableField<OfcCodeListRecord, String>, String>();
        for (int i = fromLanguagePosition - 1; i < LABEL_FIELDS.length; i++) {
            @SuppressWarnings("unchecked") TableField<OfcCodeListRecord, String> labelField = LABEL_FIELDS[i];
            updateFields.put(labelField, (String) null);
        }
        jf.update(OFC_CODE_LIST).set(updateFields).where(OFC_CODE_LIST.SURVEY_ID.eq(survey.getId()).and(OFC_CODE_LIST.CODE_LIST_ID.eq(codeListId))).execute();
        if (isCacheInUse(codeList)) {
            cache.clearItemsByCodeList(codeList);
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) HashMap(java.util.HashMap) OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) TableField(org.jooq.TableField)

Example 3 with OfcCodeListRecord

use of org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord in project collect by openforis.

the class CodeListItemDao method createDeleteQuery.

protected DeleteConditionStep<OfcCodeListRecord> createDeleteQuery(CodeList list) {
    JooqDSLContext jf = dsl(null);
    CollectSurvey survey = (CollectSurvey) list.getSurvey();
    DeleteConditionStep<OfcCodeListRecord> q = jf.delete(OFC_CODE_LIST).where(OFC_CODE_LIST.SURVEY_ID.equal(survey.getId()), OFC_CODE_LIST.CODE_LIST_ID.equal(list.getId()));
    return q;
}
Also used : OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

OfcCodeListRecord (org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord)3 CodeList (org.openforis.idm.metamodel.CodeList)2 HashMap (java.util.HashMap)1 BatchBindStep (org.jooq.BatchBindStep)1 TableField (org.jooq.TableField)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1