package org.sonar.core.issue.db;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
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
if (ids.isEmpty()) {
return Collections.emptyList();
}
- return session.getMapper(IssueMapper.class).selectByIds(ids);
+ 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> selectIssues(@Param("query") IssueQuery query, @Param("componentRootKeys") Collection<String> componentRootKeys,
@Nullable @Param("userId") Integer userId, @Param("role") String role, @Param("maxResults") Integer maxResult);
- List<IssueDto> selectByIds(@Param("ids") Collection<Long> ids);
-
void insert(IssueDto issue);
int update(IssueDto issue);
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="(" close=")" item="element" index="index" separator=" or ">i.id=#{element}</foreach>
+ and
+ <foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (">
+ <foreach collection="list" item="element" separator=",">
+ #{element}
+ </foreach>
+ </foreach>
</where>
</select>
assertThat(results).hasSize(3);
}
+ @Test
+ public void should_select_by_ids_with_huge_number_of_ids() {
+ setupData("shared");
+
+ List<Long> hugeNbOfIssues = newArrayList();
+ for (long i=0; i<1500; i++) {
+ hugeNbOfIssues.add(i);
+ }
+ List<IssueDto> results = dao.selectByIds(hugeNbOfIssues);
+
+ // The goal of this test is only to check that the query do no fail, not to check the number of results
+ assertThat(results).isEmpty();
+ }
+
private List<Long> getIssueIds(List<IssueDto> issues) {
return newArrayList(Iterables.transform(issues, new Function<IssueDto, Long>() {
@Override