From b53cc3cb38c77de88c1d55377968a13c7ab4df66 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 19 Apr 2016 16:30:22 +0200 Subject: [PATCH] SONAR-7553 DAO of CE_QUEUE count number of rows by status --- .../main/java/org/sonar/db/ce/CeQueueDao.java | 7 ++-- .../java/org/sonar/db/ce/CeQueueMapper.java | 4 +-- .../org/sonar/db/ce/CeQueueMapper.xml | 9 +++-- .../java/org/sonar/db/ce/CeQueueDaoTest.java | 34 ++++++++++++++++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java index 779f7372bbf..283b3823443 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java @@ -21,6 +21,7 @@ package org.sonar.db.ce; import com.google.common.base.Optional; import java.util.List; +import javax.annotation.Nullable; import org.apache.ibatis.session.RowBounds; import org.sonar.api.utils.System2; import org.sonar.db.Dao; @@ -100,11 +101,11 @@ public class CeQueueDao implements Dao { } public int countByStatus(DbSession dbSession, CeQueueDto.Status status) { - return mapper(dbSession).countByStatus(status); + return mapper(dbSession).countByStatusAndComponentUuid(status, null); } - public int countAll(DbSession dbSession) { - return mapper(dbSession).countAll(); + public int countByStatusAndComponentUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String componentUuid) { + return mapper(dbSession).countByStatusAndComponentUuid(status, componentUuid); } public Optional peek(DbSession session) { diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java index 62fca4a7ff1..aa0645987dd 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java @@ -40,9 +40,7 @@ public interface CeQueueMapper { @CheckForNull CeQueueDto selectByUuid(@Param("uuid") String uuid); - int countByStatus(@Param("status") CeQueueDto.Status status); - - int countAll(); + int countByStatusAndComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("componentUuid") String componentUuid); void insert(CeQueueDto dto); diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml index c9924353c1a..e3d71cc85ac 100644 --- a/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml @@ -29,8 +29,13 @@ where cq.uuid=#{uuid} - + select count(1) + from ce_queue + where status=#{status} + + and component_uuid=#{componentUuid} +