aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2022-02-23 21:43:23 +0100
committersonartech <sonartech@sonarsource.com>2022-02-25 20:02:54 +0000
commite30eb01b20e62a3365fb66d39e9b88ceb87bb4af (patch)
treef3b2cbe7232491ca4648a0c407f108db42d52599 /server/sonar-db-dao
parent97ad45993a48f860cf5957a204bca1fdbe4d7ee4 (diff)
downloadsonarqube-e30eb01b20e62a3365fb66d39e9b88ceb87bb4af.tar.gz
sonarqube-e30eb01b20e62a3365fb66d39e9b88ceb87bb4af.zip
SONAR-10930 add pagination in activity API
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java9
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml8
4 files changed, 21 insertions, 2 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java
index 494af70c784..38a84512171 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDao.java
@@ -84,6 +84,10 @@ public class CeActivityDao implements Dao {
return mapper(dbSession).selectByQuery(query, pagination);
}
+ public int countByQuery(DbSession dbSession, CeTaskQuery query) {
+ return mapper(dbSession).countByQuery(query);
+ }
+
public int countLastByStatusAndMainComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String mainComponentUuid) {
return mapper(dbSession).countLastByStatusAndMainComponentUuid(status, mainComponentUuid);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java
index 78a801c2bc7..156ae996fda 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityMapper.java
@@ -36,6 +36,8 @@ public interface CeActivityMapper {
List<CeActivityDto> selectNewerThan(@Param("afterDate") long afterDate);
+ int countByQuery(@Param("query") CeTaskQuery query);
+
int countLastByStatusAndMainComponentUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid);
void insert(CeActivityDto dto);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
index 3d4edfb5049..1e86d6b7118 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
@@ -55,13 +55,20 @@ public class CeQueueDao implements Dao {
}
public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int pageSize) {
+ return selectByQueryInDescOrder(dbSession, query, 1, pageSize);
+ }
+
+ public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int page, int pageSize) {
if (query.isShortCircuitedByMainComponentUuids()
|| query.isOnlyCurrents()
|| query.getMaxExecutedAt() != null) {
return emptyList();
}
- return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(0, pageSize));
+ int offset = (page - 1) * pageSize;
+ int limit = page * pageSize;
+
+ return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(offset, limit));
}
public int countByQuery(DbSession dbSession, CeTaskQuery query) {
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index f94c83b5ffc..261f886da0a 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -152,7 +152,13 @@
where
ca.created_at &gt; #{afterDate,jdbcType=BIGINT}
</select>
-
+
+ <select id="countByQuery" parameterType="map" resultType="int">
+ select
+ count(1)
+ <include refid="sqlSelectByQuery" />
+ </select>
+
<select id="countLastByStatusAndMainComponentUuid" resultType="int">
select
count(1)