Search in sources :

Example 1 with OfcTaxonRecord

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

the class TaxonDao method insert.

/**
 * Inserts the items in batch.
 */
public void insert(CollectTaxonomy taxonomy, List<Taxon> items) {
    if (items != null && !items.isEmpty()) {
        TaxonDSLContext dsl = dsl(taxonomy);
        int id = dsl.nextId(OFC_TAXON.ID, OFC_TAXON_ID_SEQ);
        int maxId = id;
        Insert<OfcTaxonRecord> query = dsl.createInsertStatement();
        BatchBindStep batch = dsl.batch(query);
        for (Taxon item : items) {
            if (item.getSystemId() == null) {
                item.setSystemId(id++);
            }
            Object[] values = dsl.extractValues(item);
            batch.bind(values);
            maxId = Math.max(maxId, item.getSystemId());
        }
        batch.execute();
        dsl.restartSequence(OFC_TAXON_ID_SEQ, maxId + 1);
    }
}
Also used : BatchBindStep(org.jooq.BatchBindStep) Taxon(org.openforis.idm.model.species.Taxon) OfcTaxonRecord(org.openforis.collect.persistence.jooq.tables.records.OfcTaxonRecord)

Aggregations

BatchBindStep (org.jooq.BatchBindStep)1 OfcTaxonRecord (org.openforis.collect.persistence.jooq.tables.records.OfcTaxonRecord)1 Taxon (org.openforis.idm.model.species.Taxon)1