From 3f3560bf141608eb6df41c48aac00142dc9d20bc Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 2 Nov 2021 14:12:43 +0100 Subject: [PATCH] SONAR-15528 Support export project branches in portfolio in XML --- .../org/sonar/db/component/BranchDao.java | 8 +++++ .../org/sonar/db/component/BranchMapper.java | 3 ++ .../org/sonar/db/component/BranchMapper.xml | 11 ++++++ .../org/sonar/db/component/BranchDaoTest.java | 36 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index cfbc72cb910..e48ac2a5bf3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -81,6 +82,13 @@ public class BranchDao implements Dao { return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key, branchType)); } + public List selectByKeys(DbSession dbSession, String projectUuid, Set branchKeys) { + if (branchKeys.isEmpty()) { + return emptyList(); + } + return executeLargeInputs(branchKeys, partition -> mapper(dbSession).selectByKeys(projectUuid, branchKeys)); + } + public Collection selectByComponent(DbSession dbSession, ComponentDto component) { String projectUuid = component.getMainBranchProjectUuid(); if (projectUuid == null) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java index 62837316822..b0b5ff2a23a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java @@ -22,6 +22,7 @@ package org.sonar.db.component; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; @@ -40,6 +41,8 @@ public interface BranchMapper { BranchDto selectByKey(@Param("projectUuid") String projectUuid, @Param("key") String key, @Param("branchType") BranchType branchType); + List selectByKeys(@Param("projectUuid") String projectUuid, @Param("keys") Set branchKeys); + BranchDto selectByUuid(@Param("uuid") String uuid); Collection selectByProjectUuid(@Param("projectUuid") String projectUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml index 8cdc4b70ddc..3cecf8644f9 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml @@ -83,6 +83,17 @@ pb.branch_type = #{branchType, jdbcType=VARCHAR} + +