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;
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
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 {
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() {
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 {
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
</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>
</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>
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)
@Test
public void build_query_minimal_properties() throws Exception {
- underTest = ComponentQuery.builder()
+ ComponentQuery underTest = ComponentQuery.builder()
.setQualifiers(PROJECT)
.build();
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%");
}
}
public class ComponentTreeQueryTest {
private static final String BASE_UUID = "ABCD";
+
@Rule
public ExpectedException expectedException = ExpectedException.none();
assertThat(query.getStrategy()).isEqualTo(CHILDREN);
assertThat(query.getQualifiers()).containsOnly("FIL", "DIR");
assertThat(query.getNameOrKeyQuery()).isEqualTo("teSt");
+ assertThat(query.getNameOrKeyUpperLikeQuery()).isEqualTo("%TEST%");
}
@Test
assertThat(query.getStrategy()).isEqualTo(CHILDREN);
assertThat(query.getQualifiers()).isNull();
assertThat(query.getNameOrKeyQuery()).isNull();
+ assertThat(query.getNameOrKeyUpperLikeQuery()).isNull();
}
@Test
}
@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