diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-20 11:59:16 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:43 +0000 |
commit | 566094fc629ab1e92afb0cdf191a0e2c685b5c35 (patch) | |
tree | ce172266109cf1c4e81a041e460c6cc7bcd5d50e /server/sonar-db-dao/src/main | |
parent | bcfb1cac55137b838da7a93385b20e0e5ed47abb (diff) | |
download | sonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.tar.gz sonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.zip |
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server/sonar-db-dao/src/main')
15 files changed, 147 insertions, 167 deletions
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 14da008f50e..515fd70c61a 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 @@ -62,7 +62,7 @@ import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ScrapAnalysisPropertyDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotMapper; -import org.sonar.db.component.UuidWithProjectUuidDto; +import org.sonar.db.component.UuidWithBranchUuidDto; import org.sonar.db.component.ViewsSnapshotDto; import org.sonar.db.duplication.DuplicationMapper; import org.sonar.db.duplication.DuplicationUnitDto; @@ -243,7 +243,7 @@ public class MyBatis { confBuilder.loadAlias("UserTelemetry", UserTelemetryDto.class); confBuilder.loadAlias("UserToken", UserTokenDto.class); confBuilder.loadAlias("UserTokenCount", UserTokenCount.class); - confBuilder.loadAlias("UuidWithProjectUuid", UuidWithProjectUuidDto.class); + confBuilder.loadAlias("UuidWithBranchUuid", UuidWithBranchUuidDto.class); confBuilder.loadAlias("ViewsSnapshot", ViewsSnapshotDto.class); confExtensions.forEach(ext -> ext.loadAliases(confBuilder::loadAlias)); 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 38cca4e8201..f655c175cfd 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 @@ -92,7 +92,7 @@ public class BranchDao implements Dao { public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) { String projectUuid = component.getMainBranchProjectUuid(); if (projectUuid == null) { - projectUuid = component.projectUuid(); + projectUuid = component.branchUuid(); } return mapper(dbSession).selectByProjectUuid(projectUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index b11d2801afd..d843733d1ff 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -23,6 +23,7 @@ import com.google.common.collect.Ordering; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -32,6 +33,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; +import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import org.sonar.api.resources.Qualifiers; @@ -44,14 +46,10 @@ import org.sonar.db.audit.model.ComponentNewValue; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Collections.emptyList; -import static org.sonar.core.util.stream.MoreCollectors.toList; -import static org.sonar.core.util.stream.MoreCollectors.toSet; import static org.sonar.db.DatabaseUtils.checkThatNotTooManyConditions; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet; import static org.sonar.db.DatabaseUtils.executeLargeUpdates; -import static org.sonar.db.component.ComponentDto.generateBranchKey; -import static org.sonar.db.component.ComponentDto.generatePullRequestKey; public class ComponentDao implements Dao { private final AuditPersister auditPersister; @@ -85,11 +83,7 @@ public class ComponentDao implements Dao { } public ComponentDto selectOrFailByUuid(DbSession session, String uuid) { - Optional<ComponentDto> componentDto = selectByUuid(session, uuid); - if (!componentDto.isPresent()) { - throw new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid)); - } - return componentDto.get(); + return selectByUuid(session, uuid).orElseThrow(() -> new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid))); } /** @@ -156,8 +150,8 @@ public class ComponentDao implements Dao { return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, Scopes.PROJECT, excludeDisabled); } - public int countEnabledModulesByProjectUuid(DbSession session, String projectUuid) { - return mapper(session).countEnabledModulesByProjectUuid(projectUuid); + public int countEnabledModulesByBranchUuid(DbSession session, String branchUuid) { + return mapper(session).countEnabledModulesByBranchUuid(branchUuid); } public List<ComponentDto> selectEnabledModulesFromProjectKey(DbSession session, String projectKey) { @@ -169,30 +163,45 @@ public class ComponentDao implements Dao { } public List<ComponentDto> selectByKeysAndBranch(DbSession session, Collection<String> keys, String branch) { - List<String> dbKeys = keys.stream().map(k -> generateBranchKey(k, branch)).collect(toList()); - List<String> allKeys = Stream.of(keys, dbKeys).flatMap(Collection::stream).collect(toList()); - return executeLargeInputs(allKeys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, branch)); - } - - /** - * Return list of components that will will mix main and branch components. - * Please note that a project can only appear once in the list, it's not possible to ask for many branches on same project with this method. - */ - public List<ComponentDto> selectByKeysAndBranches(DbSession session, Map<String, String> branchesByKey) { - Set<String> dbKeys = branchesByKey.entrySet().stream() - .map(entry -> generateBranchKey(entry.getKey(), entry.getValue())) - .collect(toSet()); - return selectByDbKeys(session, dbKeys); - } - - public List<ComponentDto> selectByDbKeys(DbSession session, Set<String> dbKeys) { - return executeLargeInputs(dbKeys, subKeys -> mapper(session).selectByDbKeys(subKeys)); + return executeLargeInputs(keys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, branch)); } public List<ComponentDto> selectByKeysAndPullRequest(DbSession session, Collection<String> keys, String pullRequestId) { - List<String> dbKeys = keys.stream().map(k -> generatePullRequestKey(k, pullRequestId)).collect(toList()); - List<String> allKeys = Stream.of(keys, dbKeys).flatMap(Collection::stream).collect(toList()); - return executeLargeInputs(allKeys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, pullRequestId)); + return executeLargeInputs(keys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, pullRequestId)); + } + + public List<ComponentDto> selectByDbKeys(DbSession session, Collection<String> dbKeys) { + Map<String, List<String>> keyByBranchKey = new HashMap<>(); + Map<String, List<String>> keyByPrKey = new HashMap<>(); + List<String> mainBranchKeys = new LinkedList<>(); + + for (String dbKey : dbKeys) { + String branchKey = StringUtils.substringAfterLast(dbKey, ComponentDto.BRANCH_KEY_SEPARATOR); + if (!StringUtils.isEmpty(branchKey)) { + keyByBranchKey.computeIfAbsent(branchKey, b -> new LinkedList<>()) + .add(StringUtils.substringBeforeLast(dbKey, ComponentDto.BRANCH_KEY_SEPARATOR)); + continue; + } + + String prKey = StringUtils.substringAfterLast(dbKey, ComponentDto.PULL_REQUEST_SEPARATOR); + if (!StringUtils.isEmpty(prKey)) { + keyByPrKey.computeIfAbsent(prKey, b -> new LinkedList<>()) + .add(StringUtils.substringBeforeLast(dbKey, ComponentDto.PULL_REQUEST_SEPARATOR)); + continue; + } + + mainBranchKeys.add(dbKey); + } + + List<ComponentDto> components = new LinkedList<>(); + for (Map.Entry<String, List<String>> e : keyByBranchKey.entrySet()) { + components.addAll(selectByKeysAndBranch(session, e.getValue(), e.getKey())); + } + for (Map.Entry<String, List<String>> e : keyByPrKey.entrySet()) { + components.addAll(selectByKeysAndPullRequest(session, e.getValue(), e.getKey())); + } + components.addAll(selectByKeys(session, mainBranchKeys)); + return components; } /** @@ -230,11 +239,7 @@ public class ComponentDao implements Dao { } public ComponentDto selectOrFailByKey(DbSession session, String key) { - Optional<ComponentDto> component = selectByKey(session, key); - if (!component.isPresent()) { - throw new RowNotFoundException(String.format("Component key '%s' not found", key)); - } - return component.get(); + return selectByKey(session, key).orElseThrow(() -> new RowNotFoundException(String.format("Component key '%s' not found", key))); } public Optional<ComponentDto> selectByKey(DbSession session, String key) { @@ -246,14 +251,14 @@ public class ComponentDao implements Dao { } public Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) { - return Optional.ofNullable(mapper(session).selectBranchByKeyAndBranchKey(key, generateBranchKey(key, branch), branch)); + return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, branch)); } public Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) { - return Optional.ofNullable(mapper(session).selectPrByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId)); + return Optional.ofNullable(mapper(session).selectByKeyAndPrKey(key, pullRequestId)); } - public List<UuidWithProjectUuidDto> selectAllViewsAndSubViews(DbSession session) { + public List<UuidWithBranchUuidDto> selectAllViewsAndSubViews(DbSession session) { return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW); } @@ -295,12 +300,12 @@ public class ComponentDao implements Dao { } /** - * Retrieves all components with a specific root project Uuid, no other filtering is done by this method. + * Retrieves all components with a specific branch UUID, no other filtering is done by this method. * <p> * Used by Views plugin */ - public List<ComponentDto> selectByProjectUuid(String projectUuid, DbSession dbSession) { - return mapper(dbSession).selectByProjectUuid(projectUuid); + public List<ComponentDto> selectByBranchUuid(String branchUuid, DbSession dbSession) { + return mapper(dbSession).selectByBranchUuid(branchUuid); } /** @@ -340,8 +345,8 @@ public class ComponentDao implements Dao { * Scroll all <strong>enabled</strong> files of the specified project (same project_uuid) in no specific order with * 'SOURCE' source and a non null path. */ - public void scrollAllFilesForFileMove(DbSession session, String projectUuid, ResultHandler<FileMoveRowDto> handler) { - mapper(session).scrollAllFilesForFileMove(projectUuid, handler); + public void scrollAllFilesForFileMove(DbSession session, String branchUuid, ResultHandler<FileMoveRowDto> handler) { + mapper(session).scrollAllFilesForFileMove(branchUuid, handler); } public void insert(DbSession session, ComponentDto item) { @@ -373,23 +378,23 @@ public class ComponentDao implements Dao { executeLargeUpdates(uuids, mapper(session)::updateBEnabledToFalse); } - public void applyBChangesForRootComponentUuid(DbSession session, String projectUuid) { - mapper(session).applyBChangesForRootComponentUuid(projectUuid); + public void applyBChangesForRootComponentUuid(DbSession session, String branchUuid) { + mapper(session).applyBChangesForRootComponentUuid(branchUuid); } - public void resetBChangedForRootComponentUuid(DbSession session, String projectUuid) { - mapper(session).resetBChangedForRootComponentUuid(projectUuid); + public void resetBChangedForRootComponentUuid(DbSession session, String branchUuid) { + mapper(session).resetBChangedForRootComponentUuid(branchUuid); } - public void setPrivateForRootComponentUuidWithoutAudit(DbSession session, String projectUuid, boolean isPrivate) { - mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate); + public void setPrivateForRootComponentUuidWithoutAudit(DbSession session, String branchUuid, boolean isPrivate) { + mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } - public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate, + public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, @Nullable String qualifier, String componentKey, String componentName) { - ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, componentKey, isPrivate, qualifier); + ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier); auditPersister.updateComponentVisibility(session, componentNewValue); - mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate); + mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } private static void checkThatNotTooManyComponents(ComponentQuery query) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java index a3818109278..cb17c2a859e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java @@ -24,7 +24,6 @@ import com.google.common.base.Strings; import java.util.Date; import java.util.List; import java.util.Objects; -import java.util.regex.Pattern; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ToStringBuilder; @@ -47,7 +46,6 @@ public class ComponentDto { public static final String BRANCH_KEY_SEPARATOR = ":BRANCH:"; public static final String PULL_REQUEST_SEPARATOR = ":PULL_REQUEST:"; - private static final Splitter BRANCH_OR_PULL_REQUEST_SPLITTER = Splitter.on(Pattern.compile(BRANCH_KEY_SEPARATOR + "|" + PULL_REQUEST_SEPARATOR)); private static final Splitter BRANCH_KEY_SPLITTER = Splitter.on(BRANCH_KEY_SEPARATOR); private static final Splitter PULL_REQUEST_SPLITTER = Splitter.on(PULL_REQUEST_SEPARATOR); @@ -93,7 +91,7 @@ public class ComponentDto { * - on view: UUID="5" PROJECT_UUID="5" * - on sub-view: UUID="6" PROJECT_UUID="5" */ - private String projectUuid; + private String branchUuid; /** * Badly named, it is not the root ! @@ -177,24 +175,16 @@ public class ComponentDto { return UUID_PATH_SPLITTER.splitToList(uuidPath); } - public String getDbKey() { + public String getKey() { return kee; } - public ComponentDto setDbKey(String key) { + public ComponentDto setKey(String key) { this.kee = checkComponentKey(key); return this; } /** - * The key to be displayed to user, doesn't contain information on branches - */ - public String getKey() { - List<String> split = BRANCH_OR_PULL_REQUEST_SPLITTER.splitToList(kee); - return split.size() == 2 ? split.get(0) : kee; - } - - /** * @return the key of the branch. It will be null on the main branch and when the component is not on a branch */ @CheckForNull @@ -233,12 +223,12 @@ public class ComponentDto { /** * Return the root project uuid. On a root project, return itself */ - public String projectUuid() { - return projectUuid; + public String branchUuid() { + return branchUuid; } - public ComponentDto setProjectUuid(String projectUuid) { - this.projectUuid = projectUuid; + public ComponentDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; return this; } @@ -320,7 +310,7 @@ public class ComponentDto { } /** - * Use {@link #projectUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()} + * Use {@link #branchUuid()}, {@link #moduleUuid()} or {@link #moduleUuidPath()} */ @Deprecated public String getRootUuid() { @@ -409,7 +399,7 @@ public class ComponentDto { .append("kee", kee) .append("scope", scope) .append("qualifier", qualifier) - .append("projectUuid", projectUuid) + .append("branchUuid", branchUuid) .append("moduleUuid", moduleUuid) .append("moduleUuidPath", moduleUuidPath) .append("rootUuid", rootUuid) @@ -426,11 +416,10 @@ public class ComponentDto { public ComponentDto copy() { ComponentDto copy = new ComponentDto(); - copy.projectUuid = projectUuid; copy.kee = kee; copy.uuid = uuid; copy.uuidPath = uuidPath; - copy.projectUuid = projectUuid; + copy.branchUuid = branchUuid; copy.rootUuid = rootUuid; copy.mainBranchProjectUuid = mainBranchProjectUuid; copy.moduleUuid = moduleUuid; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index e62a69a23b7..98297278093 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -37,10 +37,10 @@ public interface ComponentMapper { ComponentDto selectByKeyCaseInsensitive(@Param("key") String key); @CheckForNull - ComponentDto selectBranchByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); + ComponentDto selectByKeyAndBranchKey(@Param("key") String key, @Param("branch") String branch); @CheckForNull - ComponentDto selectPrByKeyAndBranchKey(@Param("key") String key, @Param("dbKey") String dbKey, @Param("branch") String branch); + ComponentDto selectByKeyAndPrKey(@Param("key") String key, @Param("pr") String pr); @CheckForNull ComponentDto selectByUuid(@Param("uuid") String uuid); @@ -52,19 +52,17 @@ public interface ComponentMapper { List<ComponentDto> selectByKeys(@Param("keys") Collection<String> keys); - List<ComponentDto> selectByDbKeys(@Param("dbKeys") Collection<String> dbKeys); - List<ComponentDto> selectByKeysAndBranch(@Param("keys") Collection<String> keys, @Param("branch") String branch); List<ComponentDto> selectByUuids(@Param("uuids") Collection<String> uuids); - List<ComponentDto> selectByProjectUuid(@Param("projectUuid") String projectUuid); + List<ComponentDto> selectByBranchUuid(@Param("branchUuid") String branchUuid); List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids); List<ComponentDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> qualifiers); - int countEnabledModulesByProjectUuid(@Param("projectUuid") String projectUuid); + int countEnabledModulesByBranchUuid(@Param("branchUuid") String branchUuid); List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds); @@ -103,7 +101,7 @@ public interface ComponentMapper { * <p/> * It's using a join on snapshots in order to use he indexed columns snapshots.qualifier */ - List<UuidWithProjectUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); + List<UuidWithBranchUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); /** * Return components of a given scope of a project @@ -127,7 +125,7 @@ public interface ComponentMapper { void scrollForIndexing(@Param("projectUuid") @Nullable String projectUuid, ResultHandler<ComponentDto> handler); - void scrollAllFilesForFileMove(@Param("projectUuid") String projectUuid, ResultHandler<FileMoveRowDto> handler); + void scrollAllFilesForFileMove(@Param("branchUuid") String branchUuid, ResultHandler<FileMoveRowDto> handler); void insert(ComponentDto componentDto); @@ -135,11 +133,11 @@ public interface ComponentMapper { void updateBEnabledToFalse(@Param("uuids") List<String> uuids); - void applyBChangesForRootComponentUuid(@Param("projectUuid") String projectUuid); + void applyBChangesForRootComponentUuid(@Param("branchUuid") String branchUuid); - void resetBChangedForRootComponentUuid(@Param("projectUuid") String projectUuid); + void resetBChangedForRootComponentUuid(@Param("branchUuid") String branchUuid); - void setPrivateForRootComponentUuid(@Param("projectUuid") String projectUuid, @Param("isPrivate") boolean isPrivate); + void setPrivateForRootComponentUuid(@Param("branchUuid") String branchUuid, @Param("isPrivate") boolean isPrivate); void delete(String componentUuid); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java index 90569194c85..7268d4b8aad 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentUpdateDto.java @@ -188,7 +188,7 @@ public class ComponentUpdateDto { return new ComponentUpdateDto() .setUuid(from.uuid()) .setBChanged(false) - .setBKey(from.getDbKey()) + .setBKey(from.getKey()) .setBCopyComponentUuid(from.getCopyComponentUuid()) .setBDescription(from.description()) .setBEnabled(from.isEnabled()) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithProjectUuidDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithBranchUuidDto.java index 96c5c1913c7..0794cfc99b4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithProjectUuidDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/UuidWithBranchUuidDto.java @@ -19,17 +19,17 @@ */ package org.sonar.db.component; -public class UuidWithProjectUuidDto { +public class UuidWithBranchUuidDto { private String uuid; - private String projectUuid; + private String branchUuid; - public String getProjectUuid() { - return projectUuid; + public String getBranchUuid() { + return branchUuid; } - public UuidWithProjectUuidDto setProjectUuid(String projectUuid) { - this.projectUuid = projectUuid; + public UuidWithBranchUuidDto setBranchUuid(String branchUuid) { + this.branchUuid = branchUuid; return this; } @@ -37,7 +37,7 @@ public class UuidWithProjectUuidDto { return uuid; } - public UuidWithProjectUuidDto setUuid(String uuid) { + public UuidWithBranchUuidDto setUuid(String uuid) { this.uuid = uuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java index 00a47fe64ee..80ccda2b0d7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDao.java @@ -101,7 +101,7 @@ public class IssueDao implements Dao { public List<IssueDto> selectNonClosedByModuleOrProjectExcludingExternalsAndSecurityHotspots(DbSession dbSession, ComponentDto module) { String likeModuleUuidPath = buildLikeValue(module.moduleUuidPath(), WildcardPosition.AFTER); - return mapper(dbSession).selectNonClosedByModuleOrProject(module.projectUuid(), likeModuleUuidPath); + return mapper(dbSession).selectNonClosedByModuleOrProject(module.branchUuid(), likeModuleUuidPath); } public List<PrIssueDto> selectOpenByComponentUuids(DbSession dbSession, Collection<String> componentUuids) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index 7611cff2f3c..2e9fa59db67 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -206,7 +206,7 @@ public final class IssueDto implements Serializable { } public IssueDto setComponent(ComponentDto component) { - this.componentKey = component.getDbKey(); + this.componentKey = component.getKey(); this.componentUuid = component.uuid(); this.moduleUuidPath = component.moduleUuidPath(); this.filePath = component.path(); @@ -214,7 +214,7 @@ public final class IssueDto implements Serializable { } public IssueDto setProject(ComponentDto project) { - this.projectKey = project.getDbKey(); + this.projectKey = project.getKey(); this.projectUuid = project.uuid(); return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java index 056a1651b2d..6addf4b8359 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java @@ -47,7 +47,7 @@ public class IssueTesting { public static IssueDto newIssue(RuleDto rule, ComponentDto project, ComponentDto file) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT), "Second parameter should be a project"); - return newIssue(rule, project.uuid(), project.getDbKey(), file); + return newIssue(rule, project.uuid(), project.getKey(), file); } public static IssueDto newIssue(RuleDto rule, ProjectDto project, ComponentDto file) { @@ -55,7 +55,7 @@ public class IssueTesting { } public static IssueDto newIssue(RuleDto rule, String projectUuid, String projectKey, ComponentDto file) { - checkArgument(file.projectUuid().equals(projectUuid), "The file doesn't belong to the project"); + checkArgument(file.branchUuid().equals(projectUuid), "The file doesn't belong to the project"); return new IssueDto() .setKee("uuid_" + randomAlphabetic(5)) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index cd3f294fcc6..1e8687178d4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -34,11 +34,11 @@ public interface PurgeMapper { */ List<String> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid); - Set<String> selectDisabledComponentsWithFileSource(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithFileSource(@Param("branchUuid") String branchUuid); - Set<String> selectDisabledComponentsWithUnresolvedIssues(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithUnresolvedIssues(@Param("branchUuid") String branchUuid); - Set<String> selectDisabledComponentsWithLiveMeasures(@Param("projectUuid") String projectUuid); + Set<String> selectDisabledComponentsWithLiveMeasures(@Param("branchUuid") String branchUuid); void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids); @@ -97,7 +97,7 @@ public interface PurgeMapper { @CheckForNull String selectSpecificAnalysisNewCodePeriod(@Param("projectUuid") String projectUuid); - List<String> selectDisabledComponentsWithoutIssues(@Param("projectUuid") String projectUuid); + List<String> selectDisabledComponentsWithoutIssues(@Param("branchUuid") String branchUuid); void deleteIssuesFromKeys(@Param("keys") List<String> keys); 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 0cdef645451..246dc8bbf43 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 @@ -225,8 +225,7 @@ select case when exists ( - select pb.project_uuid, pb.need_issue_sync from project_branches pb join components c on pb.project_uuid = - c.project_uuid + select pb.project_uuid, pb.need_issue_sync from project_branches pb join components c on pb.project_uuid = c.branch_uuid where c.kee in <foreach collection="componentKeys" open="(" close=")" item="componentKey" separator=","> #{componentKey,jdbcType=VARCHAR} 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 aed19c345e9..c25cc05c20b 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 @@ -5,7 +5,7 @@ <sql id="componentColumns"> p.uuid as uuid, p.uuid_path as uuidPath, - p.project_uuid as projectUuid, + p.branch_uuid as branchUuid, p.module_uuid as moduleUuid, p.module_uuid_path as moduleUuidPath, p.main_branch_project_uuid as mainBranchProjectUuid, @@ -30,6 +30,7 @@ FROM components p where p.kee=#{key,jdbcType=VARCHAR} + and p.main_branch_project_uuid is null </select> <select id="selectByKeyCaseInsensitive" parameterType="String" resultType="Component"> @@ -40,25 +41,25 @@ lower(p.kee)=lower(#{key,jdbcType=VARCHAR}) </select> - <select id="selectBranchByKeyAndBranchKey" parameterType="String" resultType="Component"> + <select id="selectByKeyAndBranchKey" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from components p - inner join project_branches pb on pb.uuid = p.project_uuid + inner join project_branches pb on pb.uuid = p.branch_uuid where - (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) + p.kee=#{key,jdbcType=VARCHAR} and pb.kee=#{branch,jdbcType=VARCHAR} - and (pb.branch_type='BRANCH') + and pb.branch_type='BRANCH' </select> - <select id="selectPrByKeyAndBranchKey" parameterType="String" resultType="Component"> + <select id="selectByKeyAndPrKey" parameterType="String" resultType="Component"> select <include refid="componentColumns"/> from components p - inner join project_branches pb on pb.uuid = p.project_uuid + inner join project_branches pb on pb.uuid = p.branch_uuid where - (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR}) - and pb.kee=#{branch,jdbcType=VARCHAR} + p.kee=#{key,jdbcType=VARCHAR} + and pb.kee=#{pr,jdbcType=VARCHAR} and pb.branch_type='PULL_REQUEST' </select> @@ -70,13 +71,13 @@ p.uuid=#{uuid,jdbcType=VARCHAR} </select> - <select id="selectByProjectUuid" parameterType="string" resultType="Component"> + <select id="selectByBranchUuid" parameterType="string" resultType="Component"> select <include refid="componentColumns"/> from components root - inner join components p on p.project_uuid=root.uuid + inner join components p on p.branch_uuid=root.uuid where - root.uuid=#{projectUuid,jdbcType=VARCHAR} + root.uuid=#{branchUuid,jdbcType=VARCHAR} </select> <select id="selectByKeys" parameterType="String" resultType="Component"> @@ -92,23 +93,11 @@ </foreach> </select> - <select id="selectByDbKeys" parameterType="String" resultType="Component"> - select - <include refid="componentColumns"/> - from components p - where - p.enabled=${_true} - and p.kee in - <foreach collection="dbKeys" open="(" close=")" item="key" separator=","> - #{key,jdbcType=VARCHAR} - </foreach> - </select> - <select id="selectByKeysAndBranch" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM components p - INNER JOIN project_branches pb on pb.uuid = p.project_uuid + INNER JOIN project_branches pb on pb.uuid = p.branch_uuid <where> p.enabled=${_true} AND p.kee IN @@ -165,7 +154,7 @@ <sql id="modulesTreeQuery"> INNER JOIN components module ON - module.project_uuid = p.project_uuid + module.branch_uuid = p.branch_uuid and module.uuid = #{moduleUuid} and module.scope='PRJ' AND module.enabled = ${_true} where @@ -193,7 +182,7 @@ fs.revision FROM components root INNER JOIN components p on - p.project_uuid=root.uuid + p.branch_uuid=root.uuid and p.enabled=${_true} and p.scope='FIL' INNER JOIN file_sources fs ON @@ -236,13 +225,13 @@ </foreach> </select> - <select id="countEnabledModulesByProjectUuid" resultType="int"> + <select id="countEnabledModulesByBranchUuid" resultType="int"> select count(1) from components p where p.enabled=${_true} - and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.qualifier = 'BRC' </select> @@ -388,7 +377,7 @@ <include refid="componentColumns"/> from components p where - p.project_uuid = #{branchUuid,jdbcType=VARCHAR} + p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.uuid_path in <foreach collection="uuidPaths" item="uuidPath" open="(" close=")" separator=","> #{uuidPath,jdbcType=VARCHAR} @@ -407,7 +396,7 @@ </select> <sql id="selectDescendantsJoins"> - inner join components base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid} + inner join components base on base.branch_uuid = p.branch_uuid and base.uuid = #{baseUuid} <choose> <when test="query.getStrategy().name() == 'CHILDREN'"> and p.uuid_path = #{baseUuidPath,jdbcType=VARCHAR} @@ -441,8 +430,8 @@ </if> </sql> - <select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid"> - SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM components p + <select id="selectUuidsForQualifiers" resultType="UuidWithBranchUuid"> + SELECT p.uuid as "uuid", p.branch_uuid as "branchUuid" FROM components p where <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR "> p.qualifier=#{qualifier,jdbcType=VARCHAR} @@ -461,7 +450,7 @@ <foreach collection="projectUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach> where p.enabled = ${_true} - and p.uuid = leaf.project_uuid + and p.uuid = leaf.branch_uuid and p.scope = 'PRJ' and p.qualifier in ('VW', 'APP') </select> @@ -470,7 +459,7 @@ from components p where p.enabled = ${_true} - and p.project_uuid = #{projectViewUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{projectViewUuid,jdbcType=VARCHAR} <choose> <when test="_databaseId == 'mssql'"> and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR} {escape '\'} @@ -487,7 +476,7 @@ SELECT <include refid="componentColumns"/> FROM components p - INNER JOIN components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} + INNER JOIN components root ON root.uuid=p.branch_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} <where> <if test="excludeDisabled"> p.enabled = ${_true} @@ -504,7 +493,7 @@ FROM components p INNER JOIN - components root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} + components root ON root.uuid=p.branch_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR} </select> <select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid"> @@ -513,7 +502,7 @@ FROM components p INNER JOIN - components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} + components root ON root.uuid=p.branch_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR} </select> <select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> @@ -527,7 +516,7 @@ and p.scope = 'PRJ' and p.qualifier in ('TRK','VW','SVW','APP') <if test="projectUuid != null"> - and p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid = #{projectUuid,jdbcType=VARCHAR} </if> </select> @@ -541,7 +530,7 @@ inner join file_sources fs on fs.file_uuid = p.uuid where - p.project_uuid = #{projectUuid,jdbcType=VARCHAR} + p.branch_uuid = #{branchUuid,jdbcType=VARCHAR} and p.enabled = ${_true} and p.scope = 'FIL' and p.qualifier in ('FIL', 'UTS') @@ -553,7 +542,7 @@ kee, uuid, uuid_path, - project_uuid, + branch_uuid, module_uuid, module_uuid_path, main_branch_project_uuid, @@ -586,7 +575,7 @@ #{kee,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{uuidPath,jdbcType=VARCHAR}, - #{projectUuid,jdbcType=VARCHAR}, + #{branchUuid,jdbcType=VARCHAR}, #{moduleUuid,jdbcType=VARCHAR}, #{moduleUuidPath,jdbcType=VARCHAR}, #{mainBranchProjectUuid, jdbcType=VARCHAR}, @@ -699,7 +688,7 @@ b_path = null, b_qualifier = null where - project_uuid = #{projectUuid,jdbcType=VARCHAR} and + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> @@ -709,7 +698,7 @@ <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules --> deprecated_kee = kee where - project_uuid = #{projectUuid,jdbcType=VARCHAR} and + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and b_changed = ${_true} </update> @@ -717,7 +706,7 @@ update components set private = #{isPrivate,jdbcType=BOOLEAN} where - project_uuid = #{projectUuid,jdbcType=VARCHAR} + branch_uuid = #{branchUuid,jdbcType=VARCHAR} and private <> #{isPrivate,jdbcType=BOOLEAN} </update> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml index 513386f1322..575645a72c6 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml @@ -38,7 +38,7 @@ <select id="selectLastSnapshotByComponentUuid" resultType="Snapshot"> select <include refid="snapshotColumns" /> from snapshots s - inner join components p on s.component_uuid = p.project_uuid + inner join components p on s.component_uuid = p.branch_uuid where s.islast=${_true} and p.uuid = #{componentUuid,jdbcType=VARCHAR} @@ -47,10 +47,10 @@ <select id="selectLastAnalysisDateByProject" resultType="long"> select max(s.created_at) from snapshots s - inner join components p on s.component_uuid = p.project_uuid + inner join components p on s.component_uuid = p.branch_uuid where s.islast=${_true} - and coalesce(p.main_branch_project_uuid, p.project_uuid) = #{projectUuid,jdbcType=VARCHAR} + and coalesce(p.main_branch_project_uuid, p.branch_uuid) = #{projectUuid,jdbcType=VARCHAR} </select> <select id="selectLastAnalysisDateByProjects" resultType="org.sonar.db.component.ProjectLastAnalysisDateDto"> @@ -65,7 +65,7 @@ from snapshots s inner join components c on - s.component_uuid = c.project_uuid + s.component_uuid = c.branch_uuid where s.islast = ${_true} and c.main_branch_project_uuid in @@ -76,21 +76,21 @@ c.main_branch_project_uuid union select - c.project_uuid as project_uuid, + c.branch_uuid as project_uuid, max(s.created_at) as last_analysis_date from snapshots s inner join components c on - s.component_uuid = c.project_uuid + s.component_uuid = c.branch_uuid where s.islast = ${_true} and c.main_branch_project_uuid is null - and c.project_uuid in + and c.branch_uuid in <foreach collection="projectUuids" item="projectUuid" separator="," open="(" close=")"> #{projectUuid,jdbcType=VARCHAR} </foreach> group by - c.project_uuid + c.branch_uuid ) result_with_duplicates group by result_with_duplicates.project_uuid diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 20df7611c2b..db14d3c6646 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -69,7 +69,7 @@ components p where ( - p.project_uuid=#{rootUuid,jdbcType=VARCHAR} + p.branch_uuid=#{rootUuid,jdbcType=VARCHAR} and p.scope = 'PRJ' and p.qualifier in ('SVW','BRC') ) or ( @@ -85,7 +85,7 @@ inner join components p on p.uuid = fs.file_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} </select> <select id="selectDisabledComponentsWithUnresolvedIssues" parameterType="map" resultType="String"> @@ -95,7 +95,7 @@ inner join components p on p.uuid = i.component_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} where resolution is null </select> @@ -107,7 +107,7 @@ inner join components p on p.uuid = lm.component_uuid and p.enabled = ${_false} - and p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} </select> <delete id="deleteAnalysisMeasures" parameterType="map"> @@ -220,7 +220,7 @@ <delete id="deleteComponentsByProjectUuid" parameterType="map"> delete from components where - project_uuid = #{rootUuid,jdbcType=VARCHAR} + branch_uuid = #{rootUuid,jdbcType=VARCHAR} </delete> <delete id="deleteComponentsByMainBranchProjectUuid" parameterType="map"> @@ -322,7 +322,7 @@ components p WHERE p.enabled = ${_false} - AND p.project_uuid=#{projectUuid,jdbcType=VARCHAR} + AND p.branch_uuid=#{branchUuid,jdbcType=VARCHAR} AND NOT EXISTS (SELECT 1 FROM issues i WHERE i.component_uuid = p.uuid) </select> |