From a1b82617d6a08c17d69ca8b19d242cb45799187a Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 28 Sep 2023 11:45:20 +0200 Subject: [PATCH] SONAR-20315 Extract pagination sql fragment --- .../src/main/java/org/sonar/db/MyBatis.java | 4 +++- .../main/java/org/sonar/db/common/Common.java | 24 +++++++++++++++++++ .../org/sonar/db/common/package-info.java | 23 ++++++++++++++++++ .../org/sonar/db/audit/AuditMapper.xml | 2 +- .../org/sonar/db/ce/CeActivityMapper.xml | 2 +- .../org/sonar/db/ce/CeQueueMapper.xml | 8 ++----- .../resources/org/sonar/db/common/Common.xml | 11 +++++++++ .../sonar/db/component/ComponentMapper.xml | 2 +- .../org/sonar/db/component/SnapshotMapper.xml | 6 +---- .../org/sonar/db/issue/IssueMapper.xml | 8 +++---- .../org/sonar/db/metric/MetricMapper.xml | 2 +- .../db/permission/GroupPermissionMapper.xml | 6 +---- .../template/PermissionTemplateMapper.xml | 8 ++----- .../org/sonar/db/project/ProjectMapper.xml | 2 +- .../QualityGateGroupPermissionsMapper.xml | 2 +- .../QualityGateUserPermissionsMapper.xml | 2 +- .../QProfileEditGroupsMapper.xml | 2 +- .../QProfileEditUsersMapper.xml | 2 +- .../org/sonar/db/scim/ScimGroupMapper.xml | 6 +---- .../org/sonar/db/scim/ScimUserMapper.xml | 6 +---- .../org/sonar/db/user/GroupMapper.xml | 6 +---- .../sonar/db/user/GroupMembershipMapper.xml | 4 ++-- .../org/sonar/db/user/UserMapper.xml | 2 +- .../db/webhook/WebhookDeliveryMapper.xml | 6 ++--- 24 files changed, 89 insertions(+), 57 deletions(-) create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/common/Common.java create mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/common/package-info.java create mode 100644 server/sonar-db-dao/src/main/resources/org/sonar/db/common/Common.xml diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 2566492e862..76f0e4a5faf 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -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 index 00000000000..f9a4243f40f --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/common/Common.java @@ -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 index 00000000000..534bfbe39c1 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/common/package-info.java @@ -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; diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml index 3aa93b67dba..b8c7ea1423d 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml @@ -32,7 +32,7 @@ where a.created_at >= #{start} and a.created_at < #{end} order by created_at asc - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml index a53f15d1d2b..23d732adbf3 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml @@ -85,7 +85,7 @@ order by ca.created_at desc, uuid desc - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - 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 index 00000000000..690168f3c40 --- /dev/null +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/common/Common.xml @@ -0,0 +1,11 @@ + + + + + + + offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + + + + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index ba9c732ea74..e5443f30e6e 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -215,7 +215,7 @@ ORDER BY LOWER(p.name), p.name, p.created_at - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - @@ -727,6 +727,6 @@ order by (select null) - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + 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 8afb81bd763..57ecbbdf673 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 @@ -45,7 +45,7 @@ m.enabled=${_true} ORDER BY UPPER(m.short_name), m.short_name - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - FROM (SELECT diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml index f24ccb52809..bc75cd1e251 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml @@ -50,7 +50,7 @@ #{uuid,jdbcType=VARCHAR} order by p.name, uuid desc - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml index acfd537f110..f95ed93b70d 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml @@ -29,7 +29,7 @@ SELECT g.uuid as groupUuid, g.name as name, qeg.uuid as uuid ORDER BY g.name ASC - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml index a8bbc1cd6d5..03ae588be8e 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml @@ -27,7 +27,7 @@ SELECT u.uuid as userUuid, u.name as name, qeu.uuid as uuid ORDER BY u.name ASC - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only + diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimGroupMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimGroupMapper.xml index 44fd376acaf..7f50a0af848 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimGroupMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/scim/ScimGroupMapper.xml @@ -39,13 +39,9 @@ where g.name = #{query.displayName,jdbcType=VARCHAR} order by s.scim_uuid asc - + - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - - - - offset #{pagination.offset,jdbcType=INTEGER} rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only - -