@Override
public void persist() {
// Don't use batch insert for duplications since keeping all data in memory can produce OOM
DbSession session = mybatis.openSession(false);
try {
MeasureMapper mapper = session.getMapper(MeasureMapper.class);
org.sonar.api.measures.Metric duplicationMetricWithId = metricFinder.findByKey(CoreMetrics.DUPLICATIONS_DATA_KEY);
for (Entry<List<DuplicationGroup>> entry : duplicationCache.entries()) {
String effectiveKey = entry.key()[0].toString();
Measure measure = new Measure(duplicationMetricWithId, DuplicationUtils.toXml(entry.value())).setPersistenceMode(PersistenceMode.DATABASE);
Resource resource = resourceCache.get(effectiveKey);
if (MeasurePersister.shouldPersistMeasure(resource, measure)) {
Snapshot snapshot = snapshotCache.get(effectiveKey);
MeasureModel measureModel = MeasurePersister.model(measure, ruleFinder).setSnapshotId(snapshot.getId());
mapper.insert(measureModel);
}
}
session.commit();
} catch (Exception e) {