]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20315 Extract pagination sql fragment
authorPierre <pierre.guillot@sonarsource.com>
Thu, 28 Sep 2023 09:45:20 +0000 (11:45 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Sep 2023 20:02:47 +0000 (20:02 +0000)
24 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
server/sonar-db-dao/src/main/java/org/sonar/db/common/Common.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/common/package-info.java [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/common/Common.xml [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateGroupPermissionsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimGroupMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimUserMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/GroupMembershipMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/webhook/WebhookDeliveryMapper.xml

index 2566492e862fdfcd1ae4ab0ad7c94405eccc5018..76f0e4a5fafff7f74b65f73e3907b3ab3142985e 100644 (file)
@@ -45,6 +45,7 @@ import org.sonar.db.ce.CeTaskCharacteristicDto;
 import org.sonar.db.ce.CeTaskCharacteristicMapper;
 import org.sonar.db.ce.CeTaskInputMapper;
 import org.sonar.db.ce.CeTaskMessageMapper;
+import org.sonar.db.common.Common;
 import org.sonar.db.component.AnalysisPropertiesMapper;
 import org.sonar.db.component.AnalysisPropertyValuePerProject;
 import org.sonar.db.component.ApplicationProjectsMapper;
@@ -344,7 +345,8 @@ public class MyBatis {
       UserPermissionMapper.class,
       UserTokenMapper.class,
       WebhookMapper.class,
-      WebhookDeliveryMapper.class
+      WebhookDeliveryMapper.class,
+      Common.class
     };
     confBuilder.loadMappers(mappers);
     confExtensions.stream()
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/common/Common.java b/server/sonar-db-dao/src/main/java/org/sonar/db/common/Common.java
new file mode 100644 (file)
index 0000000..f9a4243
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.common;
+
+public interface Common {
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/common/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/common/package-info.java
new file mode 100644 (file)
index 0000000..534bfbe
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.db.common;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 3aa93b67dba461a552b4d3c7c4e960def2e251ee..b8c7ea1423d4206228130d9a8996c0dd53851ab3 100644 (file)
@@ -32,7 +32,7 @@
     where
       a.created_at &gt;= #{start} and a.created_at &lt; #{end}
     order by created_at asc
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <insert id="insert" parameterType="Map" useGeneratedKeys="false">
index a53f15d1d2bd676fde8fa68f8ae0471d5dd372f6..23d732adbf3b0a6312cd83e9f233b78b156ac22a 100644 (file)
@@ -85,7 +85,7 @@
   <sql id="sqlSelectByQuery">
     <include refid="sqlSelectByQueryWithoutPagination"/>
     order by ca.created_at desc, uuid desc
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </sql>
 
   <select id="countByQuery" parameterType="map" resultType="int">
index 88e1d5e5e132c0a96d7d45280491dc96414df811..99a2577b74794d4d5c642e15524c60c3cd1e924c 100644 (file)
     <include refid="columns"/>
     <include refid="sqlSelectByQuery"/>
     <include refid="orderByDescDateAndUuid"/>
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="countByQuery" resultType="int">
     select
       count(1)
     select cq.uuid as ceTaskUuid, cq.created_at as createdAt
     <include refid="sqlSelectEligibleForPeek"/>
     <include refid="orderBySelectEligibleForPeek"/>
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <sql id="columnsSelectEligibleForPeek">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/common/Common.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/common/Common.xml
new file mode 100644 (file)
index 0000000..690168f
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.db.common.Common">
+
+  <sql id="pagination">
+    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+  </sql>
+
+</mapper>
+
index ba9c732ea748966aecdcaf033e348c6e01247818..e5443f30e6ea897a9a40b1318797822d78acf273 100644 (file)
       <include refid="componentColumns"/>
     <include refid="sqlSelectByQuery"/>
     ORDER BY LOWER(p.name), p.name, p.created_at
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countByQuery" resultType="int">
index 79637cfad2cdce0e70e10ed51d9fde8a1f397082..f64fbfe213941c610a78ee62b644e601965d6997 100644 (file)
       and s.status = #{status,jdbcType=VARCHAR}
     </where>
     ORDER BY s.created_at ASC
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="selectSnapshotBefore" resultType="ViewsSnapshot">
     SELECT
     <include refid="viewsSnapshotColumns" />
index b9649d46bbf2006a898ae84a2a008cf9462197fd..1cf56203c77e2cf59d562a97aa6fda3a52abdca3 100644 (file)
           </foreach>
     </if>
     order by i.kee
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string">
         </foreach>
    </if>
     order by i.kee
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="selectByComponentUuidPaginated" parameterType="map" resultMap="issueResultMap">
     left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
     where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
     order by i.issue_creation_date ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <sql id="selectByBranchColumns">
         <!--  order by clause is required if using offset rows fetch next on MSSQL Database   -->
         order by (select null)
       </if>
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 </mapper>
index 8afb81bd763c7df8467abfc5c511c155201300b3..57ecbbdf6730b9daea5257a824f88a53c5ca478b 100644 (file)
@@ -45,7 +45,7 @@
       m.enabled=${_true}
     </where>
     ORDER BY UPPER(m.short_name), m.short_name
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countEnabled" resultType="Integer">
index 49b60bfebb5db9ad167bc63fe017ba28cb5b520c..315f69b18d6bed16c99b4a3e8991a0f4bd26b059 100644 (file)
     <include refid="groupsByQuery"/>
     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
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="countGroupsByQuery" parameterType="map" resultType="int">
     select count(1)
     from (
index 2e122c5841aa35ebafab31eb91ecd70e5d45141a..da861f8d24188b0f4d74302972e5e08326743130 100644 (file)
@@ -94,7 +94,7 @@
       <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"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countUserLoginsByQueryAndTemplate" parameterType="map" resultType="int">
     <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"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countGroupNamesByQueryAndTemplate" parameterType="map" resultType="int">
       <include refid="groupNamesByQueryAndTemplate"/>) g
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <sql id="groupNamesByQueryAndTemplate">
     FROM
     (SELECT
index f24ccb528092c46f0bf46841d3633bd9d62f2418..bc75cd1e25192456c5b72c3e9a7c6cf81f66338c 100644 (file)
@@ -50,7 +50,7 @@
         #{uuid,jdbcType=VARCHAR}
       </foreach>
       order by p.name, uuid desc
-      offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+      <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="selectProjectsByKeys" resultType="Project">
index 029701e607214141f6ac2af7572826c7a82c665b..3c2bad84b949bf402b795b49e428c1a342e535fc 100644 (file)
@@ -33,7 +33,7 @@
     SELECT g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY g.name ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
    <select id="countByQuery" resultType="int">
index 9181c55b5252ee9cc16762a391437c6fa59e6e2c..e4a30c4be5c4f2db2545aea9a5568b7d38881dba 100644 (file)
@@ -41,7 +41,7 @@
     SELECT u.uuid as userUuid, u.name as name, qup.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY u.name ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <sql id="sqlSelectByQuery">
index acfd537f11054ddd488907ee3b3bec1be39cef4d..f95ed93b70dc123cd1bc99ff875a5cd2dc76aee0 100644 (file)
@@ -29,7 +29,7 @@
     SELECT g.uuid as groupUuid, g.name as name, qeg.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY g.name ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <sql id="sqlSelectByQuery">
index a8bbc1cd6d542956946577dbf74adefe25d29b15..03ae588be8e1a1924569c2f257ab45a55d98f124 100644 (file)
@@ -27,7 +27,7 @@
     SELECT u.uuid as userUuid, u.name as name, qeu.uuid as uuid
     <include refid="sqlSelectByQuery"/>
     ORDER BY u.name ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <sql id="sqlSelectByQuery">
index 44fd376acafdf6dbb32a59f1130f30988666c003..7f50a0af8486b28ce712899c66bdde9c080f33f2 100644 (file)
       where g.name = #{query.displayName,jdbcType=VARCHAR}
     </if>
     order by s.scim_uuid asc
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="countScimGroups" resultType="int">
     select count(1)
     from scim_groups s
index 8c1e7b4f3fd9c56acfdfa2f4aba0408de47c6b3f..10f5857faa3ab6029ab46bb5324dc8d6ca5963ff 100644 (file)
     <include refid="scimUsersColumns"/>
     <include refid="sqlSelectByQuery"/>
     order by s.scim_uuid asc
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="countScimUsers" parameterType="map" resultType="int">
     select count(1)
     <include refid="sqlSelectByQuery"/>
index ea9f0327977fb4cf35f9b55e2a7e7fe07b2cd1f9..7adc671389e8dac61b1f8c5d9bb6b2a80e38b291 100644 (file)
     from groups g
     <include refid="searchByQueryWhereClause"/>
     order by upper(g.name)
-    <include refid="pagination"/>
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
-  <sql id="pagination">
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
-  </sql>
-
   <select id="countByQuery" parameterType="map" resultType="int">
     select count(1)
     from groups g
index 7853f238363818c602581f6c10e66d417bc643e8..2a450e9905ceaf4feb132d42fdb3e769f1f11575 100644 (file)
@@ -25,7 +25,7 @@
     SELECT g.uuid as uuid, g.name as name, g.description as description, gu.user_uuid as userUuid
     <include refid="commonClauses"/>
     ORDER BY g.name
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countGroups" parameterType="map" resultType="int">
@@ -99,7 +99,7 @@
     SELECT u.uuid as uuid, u.login as login, u.name as name, gu.group_uuid as groupUuid
     <include refid="userCommonClauses"/>
     ORDER BY u.name ASC
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countMembers" parameterType="map" resultType="int">
index 2420da17cac3562db3b8d06178ace7d946fbd4c7..7dbc4ed5229b6d08b883f2066b570b4a24d0954f 100644 (file)
         <include refid="selectFromUsersAndJoinScmAccounts"/>
         <include refid="searchByQueryWhereClause"/>
         ORDER BY u.login
-        offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+        <include refid="org.sonar.db.common.Common.pagination"/>
     </select>
 
     <select id="countByQuery" parameterType="map" resultType="int">
index a115f936aed07cbc8b7bf6df0952827da9088616..af83ce14d04cb19cb537bdd1ead1fab1fa336ac2 100644 (file)
@@ -38,7 +38,7 @@
     from webhook_deliveries
     where webhook_uuid = #{webhookUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countByProjectUuid" parameterType="String" resultType="int">
@@ -53,7 +53,7 @@
     from webhook_deliveries
     where project_uuid = #{projectUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="selectOrderedByCeTaskUuid" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
@@ -61,7 +61,7 @@
     from webhook_deliveries
     where ce_task_uuid = #{ceTaskUuid,jdbcType=VARCHAR}
     order by created_at desc
-    offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
+    <include refid="org.sonar.db.common.Common.pagination"/>
   </select>
 
   <select id="countByCeTaskUuid" parameterType="String" resultType="int">