}
SqlSession session = mybatis.openSession();
try {
+ List<ActionPlanDto> dtosList = newArrayList();
List<List<String>> keysPartition = Lists.partition(newArrayList(keys), 1000);
- return session.getMapper(ActionPlanMapper.class).findByKeys(keysPartition);
+ for (List<String> partition : keysPartition) {
+ List<ActionPlanDto> dtos = session.getMapper(ActionPlanMapper.class).findByKeys(partition);
+ dtosList.addAll(dtos);
+ }
+ return dtosList;
} finally {
MyBatis.closeQuietly(session);
}
void delete(@Param("key") String key);
- List<ActionPlanDto> findByKeys(@Param("keys") List<List<String>> keys);
+ List<ActionPlanDto> findByKeys(@Param("keys") List<String> keys);
ActionPlanDto findByKey(@Param("key") String key);
return Collections.emptyList();
}
IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
-
+ List<IssueChangeDto> dtosList = newArrayList();
List<List<String>> keysPartition = Lists.partition(newArrayList(issueKeys), 1000);
- return mapper.selectByIssuesAndType(keysPartition, changeType);
+ for (List<String> partition : keysPartition) {
+ List<IssueChangeDto> dtos = mapper.selectByIssuesAndType(partition, changeType);
+ dtosList.addAll(dtos);
+ }
+ return dtosList;
}
public boolean delete(String key) {
/**
* Issue changes by chronological date of creation
*/
- List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<List<String>> issueKeys,
+ List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<String> issueKeys,
@Param("changeType") String changeType);
List<IssueChangeDto> selectByIssue(String issueKey);
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Maps.newHashMap;
/**
* @since 3.6
private List<IssueDto> selectIssueIds(IssueQuery query, @Nullable Integer userId, Integer maxResults, SqlSession session){
IssueMapper mapper = session.getMapper(IssueMapper.class);
- return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole(), maxResults, true);
+ return mapper.selectIssueIds(query, query.componentRoots(), userId, query.requiredRole(), maxResults);
}
public List<IssueDto> selectIssues(IssueQuery query) {
SqlSession session = mybatis.openSession();
try {
- return selectIssues(query, null, Integer.MAX_VALUE, session);
+ return selectIssues(query, null, session);
} finally {
MyBatis.closeQuietly(session);
}
}
public List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, SqlSession session){
- return selectIssues(query, userId, query.maxResults(), session);
- }
-
- public List<IssueDto> selectIssues(IssueQuery query, @Nullable Integer userId, Integer maxResults, SqlSession session){
IssueMapper mapper = session.getMapper(IssueMapper.class);
- return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole(), maxResults, false);
+ return mapper.selectIssues(query, query.componentRoots(), userId, query.requiredRole());
}
@VisibleForTesting
if (ids.isEmpty()) {
return Collections.emptyList();
}
- Object idsPartition = Lists.partition(newArrayList(ids), 1000);
- Map<String, Object> params = newHashMap();
- params.put("ids", idsPartition);
- return session.selectList("org.sonar.core.issue.db.IssueMapper.selectByIds", params);
+ List<IssueDto> dtosList = newArrayList();
+ List<List<Long>> idsPartitionList = Lists.partition(newArrayList(ids), 1000);
+ for (List<Long> idsPartition : idsPartitionList) {
+ List<IssueDto> dtos = session.selectList("org.sonar.core.issue.db.IssueMapper.selectByIds", newArrayList(idsPartition));
+ dtosList.addAll(dtos);
+ }
+ return dtosList;
}
}
}
SqlSession session = mybatis.openSession();
try {
+
+ List<ResourceDto> resources = newArrayList();
List <List<Long>> idsPartition = Lists.partition(newArrayList(ids), 1000);
- Collection<ResourceDto> resources = session.getMapper(ResourceMapper.class).selectResourcesById(idsPartition);
+ for (List<Long> partition : idsPartition) {
+ List<ResourceDto> dtos = session.getMapper(ResourceMapper.class).selectResourcesById(partition);
+ resources.addAll(dtos);
+ }
+
Collection<Component> components = newArrayList();
for (ResourceDto resourceDto : resources) {
components.add(toComponent(resourceDto));
/**
* @since3.6
*/
- List<ResourceDto> selectResourcesById(@Param("ids") List <List<Long>> ids);
+ List<ResourceDto> selectResourcesById(@Param("ids") List<Long> ids);
/**
* @since 3.6
select <include refid="actionPlanColumns"/>
from action_plans ap, projects p
<where>
- <foreach collection="keys" open="ap.kee in (" close=")" item="list" separator=") or ap.kee in (" >
- <foreach collection="list" item="element" separator=",">
- #{element}
- </foreach>
+ and ap.kee in
+ <foreach collection="keys" open="(" close=")" item="key" separator=",">
+ #{key}
</foreach>
and ap.project_id=p.id
</where>
select
<include refid="issueChangeColumns"/>
from issue_changes c
- where c.change_type=#{changeType} and (
- <foreach collection="issueKeys" open="c.issue_key in (" close=")" item="list" separator=") or c.issue_key in (">
- <foreach collection="list" item="element" separator=",">
- #{element}
- </foreach>
- </foreach>)
+ where c.change_type=#{changeType} and c.issue_key in
+ <foreach collection="issueKeys" open="(" close=")" item="key" separator=",">
+ #{key}
+ </foreach>
order by c.created_at
</select>
inner join projects p on p.id=i.component_id
inner join projects root on root.id=i.root_component_id
<where>
- and
- <foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (">
- <foreach collection="list" item="element" separator=",">
- #{element}
- </foreach>
+ and i.id in
+ <foreach collection="list" open="(" close=")" item="id" separator=",">
+ #{id}
</foreach>
</where>
</select>
</select>
<select id="selectResourcesById" parameterType="map" resultMap="resourceResultMap">
- select * from projects p where p.enabled=${_true} and
- <foreach collection="ids" open="p.id in (" close=")" item="list" separator=") or p.id in (" >
- <foreach collection="list" item="element" separator=",">
- #{element}
- </foreach>
+ select * from projects p where p.enabled=${_true}
+ and p.id in
+ <foreach collection="ids" open="(" close=")" item="key" separator=",">
+ #{key}
</foreach>
</select>
package org.sonar.core.issue.db;
+import org.apache.ibatis.session.SqlSession;
import org.junit.Before;
import org.junit.Test;
import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.persistence.MyBatis;
import java.util.Collection;
+import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
assertThat(result).hasSize(3);
}
+ @Test
+ public void should_find_by_keys_on_huge_number_of_keys() {
+ setupData("shared");
+
+ SqlSession session = getMyBatis().openSession();
+ List<String> hugeNbOKeys = newArrayList();
+ for (int i=0; i<4500; i++) {
+ hugeNbOKeys.add("ABCD" + i);
+ }
+ List<ActionPlanDto> result = dao.findByKeys(hugeNbOKeys);
+ MyBatis.closeQuietly(session);
+
+ // The goal of this test is only to check that the query do no fail, not to check the number of results
+ assertThat(result).isEmpty();
+ }
+
@Test
public void should_find_open_by_project_id() {
setupData("shared", "should_find_open_by_project_id");
SqlSession session = getMyBatis().openSession();
List<String> hugeNbOfIssues = newArrayList();
- for (int i=0; i<1500; i++) {
+ for (int i=0; i<4500; i++) {
hugeNbOfIssues.add("ABCD"+i);
}
List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, hugeNbOfIssues);
setupData("shared");
List<Long> hugeNbOfIssues = newArrayList();
- for (long i=0; i<1500; i++) {
+ for (long i=0; i<4500; i++) {
hugeNbOfIssues.add(i);
}
List<IssueDto> results = dao.selectByIds(hugeNbOfIssues);
assertThat(component.qualifier()).isNotNull();
}
+ @Test
+ public void should_find_components_by_resource_ids_on_huge_number_of_ids() {
+ setupData("fixture");
+
+ List<Long> hugeNbOfIds = newArrayList();
+ for (long i=0; i<4500; i++) {
+ hugeNbOfIds.add(i);
+ }
+ Collection<Component> results = dao.findByIds(hugeNbOfIds);
+
+ // The goal of this test is only to check that the query do no fail, not to check the number of results
+ assertThat(results).isNotNull();
+ }
+
@Test
public void should_find_root_project_by_component_key() {
setupData("fixture");