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