diff options
author | David Gageot <david@gageot.net> | 2012-07-11 17:04:02 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-11 17:38:40 +0200 |
commit | 8c1b42c30880a7a12af839d264f415bb49d4de9a (patch) | |
tree | 391e01fc2c3c90569d992a9f892abc9cd6390932 /sonar-batch | |
parent | cd2d985404cbe202d55f4024c3aa64bf1f186839 (diff) | |
download | sonarqube-8c1b42c30880a7a12af839d264f415bb49d4de9a.tar.gz sonarqube-8c1b42c30880a7a12af839d264f415bb49d4de9a.zip |
SONAR-3437 merge Mappers
Diffstat (limited to 'sonar-batch')
4 files changed, 15 insertions, 15 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 0c0cf825354..4ccc106b70a 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 @@ -85,11 +85,12 @@ public final class MeasurePersister { } private MeasureModel insertOrUpdate(Resource resource, Measure measure) { + Snapshot snapshot = resourcePersister.getSnapshotOrFail(resource); if (measure.getId() != null) { - return update(measure); + return update(measure, snapshot); } if (shouldPersistMeasure(resource, measure)) { - return insert(measure, resourcePersister.getSnapshotOrFail(resource)); + return insert(measure, snapshot); } return null; } @@ -218,9 +219,10 @@ public final class MeasurePersister { return value; } - private MeasureModel update(Measure measure) { + private MeasureModel update(Measure measure, Snapshot snapshot) { MeasureModel value = model(measure); value.setId(measure.getId()); + value.setSnapshotId(snapshot.getId()); SqlSession session = mybatis.openSession(); try { 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 4e7f37add5d..26615c99a82 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 @@ -122,7 +122,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0)); - assertEmptyTables("project_measures"); + assertEmptyTables("project_measures", "measure_data"); } @Test @@ -131,7 +131,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(aFile, new Measure("ncloc").setPersistenceMode(PersistenceMode.MEMORY)); - assertEmptyTables("project_measures"); + assertEmptyTables("project_measures", "measure_data"); } @Test @@ -150,9 +150,9 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.saveMeasure(project, new Measure(coverage()).setValue(12.5).setId(1L)); measurePersister.saveMeasure(project, new Measure(coverage()).setData(SHORT).setId(2L)); - measurePersister.saveMeasure(project, new Measure(coverage()).setData(LONG).setId(3L)); + measurePersister.saveMeasure(aPackage, new Measure(coverage()).setData(LONG).setId(3L)); - checkTables("shouldUpdateMeasure", "project_measures"); + checkTables("shouldUpdateMeasure", "project_measures", "measure_data"); } @Test @@ -180,7 +180,7 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { assertEmptyTables("project_measures"); measurePersister.dump(); - checkTables("shouldDelaySaving", "project_measures"); + checkTables("shouldDelaySaving", "project_measures", "measure_data"); } @Test @@ -201,11 +201,11 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { measurePersister.setDelayedMode(true); measurePersister.saveMeasure(aFile, new Measure(coverage()).setValue(100.0)); - assertEmptyTables("project_measures"); + assertEmptyTables("project_measures", "measure_data"); measurePersister.dump(); - assertEmptyTables("project_measures"); + assertEmptyTables("project_measures", "measure_data"); } @Test diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml index 2db0aca4e4d..b64b9b2d480 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/data.xml @@ -12,12 +12,10 @@ person_id="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> - <project_measures id="3" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" + <project_measures id="3" VALUE="60" METRIC_ID="2" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> - <measure_data id="1" measure_id="2" snapshot_id="3001" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> - </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml index e1db7336b32..22201f588e4 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml @@ -12,12 +12,12 @@ person_id="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> - <project_measures id="3" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3001" alert_text="[null]" RULES_CATEGORY_ID="[null]" + <project_measures id="3" VALUE="[null]" METRIC_ID="2" SNAPSHOT_ID="3002" alert_text="[null]" RULES_CATEGORY_ID="[null]" RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]" rule_priority="[null]" characteristic_id="[null]" url="[null]" person_id="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]" variation_value_5="[null]"/> - <measure_data id="1" measure_id="3" snapshot_id="3001" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> + <measure_data id="1" measure_id="3" snapshot_id="3002" data="MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OQ=="/> </dataset> |