From: Pierre Date: Mon, 25 Sep 2023 15:48:17 +0000 (+0200) Subject: SONAR-20315 update MetricDao queries X-Git-Tag: 10.3.0.82913~326 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=86e07a31449ea4dc0ce558e7ce5c263231cfd6a1;p=sonarqube.git SONAR-20315 update MetricDao queries --- diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/metric/MetricDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/metric/MetricDaoIT.java index 2a76e99b470..e6deff029a3 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/metric/MetricDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/metric/MetricDaoIT.java @@ -266,9 +266,9 @@ public class MetricDaoIT { underTest.insert(dbSession, newMetricDto().setEnabled(true)); underTest.insert(dbSession, newMetricDto().setEnabled(false)); - List result = underTest.selectEnabled(dbSession, 0, 100); + List result = underTest.selectEnabled(dbSession, 1, 2); - assertThat(result).hasSize(3); + assertThat(result).hasSize(2); } private void assertEquals(MetricDto expected, MetricDto result) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java index 9ece6c8f489..fdf05f99493 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java @@ -25,9 +25,9 @@ import java.util.Collection; 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; @@ -56,11 +56,11 @@ public class MetricDao implements Dao { } public List selectEnabled(DbSession session) { - return mapper(session).selectAllEnabled(); + return mapper(session).selectAllEnabled(Pagination.all()); } - public List selectEnabled(DbSession session, int offset, int limit) { - return mapper(session).selectAllEnabled(new RowBounds(offset, limit)); + public List selectEnabled(DbSession session, int page, int limit) { + return mapper(session).selectAllEnabled(Pagination.forPage(page).andSize(limit)); } public int countEnabled(DbSession session) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java index 787a64f71f3..01cbff84051 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java @@ -21,7 +21,7 @@ package org.sonar.db.metric; import java.util.List; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.session.RowBounds; +import org.sonar.db.Pagination; public interface MetricMapper { @@ -35,9 +35,7 @@ public interface MetricMapper { List selectAll(); - List selectAllEnabled(); - - List selectAllEnabled(RowBounds rowBounds); + List selectAllEnabled(@Param("pagination")Pagination pagination); void insert(MetricDto dto); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml index 604645fac12..c77a7c45a36 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml @@ -37,7 +37,7 @@ ORDER BY UPPER(m.short_name), m.short_name - SELECT FROM metrics m @@ -45,6 +45,7 @@ m.enabled=${_true} ORDER BY UPPER(m.short_name), m.short_name + offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only