summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-02 09:13:09 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-02 09:13:09 +0200
commit79fc72db28d21def2db78fa113e370b46065f96c (patch)
treed951947c71c910a91a16bbc9145a88079d3a4891 /sonar-batch
parentdfb3d2fc8cd965158e4335362adf31fb88d385a7 (diff)
downloadsonarqube-79fc72db28d21def2db78fa113e370b46065f96c.tar.gz
sonarqube-79fc72db28d21def2db78fa113e370b46065f96c.zip
Revert "SONAR-3437 Enable batch mode when saving measures into DB"
This reverts commit 1b84be0cba036bc7d782f9191874bf144c6fe534.
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java13
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java4
2 files changed, 10 insertions, 7 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 2edf522df7a..09dfd493df2 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,6 +20,7 @@
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;
@@ -34,7 +35,6 @@ 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() {
- DbSession session = mybatis.openSession(true);
+ SqlSession session = mybatis.openSession();
try {
MeasureMapper mapper = session.getMapper(MeasureMapper.class);
@@ -67,13 +67,16 @@ public final class MeasurePersister implements ScanPersister {
if (shouldPersistMeasure(resource, measure)) {
Snapshot snapshot = snapshotCache.get(effectiveKey);
MeasureModel measureModel = model(measure).setSnapshotId(snapshot.getId());
- mapper.insert(measureModel);
+ 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);
+ }
}
}
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 feb8094889b..f0a2bb666aa 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_message_when_error_during_insert_measure() {
+ public void should_display_contextual_info_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 some measures");
+ thrown.expectMessage("Unable to save measure for metric [ncloc] on component [foo]");
measurePersister.persist();
}