]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7135 WS api/measures/component_tree search query must match exactly the compone...
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 15 Jan 2016 10:54:58 +0000 (11:54 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 15 Jan 2016 10:55:34 +0000 (11:55 +0100)
sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java

index 6d92ed2c93267317aaf1494f0c6eb2b694904e6f..32087814dbd2ba74fe860b668f7422fc3897700b 100644 (file)
         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>
       </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>
 
index 9a8e159e4bde2f8ee433b508c12dc130b0eca4e8..e739cba9096cb70d47819c9f78ad9251492b6119 100644 (file)
@@ -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);