aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-15 11:54:58 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-15 11:55:34 +0100
commit078c530623663185fab34680e09d54c43d014dc5 (patch)
treee611b24f522c3a9b7ff54a336bd38c2ba8c62647 /sonar-db
parent732c9b62a2bdcbe26b374b12f69aa0707d5428ed (diff)
downloadsonarqube-078c530623663185fab34680e09d54c43d014dc5.tar.gz
sonarqube-078c530623663185fab34680e09d54c43d014dc5.zip
SONAR-7135 WS api/measures/component_tree search query must match exactly the component key
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml38
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java4
2 files changed, 22 insertions, 20 deletions
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 6d92ed2c932..32087814dbd 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
@@ -287,17 +287,18 @@
AND p.language = #{query.language}
</if>
<if test="query.nameOrKeyQuery!=null">
- AND (exists (
- select 1
- from resource_index ri
- where
- ri.resource_id=p.id
- AND ri.qualifier in
- <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
- #{qualifier}
- </foreach>
- AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
- OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/')
+ AND (
+ exists (
+ select 1
+ from resource_index ri
+ where
+ ri.resource_id=p.id
+ AND ri.qualifier in
+ <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
+ #{qualifier}
+ </foreach>
+ AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
+ OR p.kee = #{query.nameOrKeyQuery})
</if>
</where>
</sql>
@@ -351,13 +352,14 @@
</foreach>
</if>
<if test="query.nameOrKeyQuery!=null">
- AND (exists (
- select 1
- from resource_index ri
- where
- (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id)
- AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
- OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/')
+ AND (
+ exists (
+ select 1
+ from resource_index ri
+ where
+ (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id)
+ AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
+ OR p.kee = #{query.nameOrKeyQuery})
</if>
</sql>
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 9a8e159e4bd..e739cba9096 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -712,7 +712,7 @@ public class ComponentDaoTest {
db.commit();
componentDb.indexProjects();
- ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-").setQualifiers(Qualifiers.PROJECT).build();
+ ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(Qualifiers.PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
assertThat(result).hasSize(1);
@@ -782,7 +782,7 @@ public class ComponentDaoTest {
componentDb.indexProjects();
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
- .setNameOrKeyQuery("file-key").build();
+ .setNameOrKeyQuery("file-key-1").build();
List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
int count = underTest.countDirectChildren(dbSession, query);