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