import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
import static java.util.Collections.emptyList;
import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
public class CeQueueDao implements Dao {
- private static final RowBounds ONE_ROW_LIMIT = new RowBounds(0, 1);
+ private static final Pagination ONE_RESULT_PAGINATION = Pagination.forPage(1).andSize(1);
private final System2 system2;
}
public Optional<CeQueueDto> peek(DbSession session, String workerUuid) {
- List<EligibleTaskDto> eligibles = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT);
+ List<EligibleTaskDto> eligibles = mapper(session).selectEligibleForPeek(ONE_RESULT_PAGINATION);
if (eligibles.isEmpty()) {
return Optional.absent();
}
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
+import org.sonar.db.Pagination;
public interface CeQueueMapper {
int countByQuery(@Param("query") CeTaskQuery query);
- List<EligibleTaskDto> selectEligibleForPeek(RowBounds rowBounds);
+ List<EligibleTaskDto> selectEligibleForPeek(@Param("pagination") Pagination pagination);
@CheckForNull
CeQueueDto selectByUuid(@Param("uuid") String uuid);
<select id="selectEligibleForPeek" resultType="org.sonar.db.ce.EligibleTaskDto">
select
- cq.uuid as "uuid",
- cq.execution_count as "executionCount"
+ <include refid="columnsSelectEligibleForPeek"/>
+ <include refid="sqlSelectEligibleForPeek"/>
+ <include refid="orderBySelectEligibleForPeek"/>
+ limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
+ </select>
+
+ <select id="selectEligibleForPeek" parameterType="map" resultType="org.sonar.db.ce.EligibleTaskDto" databaseId="mssql">
+ select * from (
+ select
+ row_number() over(<include refid="orderBySelectEligibleForPeek"/>) as number,
+ <include refid="columnsSelectEligibleForPeek"/>
+ <include refid="sqlSelectEligibleForPeek"/>
+ ) as query
+ where
+ query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+ <include refid="orderBySelectEligibleForPeek"/>
+ </select>
+
+ <select id="selectEligibleForPeek" parameterType="map" resultType="org.sonar.db.ce.EligibleTaskDto" databaseId="oracle">
+ select * from (
+ select rownum as rn, t.* from (
+ select
+ <include refid="columnsSelectEligibleForPeek"/>
+ <include refid="sqlSelectEligibleForPeek" />
+ <include refid="orderBySelectEligibleForPeek"/>
+ ) t
+ ) t
+ where
+ t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+ </select>
+
+ <sql id="columnsSelectEligibleForPeek">
+ cq.uuid as "uuid",
+ cq.execution_count as "executionCount",
+ cq.created_at as "created_at",
+ cq.id as "id"
+ </sql>
+
+ <sql id="sqlSelectEligibleForPeek">
from
ce_queue cq
where
cq.component_uuid=cq2.component_uuid
and cq2.status <> 'PENDING'
)
- <include refid="orderByDateAndId"/>
- </select>
+ </sql>
+
+ <sql id="orderBySelectEligibleForPeek">
+ order by
+ created_at asc,
+ id asc
+ </sql>
<insert id="insert" parameterType="org.sonar.db.ce.CeQueueDto" useGeneratedKeys="false">
insert into ce_queue