aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-07 16:12:51 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-09-07 16:16:09 +0200
commit1737fa02b6e9fb52288e14696a1ecec1f52ad91b (patch)
tree72a254bc02b6c21b6390e3578a8b231d6375e85d /sonar-db
parent082546c283020089c17845b37778a0e420a93886 (diff)
downloadsonarqube-1737fa02b6e9fb52288e14696a1ecec1f52ad91b.tar.gz
sonarqube-1737fa02b6e9fb52288e14696a1ecec1f52ad91b.zip
SONAR-6749 Add query to get custom measures from a metric key and a text value
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java9
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java2
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml12
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml10
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java11
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/measure/custom/CustomMeasureDaoTest/select_by_metric_key_and_text_value.xml14
9 files changed, 50 insertions, 24 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
index 4b753923e85..2973460b1b3 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -239,15 +239,6 @@ public class ComponentDao implements Dao {
return mapper(dbSession).selectByProjectUuid(projectUuid);
}
- /**
- * Retrieves all components with a specific customer measure, no other filtering is done by this method.
- *
- * Used by Views plugin
- */
- public List<ComponentDto> selectByCustomMeasure(String metricKey, String metricValue, DbSession dbSession) {
- return mapper(dbSession).selectByCustomMeasure(metricKey, metricValue);
- }
-
private static void addPartialQueryParameterIfNotNull(Map<String, Object> parameters, @Nullable String keyOrNameFilter) {
if (keyOrNameFilter != null) {
parameters.put("query", "%" + keyOrNameFilter.toUpperCase() + "%");
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
index 1f405472d4f..4204f8ad370 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -55,8 +55,6 @@ public interface ComponentMapper {
List<ComponentDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
- List<ComponentDto> selectByCustomMeasure(@Param("metricKey") String metricKey, @Param("metricValue") String metricValue);
-
List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids);
/**
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
index 3689413a78e..90a5cd2e3f8 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
@@ -84,6 +84,13 @@ public class CustomMeasureDao implements Dao {
return mapper(session).selectByComponentUuid(componentUuid);
}
+ /**
+ * Used by Views plugin
+ */
+ public List<CustomMeasureDto> selectByMetricKeyAndTextValue(DbSession session, String metricKey, String textValue) {
+ return mapper(session).selectByMetricKeyAndTextValue(metricKey, textValue);
+ }
+
private CustomMeasureMapper mapper(DbSession session) {
return session.getMapper(CustomMeasureMapper.class);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
index c17e0228fd9..8de62f8b721 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
@@ -20,7 +20,11 @@
package org.sonar.db.measure.custom;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
public class CustomMeasureDto {
+
private long id;
private int metricId;
private String componentUuid;
@@ -49,11 +53,12 @@ public class CustomMeasureDto {
return this;
}
+ @CheckForNull
public String getTextValue() {
return textValue;
}
- public CustomMeasureDto setTextValue(String textValue) {
+ public CustomMeasureDto setTextValue(@Nullable String textValue) {
this.textValue = textValue;
return this;
}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
index cb029d6f7c8..d69733bcfe5 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
@@ -41,6 +41,8 @@ public interface CustomMeasureMapper {
List<CustomMeasureDto> selectByComponentUuid(String s, RowBounds rowBounds);
+ List<CustomMeasureDto> selectByMetricKeyAndTextValue(@Param("metricKey") String metricKey, @Param("textValue") String textValue);
+
int countByComponentUuid(String componentUuid);
int countByComponentIdAndMetricId(@Param("componentUuid") String componentUuid, @Param("metricId") int metricId);
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 86861586b7d..a3c2a787c13 100644
--- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -79,18 +79,6 @@
</where>
</select>
- <select id="selectResourcesByCustomerMeasure" parameterType="String" resultType="Component">
- SELECT
- <include refid="componentColumns"/>
- FROM projects p, metric m, manual_measures mm
- <where>
- m.name=#{metricKey}
- and mm.metric_id = m.id
- and mm.text_value=#{metricValue}
- and p.id=mm.resourceId
- </where>
- </select>
-
<select id="countById" parameterType="long" resultType="long">
SELECT count(p.id)
FROM projects p
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
index 8c264791389..722724332f9 100644
--- a/sonar-db/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
@@ -35,6 +35,16 @@
where m.component_uuid=#{componentUuid}
</select>
+ <select id="selectByMetricKeyAndTextValue" resultType="CustomMeasure">
+ SELECT
+ <include refid="selectColumns"/>
+ FROM manual_measures m
+ INNER JOIN metrics metric ON metric.id=m.metric_id AND metric.name=#{metricKey}
+ <where>
+ m.text_value=#{textValue}
+ </where>
+ </select>
+
<insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO manual_measures (
metric_id, component_uuid, value, text_value, user_login, description, created_at, updated_at
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
index 6090ddcf783..aaa68ff7347 100644
--- a/sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
@@ -157,4 +157,15 @@ public class CustomMeasureDaoTest {
underTest.selectOrFail(session, 42L);
}
+ @Test
+ public void select_by_metric_key_and_text_value() throws Exception {
+ db.prepareDbUnit(getClass(), "select_by_metric_key_and_text_value.xml");
+
+ List<CustomMeasureDto> result = underTest.selectByMetricKeyAndTextValue(session, "customKey", "value1");
+
+ assertThat(result).extracting("id").containsOnly(20L, 21L);
+
+ assertThat(underTest.selectByMetricKeyAndTextValue(session, "customKey", "unknown")).isEmpty();
+ assertThat(underTest.selectByMetricKeyAndTextValue(session, "unknown", "value1")).isEmpty();
+ }
}
diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/custom/CustomMeasureDaoTest/select_by_metric_key_and_text_value.xml b/sonar-db/src/test/resources/org/sonar/db/measure/custom/CustomMeasureDaoTest/select_by_metric_key_and_text_value.xml
new file mode 100644
index 00000000000..ff00f759c69
--- /dev/null
+++ b/sonar-db/src/test/resources/org/sonar/db/measure/custom/CustomMeasureDaoTest/select_by_metric_key_and_text_value.xml
@@ -0,0 +1,14 @@
+<dataset>
+
+ <metrics id="10" name="ncloc"/>
+ <metrics id="11" name="customKey"/>
+
+ <manual_measures id="20" metric_id="11" component_uuid="ABCD" value="[null]" text_value="value1"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+ <manual_measures id="21" metric_id="11" component_uuid="BCDE" value="[null]" text_value="value1"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+ <manual_measures id="22" metric_id="11" component_uuid="CDEF" value="[null]" text_value="value2"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+
+
+</dataset>