diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-05-01 00:15:44 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-05-05 09:07:55 +0200 |
commit | 91100b1cd572493142e2f3bd27ac4776fd8313e7 (patch) | |
tree | e7677f6d114a6253c19796564fdd537ac5972c17 /sonar-batch/src | |
parent | dc35542f2609c0377dc2a634df1dbd9684427561 (diff) | |
download | sonarqube-91100b1cd572493142e2f3bd27ac4776fd8313e7.tar.gz sonarqube-91100b1cd572493142e2f3bd27ac4776fd8313e7.zip |
SONAR-3437 Enable batch mode when saving measures into DB
Diffstat (limited to 'sonar-batch/src')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java | 13 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java | 4 |
2 files changed, 7 insertions, 10 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index 09dfd493df2..2edf522df7a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -20,7 +20,6 @@ package org.sonar.batch.index; import com.google.common.annotations.VisibleForTesting; -import org.apache.ibatis.session.SqlSession; import org.sonar.api.database.model.MeasureMapper; import org.sonar.api.database.model.MeasureModel; import org.sonar.api.database.model.Snapshot; @@ -35,6 +34,7 @@ import org.sonar.api.technicaldebt.batch.Characteristic; import org.sonar.api.utils.SonarException; import org.sonar.batch.index.Cache.Entry; import org.sonar.batch.scan.measure.MeasureCache; +import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; public final class MeasurePersister implements ScanPersister { @@ -55,7 +55,7 @@ public final class MeasurePersister implements ScanPersister { @Override public void persist() { - SqlSession session = mybatis.openSession(); + DbSession session = mybatis.openSession(true); try { MeasureMapper mapper = session.getMapper(MeasureMapper.class); @@ -67,16 +67,13 @@ public final class MeasurePersister implements ScanPersister { if (shouldPersistMeasure(resource, measure)) { Snapshot snapshot = snapshotCache.get(effectiveKey); MeasureModel measureModel = model(measure).setSnapshotId(snapshot.getId()); - try { - mapper.insert(measureModel); - } catch (Exception e) { - // SONAR-4066 - throw new SonarException(String.format("Unable to save measure for metric [%s] on component [%s]", measure.getMetricKey(), resource.getKey()), e); - } + mapper.insert(measureModel); } } session.commit(); + } catch (Exception e) { + throw new SonarException("Unable to save some measures", e); } finally { MyBatis.closeQuietly(session); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index f0a2bb666aa..feb8094889b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -97,14 +97,14 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { } @Test - public void should_display_contextual_info_when_error_during_insert_measure() { + public void should_display_message_when_error_during_insert_measure() { setupData("empty"); Measure measure = new Measure(ncloc()).setValue(1234.0).setAlertText(TOO_LONG); when(measureCache.entries()).thenReturn(Arrays.asList(new Cache.Entry<Measure>(new String[] {"foo", "ncloc"}, measure))); thrown.expect(SonarException.class); - thrown.expectMessage("Unable to save measure for metric [ncloc] on component [foo]"); + thrown.expectMessage("Unable to save some measures"); measurePersister.persist(); } |