underTest.insert(dbSession, newMetricDto().setEnabled(true));
underTest.insert(dbSession, newMetricDto().setEnabled(false));
- List<MetricDto> result = underTest.selectEnabled(dbSession, 0, 100);
+ List<MetricDto> result = underTest.selectEnabled(dbSession, 1, 2);
- assertThat(result).hasSize(3);
+ assertThat(result).hasSize(2);
}
private void assertEquals(MetricDto expected, MetricDto result) {
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
-import org.apache.ibatis.session.RowBounds;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
import org.sonar.db.RowNotFoundException;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
}
public List<MetricDto> selectEnabled(DbSession session) {
- return mapper(session).selectAllEnabled();
+ return mapper(session).selectAllEnabled(Pagination.all());
}
- public List<MetricDto> selectEnabled(DbSession session, int offset, int limit) {
- return mapper(session).selectAllEnabled(new RowBounds(offset, limit));
+ public List<MetricDto> selectEnabled(DbSession session, int page, int limit) {
+ return mapper(session).selectAllEnabled(Pagination.forPage(page).andSize(limit));
}
public int countEnabled(DbSession session) {
import java.util.List;
import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.RowBounds;
+import org.sonar.db.Pagination;
public interface MetricMapper {
List<MetricDto> selectAll();
- List<MetricDto> selectAllEnabled();
-
- List<MetricDto> selectAllEnabled(RowBounds rowBounds);
+ List<MetricDto> selectAllEnabled(@Param("pagination")Pagination pagination);
void insert(MetricDto dto);
ORDER BY UPPER(m.short_name), m.short_name
</select>
- <select id="selectAllEnabled" parameterType="map" resultType="org.sonar.db.metric.MetricDto">
+ <select id="selectAllEnabled" resultType="org.sonar.db.metric.MetricDto">
SELECT
<include refid="metricColumns"/>
FROM metrics m
m.enabled=${_true}
</where>
ORDER BY UPPER(m.short_name), m.short_name
+ offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
</select>
<select id="countEnabled" resultType="Integer">
.setPage(request.mandatoryParamAsInt(Param.PAGE),
request.mandatoryParamAsInt(Param.PAGE_SIZE));
try (DbSession dbSession = dbClient.openSession(false)) {
- List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, searchOptions.getOffset(), searchOptions.getLimit());
+ List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, searchOptions.getPage(), searchOptions.getLimit());
int nbMetrics = dbClient.metricDao().countEnabled(dbSession);
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();