From 1a32e7df803b34d80161269c0ad577fd5a2e6a60 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 25 Sep 2023 18:11:05 +0200 Subject: [PATCH] SONAR-20315 update GroupPermissionDao queries --- .../java/org/sonar/db/permission/GroupPermissionDao.java | 4 ++-- .../org/sonar/db/permission/GroupPermissionMapper.java | 4 ++-- .../org/sonar/db/permission/GroupPermissionMapper.xml | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 39d0d8cfb22..8aff217a7c5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -25,10 +25,10 @@ import java.util.Map; import java.util.Set; import javax.annotation.Nullable; import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.RowBounds; import org.sonar.api.security.DefaultGroups; 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.GroupPermissionNewValue; import org.sonar.db.entity.EntityDto; @@ -54,7 +54,7 @@ public class GroupPermissionDao implements Dao { * @return group names, sorted in alphabetical order */ public List selectGroupNamesByQuery(DbSession dbSession, PermissionQuery query) { - return mapper(dbSession).selectGroupNamesByQuery(query, new RowBounds(query.getPageOffset(), query.getPageSize())); + return mapper(dbSession).selectGroupNamesByQuery(query, Pagination.forPage(query.getPageIndex()).andSize(query.getPageSize())); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index f3d2934b39f..b548d8f1ca8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -25,11 +25,11 @@ import java.util.Set; 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; public interface GroupPermissionMapper { - List selectGroupNamesByQuery(@Param("query") PermissionQuery query, RowBounds rowBounds); + List selectGroupNamesByQuery(@Param("query") PermissionQuery query, @Param("pagination") Pagination pagination); int countGroupsByQuery(@Param("query") PermissionQuery query); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index 78d5f251ecd..3a214437939 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -70,13 +70,18 @@ from group_roles gr where gr.group_uuid is null and gr.entity_uuid is not null - select sub.name, lower(sub.name), sub.groupUuid group by sub.name, lower(sub.name), sub.groupUuid order by case when (count(sub.permission) > 0) then 1 else 2 end asc, lower(sub.name), sub.name, sub.groupUuid + + + offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + +