diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-23 20:58:25 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-25 11:41:56 +0100 |
commit | 66def28825633abed23e037f58502ea9278fd755 (patch) | |
tree | 9c96d94f27b91b0a22fa79422dc41babc10837a4 /sonar-db | |
parent | 79d2ca13d81462168cba7197fcd6e8de868de53a (diff) | |
download | sonarqube-66def28825633abed23e037f58502ea9278fd755.tar.gz sonarqube-66def28825633abed23e037f58502ea9278fd755.zip |
SONAR-8675 remove joins on resource_index in ComponentMapper
Diffstat (limited to 'sonar-db')
7 files changed, 38 insertions, 62 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java index 58771e1e140..1d0f82addb8 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java @@ -23,10 +23,10 @@ import java.util.Locale; import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.sonar.db.WildcardPosition; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.db.DatabaseUtils.buildLikeValue; -import static org.sonar.db.WildcardPosition.AFTER; public class ComponentQuery { private final String nameOrKeyQuery; @@ -64,14 +64,12 @@ public class ComponentQuery { return nameOrKeyQuery; } + /** + * Used by MyBatis mapper + */ @CheckForNull - public String getNameOrKeyQueryToSqlForResourceIndex() { - return buildLikeValue(nameOrKeyQuery, AFTER).toLowerCase(Locale.ENGLISH); - } - - @CheckForNull - public String getNameOrKeyQueryToSqlForProjectKey() { - return buildLikeValue(nameOrKeyQuery, AFTER); + public String getNameOrKeyUpperLikeQuery() { + return buildLikeValue(nameOrKeyQuery, WildcardPosition.BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); } @CheckForNull diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java index 5405f9cb364..1e9a03a78a4 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java @@ -29,7 +29,7 @@ import org.sonar.db.WildcardPosition; import static com.google.common.collect.Lists.newArrayList; import static java.util.Objects.requireNonNull; import static org.sonar.db.DatabaseUtils.buildLikeValue; -import static org.sonar.db.WildcardPosition.AFTER; +import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER; public class ComponentTreeQuery { @@ -62,9 +62,12 @@ public class ComponentTreeQuery { return nameOrKeyQuery; } + /** + * Used by MyBatis mapper + */ @CheckForNull - public String getNameOrKeyQueryToSqlForResourceIndex() { - return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER).toLowerCase(Locale.ENGLISH); + public String getNameOrKeyUpperLikeQuery() { + return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); } public String getBaseUuid() { diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java index 8ccd5a6a85d..19970bd24db 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java @@ -29,7 +29,7 @@ import org.sonar.db.component.ComponentDto; import static com.google.common.collect.Lists.newArrayList; import static java.util.Objects.requireNonNull; import static org.sonar.db.DatabaseUtils.buildLikeValue; -import static org.sonar.db.WildcardPosition.AFTER; +import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER; public class MeasureTreeQuery { @@ -63,9 +63,12 @@ public class MeasureTreeQuery { return nameOrKeyQuery; } + /** + * Used by MyBatis mapper + */ @CheckForNull - public String getNameOrKeyQueryToSqlForResourceIndex() { - return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER).toLowerCase(Locale.ENGLISH); + public String getNameOrKeyUpperLikeQuery() { + return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH); } @CheckForNull 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 3ff8987b017..0607cbce185 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 @@ -258,20 +258,10 @@ </foreach> </if> <if test="query.nameOrKeyQuery!=null"> - AND ( - p.kee=#{query.nameOrKeyQuery,jdbcType=VARCHAR} - OR - p.uuid IN ( - SELECT ri.component_uuid - FROM resource_index ri - WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' - <if test="query.qualifiers!=null"> - AND ri.qualifier in - <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=","> - #{qualifier,jdbcType=VARCHAR} - </foreach> - </if> - ) + and ( + p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} + or + upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' ) </if> </sql> @@ -308,19 +298,9 @@ </if> <if test="query.nameOrKeyQuery != null"> and ( - p.kee=#{query.nameOrKeyQuery} - or - p.uuid IN ( - SELECT ri.component_uuid - FROM resource_index ri - WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' - ) - or - p.copy_component_uuid IN ( - SELECT ri.component_uuid - FROM resource_index ri - WHERE ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/' - ) + p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR} + or + upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/' ) </if> </sql> diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java index ebf181d5847..f81cf160dd9 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java @@ -27,14 +27,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.resources.Qualifiers.PROJECT; public class ComponentQueryTest { + @Rule public ExpectedException expectedException = ExpectedException.none(); - ComponentQuery underTest; - @Test public void build_query() throws Exception { - underTest = ComponentQuery.builder() + ComponentQuery underTest = ComponentQuery.builder() .setNameOrKeyQuery("key") .setLanguage("java") .setQualifiers(PROJECT) @@ -47,7 +46,7 @@ public class ComponentQueryTest { @Test public void build_query_minimal_properties() throws Exception { - underTest = ComponentQuery.builder() + ComponentQuery underTest = ComponentQuery.builder() .setQualifiers(PROJECT) .build(); @@ -61,26 +60,16 @@ public class ComponentQueryTest { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("At least one qualifier must be provided"); - underTest = ComponentQuery.builder().setLanguage("java").build(); + ComponentQuery.builder().setLanguage("java").build(); } @Test - public void test_getNameOrKeyQueryToSqlForResourceIndex() throws Exception { - underTest = ComponentQuery.builder() + public void test_getNameOrKeyUpperLikeQuery() throws Exception { + ComponentQuery underTest = ComponentQuery.builder() .setNameOrKeyQuery("NAME/key") .setQualifiers(PROJECT) .build(); - assertThat(underTest.getNameOrKeyQueryToSqlForResourceIndex()).isEqualTo("name//key%"); - } - - @Test - public void test_getNameOrKeyQueryToSqlForProjectKey() throws Exception { - underTest = ComponentQuery.builder() - .setNameOrKeyQuery("name/key") - .setQualifiers(PROJECT) - .build(); - - assertThat(underTest.getNameOrKeyQueryToSqlForProjectKey()).isEqualTo("name//key%"); + assertThat(underTest.getNameOrKeyUpperLikeQuery()).isEqualTo("%NAME//KEY%"); } } diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java index 817f2f0ecfd..813ccf1502f 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java @@ -33,6 +33,7 @@ import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; public class ComponentTreeQueryTest { private static final String BASE_UUID = "ABCD"; + @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -49,6 +50,7 @@ public class ComponentTreeQueryTest { assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).containsOnly("FIL", "DIR"); assertThat(query.getNameOrKeyQuery()).isEqualTo("teSt"); + assertThat(query.getNameOrKeyUpperLikeQuery()).isEqualTo("%TEST%"); } @Test @@ -62,6 +64,7 @@ public class ComponentTreeQueryTest { assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).isNull(); assertThat(query.getNameOrKeyQuery()).isNull(); + assertThat(query.getNameOrKeyUpperLikeQuery()).isNull(); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java index 3620cd3cc7b..90db7f36863 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java @@ -68,15 +68,15 @@ public class MeasureTreeQueryTest { } @Test - public void test_getNameOrKeyQueryToSqlForResourceIndex() throws Exception { + public void test_getNameOrKeyUpperLikeQuery() throws Exception { assertThat(MeasureTreeQuery.builder() .setNameOrKeyQuery("like-\\_%/-value") .setStrategy(CHILDREN) - .build().getNameOrKeyQueryToSqlForResourceIndex()).isEqualTo("like-\\/_/%//-value%"); + .build().getNameOrKeyUpperLikeQuery()).isEqualTo("%LIKE-\\/_/%//-VALUE%"); assertThat(MeasureTreeQuery.builder() .setStrategy(CHILDREN) - .build().getNameOrKeyQueryToSqlForResourceIndex()).isNull(); + .build().getNameOrKeyUpperLikeQuery()).isNull(); } @Test |