Search in sources :

Example 1 with OfcSamplingDesignRecord

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

the class SamplingDesignDao method insert.

/**
 * Inserts the items in batch.
 *
 * @param taxa
 */
public void insert(List<SamplingDesignItem> items) {
    if (items != null && !items.isEmpty()) {
        SamplingDesignDSLContext dsl = dsl();
        int id = dsl.nextId(OFC_SAMPLING_DESIGN.ID, OFC_SAMPLING_DESIGN_ID_SEQ);
        int maxId = id;
        Insert<OfcSamplingDesignRecord> query = dsl.createInsertStatement();
        BatchBindStep batch = dsl.batch(query);
        for (SamplingDesignItem item : items) {
            if (item.getId() == null) {
                item.setId(id++);
            }
            Object[] values = dsl.extractValues(item);
            batch.bind(values);
            maxId = Math.max(maxId, item.getId());
        }
        batch.execute();
        dsl.restartSequence(OFC_SAMPLING_DESIGN_ID_SEQ, maxId + 1);
    }
}
Also used : BatchBindStep(org.jooq.BatchBindStep) OfcSamplingDesignRecord(org.openforis.collect.persistence.jooq.tables.records.OfcSamplingDesignRecord) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Aggregations

BatchBindStep (org.jooq.BatchBindStep)1 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)1 OfcSamplingDesignRecord (org.openforis.collect.persistence.jooq.tables.records.OfcSamplingDesignRecord)1