aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/main/java
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-10-23 15:33:39 -0500
committerSonarTech <sonartech@sonarsource.com>2020-01-31 20:46:09 +0100
commitace9a50d55d831ec71b7db421aa04d1198392c6c (patch)
tree3bf598bfe3f760d45310b2a65d014a53370a9930 /server/sonar-db-dao/src/main/java
parent1ff9a01fd6e822793ef223f9ce259b15d17eecc4 (diff)
downloadsonarqube-ace9a50d55d831ec71b7db421aa04d1198392c6c.tar.gz
sonarqube-ace9a50d55d831ec71b7db421aa04d1198392c6c.zip
SONAR-12689 Separate storage of projects/apps from their components and branches
Diffstat (limited to 'server/sonar-db-dao/src/main/java')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java34
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java88
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java184
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java56
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java201
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/package-info.java24
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java22
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java9
26 files changed, 661 insertions, 64 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index 34f8d4e0d37..9cf5de73ba4 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -61,6 +61,7 @@ import org.sonar.db.permission.UserPermissionDao;
import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
import org.sonar.db.permission.template.PermissionTemplateDao;
import org.sonar.db.plugin.PluginDao;
+import org.sonar.db.project.ProjectDao;
import org.sonar.db.property.InternalComponentPropertiesDao;
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
@@ -135,6 +136,7 @@ public class DaoModule extends Module {
PermissionTemplateCharacteristicDao.class,
PermissionTemplateDao.class,
PluginDao.class,
+ ProjectDao.class,
ProjectLinkDao.class,
ProjectMappingsDao.class,
ProjectQgateAssociationDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index c7a3bea3ce1..9707a025944 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -59,6 +59,7 @@ import org.sonar.db.permission.UserPermissionDao;
import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
import org.sonar.db.permission.template.PermissionTemplateDao;
import org.sonar.db.plugin.PluginDao;
+import org.sonar.db.project.ProjectDao;
import org.sonar.db.property.InternalComponentPropertiesDao;
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
@@ -158,6 +159,7 @@ public class DbClient {
private final ProjectMappingsDao projectMappingsDao;
private final OrganizationAlmBindingDao organizationAlmBindingDao;
private final NewCodePeriodDao newCodePeriodDao;
+ private final ProjectDao projectDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
@@ -233,6 +235,7 @@ public class DbClient {
organizationAlmBindingDao = getDao(map, OrganizationAlmBindingDao.class);
internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class);
newCodePeriodDao = getDao(map, NewCodePeriodDao.class);
+ projectDao = getDao(map, ProjectDao.class);
}
public DbSession openSession(boolean batch) {
@@ -311,6 +314,10 @@ public class DbClient {
return componentDao;
}
+ public ProjectDao projectDao() {
+ return projectDao;
+ }
+
public ComponentKeyUpdaterDao componentKeyUpdaterDao() {
return componentKeyUpdaterDao;
}
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 53cd1122e1c..0fc20ca8a47 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
@@ -102,6 +102,8 @@ import org.sonar.db.permission.template.PermissionTemplateMapper;
import org.sonar.db.permission.template.PermissionTemplateUserDto;
import org.sonar.db.plugin.PluginDto;
import org.sonar.db.plugin.PluginMapper;
+import org.sonar.db.project.ProjectDto;
+import org.sonar.db.project.ProjectMapper;
import org.sonar.db.property.InternalComponentPropertiesMapper;
import org.sonar.db.property.InternalComponentPropertyDto;
import org.sonar.db.property.InternalPropertiesMapper;
@@ -202,6 +204,7 @@ public class MyBatis implements Startable {
confBuilder.loadAlias("PrIssue", PrIssueDto.class);
confBuilder.loadAlias("ProjectAlmBinding", ProjectAlmBindingDto.class);
confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class);
+ confBuilder.loadAlias("Project", ProjectDto.class);
confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class);
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class);
@@ -267,6 +270,7 @@ public class MyBatis implements Startable {
ProjectAlmBindingMapper.class,
ProjectAlmSettingMapper.class,
ProjectLinkMapper.class,
+ ProjectMapper.class,
ProjectMappingsMapper.class,
ProjectQgateAssociationMapper.class,
PropertiesMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
index 7d73d4c341c..7e67ce74e70 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java
@@ -25,6 +25,7 @@ import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
public class ProjectAlmSettingDao implements Dao {
@@ -49,8 +50,8 @@ public class ProjectAlmSettingDao implements Dao {
projectAlmSettingDto.setUpdatedAt(now);
}
- public void deleteByProject(DbSession dbSession, ComponentDto project) {
- getMapper(dbSession).deleteByProjectUuid(project.uuid());
+ public void deleteByProject(DbSession dbSession, ProjectDto project) {
+ getMapper(dbSession).deleteByProjectUuid(project.getUuid());
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
@@ -61,8 +62,8 @@ public class ProjectAlmSettingDao implements Dao {
return getMapper(dbSession).countByAlmSettingUuid(almSetting.getUuid());
}
- public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, ComponentDto project) {
- return selectByProject(dbSession, project.uuid());
+ public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, ProjectDto project) {
+ return selectByProject(dbSession, project.getUuid());
}
public Optional<ProjectAlmSettingDto> selectByProject(DbSession dbSession, String projectUuid) {
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 434e04f1b51..bc116be2d0b 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
@@ -20,11 +20,14 @@
package org.sonar.db.component;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.project.ProjectDto;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
@@ -72,6 +75,13 @@ public class BranchDao implements Dao {
return selectByKey(dbSession, projectUuid, key, KeyType.BRANCH);
}
+ public List<BranchDto> selectByBranchKeys(DbSession dbSession, Map<String, String> branchKeyByProjectUuid) {
+ if (branchKeyByProjectUuid.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return mapper(dbSession).selectByBranchKeys(branchKeyByProjectUuid);
+ }
+
public Optional<BranchDto> selectByPullRequestKey(DbSession dbSession, String projectUuid, String key) {
return selectByKey(dbSession, projectUuid, key, KeyType.PULL_REQUEST);
}
@@ -88,6 +98,10 @@ public class BranchDao implements Dao {
return mapper(dbSession).selectByProjectUuid(projectUuid);
}
+ public Collection<BranchDto> selectByProject(DbSession dbSession, ProjectDto project) {
+ return mapper(dbSession).selectByProjectUuid(project.getUuid());
+ }
+
public List<BranchDto> selectByUuids(DbSession session, Collection<String> uuids) {
return executeLargeInputs(uuids, mapper(session)::selectByUuids);
}
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 997d3a59516..fc7987f4572 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
@@ -21,8 +21,10 @@ package org.sonar.db.component;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
+import org.sonar.db.DbSession;
public interface BranchMapper {
@@ -43,6 +45,8 @@ public interface BranchMapper {
Collection<BranchDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
+ List<BranchDto> selectByBranchKeys(@Param("branchKeyByProjectUuid") Map<String, String> branchKeyByProjectUuid);
+
List<BranchDto> selectByUuids(@Param("uuids") Collection<String> uuids);
long countNonMainBranches();
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 710ef904c0f..54f0ba7b0df 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
@@ -73,14 +73,6 @@ public class ComponentDao implements Dao {
return mapper(session).countByQuery(organizationUuid, query);
}
- @CheckForNull
- private static String buildUpperLikeSql(@Nullable String textQuery) {
- if (isBlank(textQuery)) {
- return null;
- }
- return buildLikeValue(textQuery.toUpperCase(Locale.ENGLISH), BEFORE_AND_AFTER);
- }
-
private static ComponentMapper mapper(DbSession session) {
return session.getMapper(ComponentMapper.class);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
index 10495b676b6..61dcb2242b6 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
@@ -20,7 +20,6 @@
package org.sonar.db.component;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.HashMap;
@@ -36,10 +35,10 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Scopes;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
-import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.core.component.ComponentKeys.checkProjectKey;
/**
@@ -48,25 +47,21 @@ import static org.sonar.core.component.ComponentKeys.checkProjectKey;
* @since 3.2
*/
public class ComponentKeyUpdaterDao implements Dao {
-
- private static final Set<String> PROJECT_OR_MODULE_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.MODULE);
-
- public void updateKey(DbSession dbSession, String projectOrModuleUuid, String newKey) {
+ public void updateKey(DbSession dbSession, String projectUuid, String newKey) {
ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class);
if (mapper.countResourceByKey(newKey) > 0) {
throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists.");
}
// must SELECT first everything
- ResourceDto project = mapper.selectProjectByUuid(projectOrModuleUuid);
+ ResourceDto project = mapper.selectProjectByUuid(projectUuid);
String projectOldKey = project.getKey();
- List<ResourceDto> resources = mapper.selectProjectResources(projectOrModuleUuid);
+ List<ResourceDto> resources = mapper.selectProjectResources(projectUuid);
resources.add(project);
// add branch components
- dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectOrModuleUuid)
- .stream()
- .filter(branch -> !projectOrModuleUuid.equals(branch.getUuid()))
+ dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid).stream()
+ .filter(branch -> !projectUuid.equals(branch.getUuid()))
.forEach(branch -> {
resources.addAll(mapper.selectProjectResources(branch.getUuid()));
resources.add(mapper.selectProjectByUuid(branch.getUuid()));
@@ -77,10 +72,6 @@ public class ComponentKeyUpdaterDao implements Dao {
});
}
- public static void checkIsProjectOrModule(ComponentDto component) {
- checkArgument(PROJECT_OR_MODULE_QUALIFIERS.contains(component.qualifier()), "Component updated must be a module or a key");
- }
-
/**
*
* @return a map with currentKey/newKey is a bulk update was executed
@@ -118,8 +109,7 @@ public class ComponentKeyUpdaterDao implements Dao {
// add branches (no check should be done as branch keys cannot be changed by the user)
Map<String, String> branchBaseKeys = new HashMap<>();
- session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid)
- .stream()
+ session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid).stream()
.filter(branch -> !projectUuid.equals(branch.getUuid()))
.forEach(branch -> {
Set<ResourceDto> branchModules = collectAllModules(branch.getUuid(), stringToReplace, mapper, true);
@@ -167,14 +157,18 @@ public class ComponentKeyUpdaterDao implements Dao {
@Nullable BiConsumer<ResourceDto, String> consumer) {
for (ResourceDto resource : resources) {
String oldResourceKey = resource.getKey();
- String newResourceKey = newKey + oldResourceKey.substring(oldKey.length(), oldResourceKey.length());
+ String newResourceKey = newKey + oldResourceKey.substring(oldKey.length());
resource.setKey(newResourceKey);
String oldResourceDeprecatedKey = resource.getDeprecatedKey();
if (StringUtils.isNotBlank(oldResourceDeprecatedKey)) {
- String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length(), oldResourceDeprecatedKey.length());
+ String newResourceDeprecatedKey = newKey + oldResourceDeprecatedKey.substring(oldKey.length());
resource.setDeprecatedKey(newResourceDeprecatedKey);
}
- mapper.update(resource);
+ mapper.updateComponent(resource);
+ if (resource.getScope().equals(Scopes.PROJECT) && (resource.getQualifier().equals(Qualifiers.PROJECT) || resource.getQualifier().equals(Qualifiers.APP))) {
+ mapper.updateProject(oldResourceKey, newResourceKey);
+ }
+
if (consumer != null) {
consumer.accept(resource, oldResourceKey);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java
index c5c560db291..64c14ffce0b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java
@@ -32,6 +32,8 @@ public interface ComponentKeyUpdaterMapper {
List<ResourceDto> selectDescendantProjects(@Param("rootUuid") String rootUuid);
- void update(ResourceDto resource);
+ void updateComponent(ResourceDto resource);
+
+ void updateProject(@Param("oldProjectKey") String oldProjectKey, @Param("newProjectKey") String newProjectKey);
}
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 c700eef4330..37f74824907 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
@@ -29,6 +29,7 @@ import org.sonar.api.utils.DateUtils;
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.core.util.Uuids;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
@@ -47,13 +48,22 @@ public class IssueTesting {
public static IssueDto newIssue(RuleDefinitionDto rule, ComponentDto project, ComponentDto file) {
checkArgument(project.qualifier().equals(Qualifiers.PROJECT), "Second parameter should be a project");
- checkArgument(file.projectUuid().equals(project.uuid()), "The file doesn't belong to the project");
+ return newIssue(rule, project.uuid(), project.getDbKey(), file);
+ }
+
+ public static IssueDto newIssue(RuleDefinitionDto rule, ProjectDto project, ComponentDto file) {
+ return newIssue(rule, project.getUuid(), project.getKey(), file);
+ }
+
+ public static IssueDto newIssue(RuleDefinitionDto rule, String projectUuid, String projectKey, ComponentDto file) {
+ checkArgument(file.projectUuid().equals(projectUuid), "The file doesn't belong to the project");
return new IssueDto()
.setKee("uuid_" + randomAlphabetic(5))
.setRule(rule)
.setType(RuleType.values()[nextInt(RuleType.values().length)])
- .setProject(project)
+ .setProjectUuid(projectUuid)
+ .setProjectKey(projectKey)
.setComponent(file)
.setStatus(Issue.STATUS_OPEN)
.setResolution(null)
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
index 593256b3066..6892169d1b3 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
@@ -69,10 +69,11 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
CoreMetrics.NEW_LINES_KEY,
CoreMetrics.NEW_RELIABILITY_RATING_KEY);
+ // TODO filter on enabled projects
private static final String SQL_PROJECTS = "SELECT p.organization_uuid, p.uuid, p.kee, p.name, s.created_at, p.tags " +
"FROM projects p " +
"LEFT OUTER JOIN snapshots s ON s.component_uuid=p.uuid AND s.islast=? " +
- "WHERE p.enabled=? AND p.scope=? AND p.qualifier=? and p.main_branch_project_uuid is null ";
+ "WHERE p.qualifier=?";
private static final String PROJECT_FILTER = " AND p.uuid=?";
@@ -130,11 +131,9 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
}
PreparedStatement stmt = session.getConnection().prepareStatement(sql.toString());
stmt.setBoolean(1, true);
- stmt.setBoolean(2, true);
- stmt.setString(3, Scopes.PROJECT);
- stmt.setString(4, Qualifiers.PROJECT);
+ stmt.setString(2, Qualifiers.PROJECT);
if (projectUuid != null) {
- stmt.setString(5, projectUuid);
+ stmt.setString(3, projectUuid);
}
return stmt;
} catch (SQLException e) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
new file mode 100644
index 00000000000..25550fac2d2
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
@@ -0,0 +1,88 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.project;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class ProjectDao implements Dao {
+
+ public void insert(DbSession session, ProjectDto item) {
+ mapper(session).insert(item);
+ }
+
+ public Optional<ProjectDto> selectProjectByKey(DbSession session, String key) {
+ return Optional.ofNullable(mapper(session).selectProjectByKey(key));
+ }
+
+ public Optional<ProjectDto> selectApplicationByKey(DbSession session, String key) {
+ return Optional.ofNullable(mapper(session).selectApplicationByKey(key));
+ }
+
+ public Optional<ProjectDto> selectProjectOrAppByKey(DbSession session, String key) {
+ return Optional.ofNullable(mapper(session).selectProjectOrAppByKey(key));
+ }
+
+ public List<ProjectDto> selectProjectsByKeys(DbSession session, Set<String> keys) {
+ if (keys.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return mapper(session).selectProjectsByKeys(keys);
+ }
+
+ public List<ProjectDto> selectProjects(DbSession session) {
+ return mapper(session).selectProjects();
+ }
+
+ public Optional<ProjectDto> selectByUuid(DbSession session, String uuid) {
+ return Optional.ofNullable(mapper(session).selectByUuid(uuid));
+ }
+
+ public List<ProjectDto> selectByOrganizationUuid(DbSession session, String organizationUuid) {
+ return mapper(session).selectByOrganizationUuid(organizationUuid);
+ }
+
+ public List<ProjectDto> selectProjectsByOrganizationUuid(DbSession session, String organizationUuid) {
+ return mapper(session).selectProjectsByOrganizationUuid(organizationUuid);
+ }
+
+ public List<ProjectDto> selectByUuids(DbSession session, Set<String> uuids) {
+ if (uuids.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return mapper(session).selectByUuids(uuids);
+ }
+
+ public void updateTags(DbSession session, ProjectDto project) {
+ mapper(session).updateTags(project);
+ }
+
+ public void update(DbSession session, ProjectDto project) {
+ mapper(session).update(project);
+ }
+
+ private static ProjectMapper mapper(DbSession session) {
+ return session.getMapper(ProjectMapper.class);
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
new file mode 100644
index 00000000000..e01902c2eb5
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
@@ -0,0 +1,184 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.project;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static org.apache.commons.lang.StringUtils.trimToNull;
+import static org.sonar.db.component.DbTagsReader.readDbTags;
+
+public class ProjectDto {
+ private static final String TAGS_SEPARATOR = ",";
+ private String uuid;
+ private String kee;
+ private String qualifier;
+ private String name;
+ private String description;
+ private boolean isPrivate = false;
+ private String tags;
+ private long createdAt;
+ private long updatedAt;
+ private String organizationUuid;
+
+ public ProjectDto() {
+ // nothing to do here
+ }
+
+ public long getCreatedAt() {
+ return createdAt;
+ }
+
+ public ProjectDto setCreatedAt(long createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ public long getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public ProjectDto setUpdatedAt(long updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public ProjectDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ /**
+ * This is the getter used by MyBatis mapper.
+ */
+ public String getKee() {
+ return kee;
+ }
+
+ public String getKey() {
+ return getKee();
+ }
+
+ /**
+ * This is the setter used by MyBatis mapper.
+ */
+ public ProjectDto setKee(String kee) {
+ this.kee = kee;
+ return this;
+ }
+
+ public ProjectDto setKey(String key) {
+ return setKee(key);
+ }
+
+ public boolean isPrivate() {
+ return isPrivate;
+ }
+
+ public ProjectDto setPrivate(boolean aPrivate) {
+ isPrivate = aPrivate;
+ return this;
+ }
+
+ public List<String> getTags() {
+ return readDbTags(tags);
+ }
+
+ public ProjectDto setTags(List<String> tags) {
+ setTagsString(tags.stream()
+ .filter(t -> !t.isEmpty())
+ .collect(Collectors.joining(TAGS_SEPARATOR)));
+ return this;
+ }
+
+ /**
+ * Used by MyBatis
+ */
+ @CheckForNull
+ public String getTagsString() {
+ return tags;
+ }
+
+ public ProjectDto setTagsString(@Nullable String tags) {
+ this.tags = trimToNull(tags);
+ return this;
+ }
+
+ public String getOrganizationUuid() {
+ return organizationUuid;
+ }
+
+ public ProjectDto setOrganizationUuid(String organizationUuid) {
+ this.organizationUuid = organizationUuid;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public ProjectDto setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @CheckForNull
+ public String getDescription() {
+ return description;
+ }
+
+ public ProjectDto setDescription(@Nullable String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public ProjectDto setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProjectDto that = (ProjectDto) o;
+ return Objects.equals(uuid, that.uuid);
+ }
+
+ @Override
+ public int hashCode() {
+ return uuid != null ? uuid.hashCode() : 0;
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
new file mode 100644
index 00000000000..754358ff2fe
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.project;
+
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import org.apache.ibatis.annotations.Param;
+
+public interface ProjectMapper {
+
+ void insert(ProjectDto project);
+
+ @CheckForNull
+ ProjectDto selectProjectByKey(String key);
+
+ @CheckForNull
+ ProjectDto selectApplicationByKey(String key);
+
+ @CheckForNull
+ ProjectDto selectProjectOrAppByKey(String key);
+
+ List<ProjectDto> selectProjectsByKeys(@Param("kees") Collection<String> kees);
+
+ @CheckForNull
+ ProjectDto selectByUuid(String uuid);
+
+ List<ProjectDto> selectByUuids(@Param("uuids") Collection<String> uuids);
+
+ List<ProjectDto> selectByOrganizationUuid(String organizationUuid);
+
+ void updateTags(ProjectDto project);
+
+ void update(ProjectDto project);
+
+ List<ProjectDto> selectProjects();
+
+ List<ProjectDto> selectProjectsByOrganizationUuid(String organizationUuid);
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java
new file mode 100644
index 00000000000..266191ec81f
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectQuery.java
@@ -0,0 +1,201 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.project;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+import java.util.stream.Stream;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.db.WildcardPosition;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.db.DaoUtils.buildLikeValue;
+
+public class ProjectQuery {
+ private final String nameOrKeyQuery;
+ private final boolean partialMatchOnKey;
+ private final Boolean isPrivate;
+ private final Set<String> projectUuids;
+ private final Set<String> projectKeys;
+ private final Long analyzedBefore;
+ private final Long anyBranchAnalyzedBefore;
+ private final Long anyBranchAnalyzedAfter;
+ private final Date createdAfter;
+ private final boolean onProvisionedOnly;
+
+ private ProjectQuery(ProjectQuery.Builder builder) {
+ this.nameOrKeyQuery = builder.nameOrKeyQuery;
+ this.partialMatchOnKey = builder.partialMatchOnKey != null && builder.partialMatchOnKey;
+ this.projectUuids = builder.projectUuids;
+ this.projectKeys = builder.projectKeys;
+ this.isPrivate = builder.isPrivate;
+ this.analyzedBefore = builder.analyzedBefore;
+ this.anyBranchAnalyzedBefore = builder.anyBranchAnalyzedBefore;
+ this.anyBranchAnalyzedAfter = builder.anyBranchAnalyzedAfter;
+ this.createdAfter = builder.createdAfter;
+ this.onProvisionedOnly = builder.onProvisionedOnly;
+ }
+
+ @CheckForNull
+ public String getNameOrKeyQuery() {
+ return nameOrKeyQuery;
+ }
+
+ /**
+ * Used by MyBatis mapper
+ */
+ @CheckForNull
+ public String getNameOrKeyUpperLikeQuery() {
+ return buildLikeValue(nameOrKeyQuery, WildcardPosition.BEFORE_AND_AFTER).toUpperCase(Locale.ENGLISH);
+ }
+
+ /**
+ * Used by MyBatis mapper
+ */
+ public boolean isPartialMatchOnKey() {
+ return partialMatchOnKey;
+ }
+
+ @CheckForNull
+ public Set<String> getProjectUuids() {
+ return projectUuids;
+ }
+
+ @CheckForNull
+ public Set<String> getProjectKeys() {
+ return projectKeys;
+ }
+
+ @CheckForNull
+ public Boolean getPrivate() {
+ return isPrivate;
+ }
+
+ @CheckForNull
+ public Long getAnalyzedBefore() {
+ return analyzedBefore;
+ }
+
+ @CheckForNull
+ public Long getAnyBranchAnalyzedBefore() {
+ return anyBranchAnalyzedBefore;
+ }
+
+ @CheckForNull
+ public Long getAnyBranchAnalyzedAfter() {
+ return anyBranchAnalyzedAfter;
+ }
+
+ @CheckForNull
+ public Date getCreatedAfter() {
+ return createdAfter;
+ }
+
+ public boolean isOnProvisionedOnly() {
+ return onProvisionedOnly;
+ }
+
+ boolean hasEmptySetOfProjects() {
+ return Stream.of(projectKeys, projectUuids)
+ .anyMatch(list -> list != null && list.isEmpty());
+ }
+
+ public static ProjectQuery.Builder builder() {
+ return new ProjectQuery.Builder();
+ }
+
+ public static class Builder {
+ private String nameOrKeyQuery;
+ private Boolean partialMatchOnKey;
+ private Boolean isPrivate;
+ private Set<String> projectUuids;
+ private Set<String> projectKeys;
+ private Long analyzedBefore;
+ private Long anyBranchAnalyzedBefore;
+ private Long anyBranchAnalyzedAfter;
+ private Date createdAfter;
+ private boolean onProvisionedOnly = false;
+
+ public ProjectQuery.Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) {
+ this.nameOrKeyQuery = nameOrKeyQuery;
+ return this;
+ }
+
+ /**
+ * Beware, can be resource intensive! Should be used with precautions.
+ */
+ public ProjectQuery.Builder setPartialMatchOnKey(@Nullable Boolean partialMatchOnKey) {
+ this.partialMatchOnKey = partialMatchOnKey;
+ return this;
+ }
+
+ public ProjectQuery.Builder setProjectUuids(@Nullable Set<String> projectUuids) {
+ this.projectUuids = projectUuids;
+ return this;
+ }
+
+ public ProjectQuery.Builder setProjectKeys(@Nullable Set<String> projectKeys) {
+ this.projectKeys = projectKeys;
+ return this;
+ }
+
+ public ProjectQuery.Builder setPrivate(@Nullable Boolean isPrivate) {
+ this.isPrivate = isPrivate;
+ return this;
+ }
+
+ public ProjectQuery.Builder setAnalyzedBefore(@Nullable Long l) {
+ this.analyzedBefore = l;
+ return this;
+ }
+
+ public ProjectQuery.Builder setAnyBranchAnalyzedBefore(@Nullable Long l) {
+ this.anyBranchAnalyzedBefore = l;
+ return this;
+ }
+
+ /**
+ * Filter on date of last analysis. On projects, all branches and pull requests are taken into
+ * account. For example the analysis of a branch is included in the filter
+ * even if the main branch has never been analyzed.
+ */
+ public ProjectQuery.Builder setAnyBranchAnalyzedAfter(@Nullable Long l) {
+ this.anyBranchAnalyzedAfter = l;
+ return this;
+ }
+
+ public ProjectQuery.Builder setCreatedAfter(@Nullable Date l) {
+ this.createdAfter = l;
+ return this;
+ }
+
+ public ProjectQuery.Builder setOnProvisionedOnly(boolean onProvisionedOnly) {
+ this.onProvisionedOnly = onProvisionedOnly;
+ return this;
+ }
+
+ public ProjectQuery build() {
+ checkArgument(nameOrKeyQuery != null || partialMatchOnKey == null, "A query must be provided if a partial match on key is specified.");
+ return new ProjectQuery(this);
+ }
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/package-info.java
new file mode 100644
index 00000000000..b2e9cab60f2
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.project;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
index 4e07b384823..b3a902160b1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
@@ -109,7 +109,7 @@ public class PropertiesDao implements Dao {
private static PreparedStatement createStatement(String projectUuid, Collection<String> dispatcherKeys, Connection connection) throws SQLException {
String sql = "SELECT count(1) FROM properties pp " +
- "left outer join projects pj on pp.resource_id = pj.id " +
+ "left outer join components pj on pp.resource_id = pj.id " +
"where pp.user_id is not null and (pp.resource_id is null or pj.uuid=?) " +
"and (" + repeat("pp.prop_key like ?", " or ", dispatcherKeys.size()) + ")";
PreparedStatement res = connection.prepareStatement(sql);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index 7fad045f441..1cfa3e45f7f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -283,6 +283,13 @@ class PurgeCommands {
profiler.stop();
}
+ void deleteProject(String projectUuid) {
+ profiler.start("deleteProject (projects)");
+ purgeMapper.deleteProjectsByProjectUuid(projectUuid);
+ session.commit();
+ profiler.stop();
+ }
+
void deleteComponents(List<String> componentUuids) {
if (componentUuids.isEmpty()) {
return;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index 7d335530f5b..107a444bfd9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -211,8 +211,7 @@ public class PurgeDao implements Dao {
PurgeMapper purgeMapper = mapper(session);
PurgeCommands purgeCommands = new PurgeCommands(session, profiler, system2);
- session.getMapper(BranchMapper.class).selectByProjectUuid(uuid)
- .stream()
+ session.getMapper(BranchMapper.class).selectByProjectUuid(uuid).stream()
.filter(branch -> !uuid.equals(branch.getUuid()))
.forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands));
@@ -242,6 +241,7 @@ public class PurgeDao implements Dao {
commands.deleteNewCodePeriods(rootUuid);
commands.deleteBranch(rootUuid);
commands.deleteComponents(rootUuid);
+ commands.deleteProject(rootUuid);
}
/**
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 bc712a70be2..049cb8792b6 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
@@ -74,6 +74,8 @@ public interface PurgeMapper {
void deleteComponentsByProjectUuid(@Param("rootUuid") String rootUuid);
+ void deleteProjectsByProjectUuid(@Param("projectUuid") String projectUuid);
+
void deleteComponentsByUuids(@Param("componentUuids") List<String> componentUuids);
void deleteGroupRolesByComponentId(@Param("rootId") long rootId);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java
index d16e00382fc..83ec55bb9fa 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java
@@ -31,11 +31,11 @@ public class ProjectQgateAssociationDao implements Dao {
}
/**
- * @return quality gate uuid if a specific Quality Gate has been defined for the given component uuid. <br>
+ * @return quality gate uuid if a specific Quality Gate has been defined for the given project uuid. <br>
* Returns <code>{@link Optional#empty()}</code> otherwise (ex: default quality gate applies)
*/
- public Optional<String> selectQGateUuidByComponentUuid(DbSession dbSession, String componentUuid) {
- String uuid = mapper(dbSession).selectQGateUuidByComponentUuid(componentUuid);
+ public Optional<String> selectQGateUuidByProjectUuid(DbSession dbSession, String projectUuid) {
+ String uuid = mapper(dbSession).selectQGateUuidByProjectUuid(projectUuid);
return Optional.ofNullable(uuid);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.java
index 36db6cce990..a2c68932497 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.java
@@ -28,7 +28,7 @@ public interface ProjectQgateAssociationMapper {
List<ProjectQgateAssociationDto> selectProjects(@Param("query") ProjectQgateAssociationQuery query);
@CheckForNull
- String selectQGateUuidByComponentUuid(String componentUuid);
+ String selectQGateUuidByProjectUuid(String projectUuid);
void deleteByProjectUuid(String projectUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
index 763b5ac08df..02deb13e0ac 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java
@@ -107,7 +107,7 @@ public class QualityGateDao implements Dao {
return session.getMapper(QualityGateMapper.class);
}
- public QualityGateDto selectByProjectUuid(DbSession dbSession, String uuid) {
- return mapper(dbSession).selectByProjectUuid(uuid);
+ public QualityGateDto selectByProjectUuid(DbSession dbSession, String projectUuid) {
+ return mapper(dbSession).selectByProjectUuid(projectUuid);
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
index 273c089addc..90f8d985a14 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
@@ -35,8 +35,8 @@ import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
import org.sonar.db.KeyLongValue;
import org.sonar.db.RowNotFoundException;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyList;
@@ -156,12 +156,12 @@ public class QualityProfileDao implements Dao {
}
@CheckForNull
- public QProfileDto selectAssociatedToProjectAndLanguage(DbSession dbSession, ComponentDto project, String language) {
- return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.projectUuid(), language);
+ public QProfileDto selectAssociatedToProjectAndLanguage(DbSession dbSession, ProjectDto project, String language) {
+ return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.getUuid(), language);
}
- public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ComponentDto project, Collection<String> languages) {
- return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), partition));
+ public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, ProjectDto project, Collection<String> languages) {
+ return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.getUuid(), partition));
}
public List<QProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
@@ -205,16 +205,16 @@ public class QualityProfileDao implements Dao {
return KeyLongValue.toMap(executeLargeInputs(profileUuids, partition -> mapper(dbSession).countProjectsByOrganizationAndProfiles(organization.getUuid(), partition)));
}
- public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
- mapper(dbSession).insertProjectProfileAssociation(project.uuid(), profile.getKee());
+ public void insertProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) {
+ mapper(dbSession).insertProjectProfileAssociation(project.getUuid(), profile.getKee());
}
- public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
- mapper(dbSession).deleteProjectProfileAssociation(project.uuid(), profile.getKee());
+ public void deleteProjectProfileAssociation(DbSession dbSession, ProjectDto project, QProfileDto profile) {
+ mapper(dbSession).deleteProjectProfileAssociation(project.getUuid(), profile.getKee());
}
- public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileUuid, String oldProfileUuid) {
- mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileUuid, oldProfileUuid);
+ public void updateProjectProfileAssociation(DbSession dbSession, ProjectDto project, String newProfileUuid, String oldProfileUuid) {
+ mapper(dbSession).updateProjectProfileAssociation(project.getUuid(), newProfileUuid, oldProfileUuid);
}
public void deleteProjectAssociationsByProfileUuids(DbSession dbSession, Collection<String> profileUuids) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
index 5a282bf4b90..f8b1b12be31 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
@@ -36,6 +36,7 @@ import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import static java.util.Locale.ENGLISH;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
@@ -143,6 +144,10 @@ public class UserDao implements Dao {
mapper(dbSession).clearHomepages("ORGANIZATION", organization.getUuid(), system2.now());
}
+ public void cleanHomepage(DbSession dbSession, ProjectDto project) {
+ mapper(dbSession).clearHomepages("PROJECT", project.getUuid(), system2.now());
+ }
+
public void cleanHomepage(DbSession dbSession, ComponentDto project) {
mapper(dbSession).clearHomepages("PROJECT", project.uuid(), system2.now());
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java
index 98d3d5ef671..bbed39b4fa0 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java
@@ -26,6 +26,7 @@ import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkState;
@@ -49,8 +50,8 @@ public class WebhookDao implements Dao {
return mapper(dbSession).selectForOrganizationUuidOrderedByName(organizationUuid);
}
- public List<WebhookDto> selectByProject(DbSession dbSession, ComponentDto componentDto) {
- return mapper(dbSession).selectForProjectUuidOrderedByName(componentDto.uuid());
+ public List<WebhookDto> selectByProject(DbSession dbSession, ProjectDto projectDto) {
+ return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid());
}
public void insert(DbSession dbSession, WebhookDto dto) {
@@ -73,8 +74,8 @@ public class WebhookDao implements Dao {
mapper(dbSession).deleteForOrganizationUuid(organization.getUuid());
}
- public void deleteByProject(DbSession dbSession, ComponentDto componentDto) {
- mapper(dbSession).deleteForProjectUuid(componentDto.uuid());
+ public void deleteByProject(DbSession dbSession, ProjectDto projectDto) {
+ mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
}
private static WebhookMapper mapper(DbSession dbSession) {