]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20315 update SnapshotDao queries
authorPierre <pierre.guillot@sonarsource.com>
Mon, 25 Sep 2023 16:05:40 +0000 (18:05 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 28 Sep 2023 20:03:12 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml

index ab07876c85b8095403b39b366ad165c572b12054..745efa8cd30427bceb47f0cdb0a8c5b6b7674526 100644 (file)
@@ -29,9 +29,9 @@ import java.util.Optional;
 import java.util.stream.IntStream;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.apache.ibatis.session.RowBounds;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
@@ -89,7 +89,7 @@ public class SnapshotDao implements Dao {
   }
 
   public Optional<SnapshotDto> selectOldestAnalysis(DbSession session, String rootComponentUuid) {
-    return mapper(session).selectOldestSnapshots(rootComponentUuid, SnapshotDto.STATUS_PROCESSED, new RowBounds(0, 1))
+    return mapper(session).selectOldestSnapshots(rootComponentUuid, SnapshotDto.STATUS_PROCESSED, Pagination.first())
       .stream()
       .findFirst();
   }
index 7a9e64c2c57fa58b54751bd2e684dd699a8fd1d4..79a4435c416e26de422aeded1b3cfd262ec54d60 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Collection;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.RowBounds;
+import org.sonar.db.Pagination;
 import org.sonar.db.component.SnapshotDao.ProjectUuidFromDatePair;
 
 public interface SnapshotMapper {
@@ -42,7 +42,7 @@ public interface SnapshotMapper {
 
   List<SnapshotDto> selectSnapshotsByQuery(@Param("query") SnapshotQuery query);
 
-  List<SnapshotDto> selectOldestSnapshots(@Param("rootComponentUuid") String rootComponentUuid, @Param("status") String status, RowBounds rowBounds);
+  List<SnapshotDto> selectOldestSnapshots(@Param("rootComponentUuid") String rootComponentUuid, @Param("status") String status, @Param("pagination") Pagination pagination);
 
   List<ViewsSnapshotDto> selectSnapshotBefore(@Param("rootComponentUuid") String rootComponentUuid, @Param("date") long date);
 
index 5a2356a79aba0f7cfc3d2ecd1656d2aac180849f..d66491e315d194d806c4f8a71342f8a4b71be44a 100644 (file)
       and s.status = #{status,jdbcType=VARCHAR}
     </where>
     ORDER BY s.created_at ASC
+    <include refid="pagination"/>
   </select>
 
+  <sql id="pagination">
+    offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+  </sql>
+
   <select id="selectSnapshotBefore" resultType="ViewsSnapshot">
     SELECT
     <include refid="viewsSnapshotColumns" />