]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Fix sql query
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 24 May 2013 12:57:14 +0000 (14:57 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 24 May 2013 12:57:14 +0000 (14:57 +0200)
sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml

index 55f672c763c344106dbf5f4973e837e2ec45a4d2..9c46d100585a7e5bb0ce93aee3618360f88108a8 100644 (file)
@@ -96,13 +96,13 @@ public class IssueDao implements BatchComponent, ServerComponent {
     return selectIssueAndProjectIds(query, authorizedRootProjectIds, query.maxResults(), session);
   }
 
-  private List<IssueDto> selectIssueAndProjectIds(IssueQuery query, Collection<Integer> authorizedRootProjectIds, Integer maxResult, SqlSession session){
+  private List<IssueDto> selectIssueAndProjectIds(IssueQuery query, Collection<Integer> authorizedRootProjectIds, Integer maxResults, SqlSession session){
     if (authorizedRootProjectIds.isEmpty()) {
       return Collections.emptyList();
     }
     IssueMapper mapper = session.getMapper(IssueMapper.class);
     List<List<Integer>> idsPartition = Lists.partition(newArrayList(authorizedRootProjectIds), 1000);
-    return mapper.selectIssueAndProjectIds(query, idsPartition, maxResult);
+    return mapper.selectIssueAndProjectIds(query, idsPartition, maxResults);
   }
 
   @VisibleForTesting
index 08509871f2fbecac1f37521c69c734b888274219..caa04f88709e9dd65709f1a85fd012c8d47a8ed8 100644 (file)
   </select>
 
   <select id="selectIssueAndProjectIds" parameterType="map" resultType="Issue" fetchSize="2147483647">
-    select i.id, i.project_id as projectId
+    select
+    <if test="_databaseId == 'mssql' ">
+      top #{maxResults}
+    </if>
+    i.id, i.project_id as projectId
     <include refid="sortColumn"/>
     <include refid="selectQueryConditions"/>
   </select>
       <if test="query.createdBefore() != null">
         and i.issue_creation_date &lt; #{query.createdBefore}
       </if>
+      <if test="_databaseId == 'oracle' ">
+        and rownum &lt;= #{maxResults}
+      </if>
     </where>
     order by i.id
-    limit #{maxResults}
+    <if test="_databaseId != 'oracle' and _databaseId != 'mssql'">
+      limit #{maxResults}
+    </if>
   </sql>
 
 </mapper>