diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-11-24 14:16:57 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-11-25 15:33:07 +0100 |
commit | 72a252ae0f8e6b6f9d54aade3188f4d6c9c2fcb7 (patch) | |
tree | 2c2bfaf3f513344c466cabcf5f3a2ec89fd2a337 /sonar-db | |
parent | 63bd0008b7563283652b35000cd002b00ef37532 (diff) | |
download | sonarqube-72a252ae0f8e6b6f9d54aade3188f4d6c9c2fcb7.tar.gz sonarqube-72a252ae0f8e6b6f9d54aade3188f4d6c9c2fcb7.zip |
SONAR-7027 add MeasureDao#selectBySnapshotAndMetrics
Diffstat (limited to 'sonar-db')
4 files changed, 64 insertions, 0 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java index 13b27d68768..23458f0b882 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -93,6 +93,19 @@ public class MeasureDao implements Dao { }); } + /** + * Used by plugin Developer Cockpit + */ + public List<MeasureDto> selectBySnapshotAndMetrics(final DbSession dbSession, final long snapshotId, Collection<Integer> metricIds) { + return DatabaseUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<MeasureDto>>() { + @Override + @Nonnull + public List<MeasureDto> apply(@Nonnull List<Integer> input) { + return mapper(dbSession).selectBySnapshotAndMetrics(snapshotId, input); + } + }); + } + public void insert(DbSession session, MeasureDto measureDto) { mapper(session).insert(measureDto); } diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java index fc6debc0a62..a5b096001f8 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java @@ -34,6 +34,8 @@ public interface MeasureMapper { List<MeasureDto> selectByDeveloperForSnapshotAndMetrics(@Param("developerId") long developerId, @Param("snapshotId") long snapshotId, @Param("metricIds") List<Integer> metricIds); + List<MeasureDto> selectBySnapshotAndMetrics(@Param("snapshotId") long snapshotId, @Param("metricIds") List<Integer> input); + @CheckForNull MeasureDto selectByComponentAndMetric(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey); diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 7874e1e2d20..f2d22396374 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -92,6 +92,22 @@ </where> </select> + <select id="selectBySnapshotAndMetrics" parameterType="map" resultType="Measure"> + SELECT + <include refid="measureColumns"/> + FROM project_measures pm + <where> + pm.snapshot_id = #{snapshotId} + AND pm.rule_id is NULL + AND pm.characteristic_id is NULL + AND pm.person_id is NULL + AND + <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")"> + pm.metric_id=#{metricId} + </foreach> + </where> + </select> + <select id="countByComponentAndMetric" parameterType="map" resultType="long"> SELECT count(pm.id) FROM project_measures pm diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 60538b15b0e..87136d9ca75 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -359,6 +359,39 @@ public class MeasureDaoTest { } @Test + public void selectBySnapshotAndMetrics_returns_empty_when_single_metric_id_does_not_exist() { + db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml"); + + List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(), + SNAPSHOT_ID, + ImmutableList.of(666)); + + assertThat(measureDtos).isEmpty(); + } + + @Test + public void selectBySnapshotAndMetrics_returns_only_measures_not_for_developer() { + db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml"); + + List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(), + SNAPSHOT_ID, + ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID)); + + assertThat(measureDtos).extracting("id").containsOnly(20L, 21L, 22L); + } + + @Test + public void selectBySnapshotAndMetrics_returns_only_measures_not_for_developer_and_with_specified_metric_id() { + db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml"); + + List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(), + SNAPSHOT_ID, + ImmutableList.of(NCLOC_METRIC_ID)); + + assertThat(measureDtos).extracting("id").containsOnly(22L); + } + + @Test public void selectByDeveloperForSnapshotAndMetrics_returns_empty_when_single_metric_id_does_not_exist() { db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml"); |