private final boolean withAtLeastOnePermission;
private final int pageSize;
+ private final int pageIndex;
private final int pageOffset;
private PermissionQuery(Builder builder) {
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);
}
return pageSize;
}
+ public int getPageIndex() {
+ return pageIndex;
+ }
+
public int getPageOffset() {
return pageOffset;
}
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;
* @return a paginated list of user logins.
*/
public List<String> 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) {
}
public List<String> 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) {
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;
/**
PermissionTemplateDto selectByName(@Param("name") String name);
- List<String> selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid, RowBounds rowBounds);
+ List<String> selectUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid, @Param("pagination") Pagination pagination);
int countUserLoginsByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid);
- List<String> selectGroupNamesByQueryAndTemplate(@Param("templateUuid") String templateUuid, @Param("query") PermissionQuery query, RowBounds rowBounds);
+ List<String> selectGroupNamesByQueryAndTemplate(@Param("templateUuid") String templateUuid, @Param("query") PermissionQuery query, @Param("pagination") Pagination pagination);
int countGroupNamesByQueryAndTemplate(@Param("query") PermissionQuery query, @Param("templateUuid") String templateUuid);
where group_uuid = #{groupUuid,jdbcType=VARCHAR}
</delete>
- <select id="selectUserLoginsByQueryAndTemplate" parameterType="map" resultType="string">
+ <select id="selectUserLoginsByQueryAndTemplate" resultType="string">
select u.login as login
<include refid="userLoginsByQueryAndTemplate"/>
group by u.login, u.name
order by case when (count(ptu.permission_reference) > 0) then 1 else 2 end asc, u.name
+ <include refid="pagination"/>
</select>
<select id="countUserLoginsByQueryAndTemplate" parameterType="map" resultType="int">
</where>
</sql>
- <select id="selectGroupNamesByQueryAndTemplate" parameterType="map" resultType="string">
+ <select id="selectGroupNamesByQueryAndTemplate" resultType="string">
select groups.name, lower(groups.name), groups.group_uuid
<include refid="groupNamesByQueryAndTemplate"/>
group by groups.name, lower(groups.name), groups.group_uuid
order by case when (count(groups.permission) > 0) then 1 else 2 end asc, lower(groups.name), groups.name, groups.group_uuid
+ <include refid="pagination"/>
</select>
<select id="countGroupNamesByQueryAndTemplate" parameterType="map" resultType="int">
<include refid="groupNamesByQueryAndTemplate"/>) g
</select>
+ <sql id="pagination">
+ offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+ </sql>
+
<sql id="groupNamesByQueryAndTemplate">
FROM
(SELECT