From: Pierre Date: Mon, 25 Sep 2023 15:18:01 +0000 (+0200) Subject: SONAR-20315 update PermissionTemplateDao queries X-Git-Tag: 10.3.0.82913~328 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=85a1f6059f40f9b7b29d7755b1b7a155f80c8359;p=sonarqube.git SONAR-20315 update PermissionTemplateDao queries --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java index af8780c1a4c..c12ea9fdb04 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/PermissionQuery.java @@ -58,6 +58,7 @@ public class PermissionQuery { private final boolean withAtLeastOnePermission; private final int pageSize; + private final int pageIndex; private final int pageOffset; private PermissionQuery(Builder builder) { @@ -68,6 +69,7 @@ public class PermissionQuery { this.searchQueryToSql = builder.searchQuery == null ? null : buildLikeValue(builder.searchQuery, WildcardPosition.BEFORE_AND_AFTER); this.searchQueryToSqlLowercase = searchQueryToSql == null ? null : searchQueryToSql.toLowerCase(Locale.ENGLISH); this.pageSize = builder.pageSize; + this.pageIndex = builder.pageIndex; this.pageOffset = offset(builder.pageIndex, builder.pageSize); } @@ -104,6 +106,10 @@ public class PermissionQuery { return pageSize; } + public int getPageIndex() { + return pageIndex; + } + public int getPageOffset() { return pageOffset; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java index 3e63318ea05..e0731b895e8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateDao.java @@ -28,11 +28,11 @@ import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.RowBounds; import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DbSession; +import org.sonar.db.Pagination; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.PermissionTemplateNewValue; import org.sonar.db.permission.CountPerEntityPermission; @@ -61,7 +61,7 @@ public class PermissionTemplateDao implements Dao { * @return a paginated list of user logins. */ public List selectUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { - return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateUuid, new RowBounds(query.getPageOffset(), query.getPageSize())); + return mapper(session).selectUserLoginsByQueryAndTemplate(query, templateUuid, Pagination.forPage(query.getPageIndex()).andSize(query.getPageSize())); } public int countUserLoginsByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { @@ -77,7 +77,7 @@ public class PermissionTemplateDao implements Dao { } public List selectGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { - return mapper(session).selectGroupNamesByQueryAndTemplate(templateUuid, query, new RowBounds(query.getPageOffset(), query.getPageSize())); + return mapper(session).selectGroupNamesByQueryAndTemplate(templateUuid, query, Pagination.forPage(query.getPageIndex()).andSize(query.getPageSize())); } public int countGroupNamesByQueryAndTemplate(DbSession session, PermissionQuery query, String templateUuid) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java index 35465a64fb6..420d14eda8e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/template/PermissionTemplateMapper.java @@ -24,7 +24,7 @@ import java.util.Map; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.RowBounds; +import org.sonar.db.Pagination; import org.sonar.db.permission.PermissionQuery; /** @@ -62,11 +62,11 @@ public interface PermissionTemplateMapper { PermissionTemplateDto selectByName(@Param("name") String name); - List selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid, RowBounds rowBounds); + List selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid, @Param("pagination") Pagination pagination); int countUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid); - List selectGroupNamesByQueryAndTemplate(@Param("templateUuid") String templateUuid, @Param("query") PermissionQuery query, RowBounds rowBounds); + List selectGroupNamesByQueryAndTemplate(@Param("templateUuid") String templateUuid, @Param("query") PermissionQuery query, @Param("pagination") Pagination pagination); int countGroupNamesByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml index 0ced621cbd7..73520e48809 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml @@ -89,11 +89,12 @@ where group_uuid = #{groupUuid,jdbcType=VARCHAR} - select u.login as login group by u.login, u.name order by case when (count(ptu.permission_reference) > 0) then 1 else 2 end asc, u.name + + + + offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + + FROM (SELECT