aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/entity/EntityDaoIT.java148
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java110
-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.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDao.java65
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDto.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityMapper.java41
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java30
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java12
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/entity/EntityMapper.xml79
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml77
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentHit.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java9
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java26
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java2
24 files changed, 372 insertions, 269 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/entity/EntityDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/entity/EntityDaoIT.java
new file mode 100644
index 00000000000..7c21aa67ce5
--- /dev/null
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/entity/EntityDaoIT.java
@@ -0,0 +1,148 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.entity;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.ibatis.session.ResultHandler;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.portfolio.PortfolioDto;
+
+import static java.util.Collections.emptyList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EntityDaoIT {
+ private final System2 system2 = new AlwaysIncreasingSystem2(1000L);
+
+ @Rule
+ public DbTester db = DbTester.create(system2);
+
+ private final EntityDao entityDao = new EntityDao();
+
+ @Test
+ public void selectEntitiesByKeys_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ assertThat(entityDao.selectByKeys(db.getSession(), List.of(application.projectKey(), project.projectKey(), portfolio.getKey(), "unknown")))
+ .extracting(EntityDto::getUuid)
+ .containsOnly(application.projectUuid(), project.projectUuid(), portfolio.getUuid());
+ }
+
+ @Test
+ public void selectEntitiesByKeys_whenEmptyInput_shouldReturnEmptyList() {
+ assertThat(entityDao.selectByKeys(db.getSession(), emptyList())).isEmpty();
+ }
+
+ @Test
+ public void selectEntitiesByUuids_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ assertThat(entityDao.selectByUuids(db.getSession(), List.of(application.projectUuid(), project.projectUuid(), portfolio.getUuid(), "unknown")))
+ .extracting(EntityDto::getKey)
+ .containsOnly(application.projectKey(), project.projectKey(), portfolio.getKey());
+ }
+
+ @Test
+ public void selectEntitiesByUuids_whenEmptyInput_shouldReturnEmptyList() {
+ assertThat(entityDao.selectByUuids(db.getSession(), emptyList())).isEmpty();
+ }
+
+ @Test
+ public void selectEntityByUuid_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ assertThat(entityDao.selectByUuid(db.getSession(), application.projectUuid()).get().getKey()).isEqualTo(application.projectKey());
+ assertThat(entityDao.selectByUuid(db.getSession(), project.projectUuid()).get().getKey()).isEqualTo(project.projectKey());
+ assertThat(entityDao.selectByUuid(db.getSession(), portfolio.getUuid()).get().getKey()).isEqualTo(portfolio.getKey());
+ }
+
+ @Test
+ public void selectEntityByUuid_whenNoMatch_shouldReturnEmpty() {
+ assertThat(entityDao.selectByUuid(db.getSession(), "unknown")).isEmpty();
+ }
+
+ @Test
+ public void selectEntityByKey_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ assertThat(entityDao.selectByKey(db.getSession(), application.projectKey()).get().getUuid()).isEqualTo(application.projectUuid());
+ assertThat(entityDao.selectByKey(db.getSession(), project.projectKey()).get().getUuid()).isEqualTo(project.projectUuid());
+ assertThat(entityDao.selectByKey(db.getSession(), portfolio.getKey()).get().getUuid()).isEqualTo(portfolio.getUuid());
+ }
+
+ @Test
+ public void selectEntityByKey_whenNoMatch_shouldReturnEmpty() {
+ assertThat(entityDao.selectByKey(db.getSession(), "unknown")).isEmpty();
+ }
+
+ @Test
+ public void scrollEntitiesForIndexing_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ entityDao.scrollForIndexing(db.getSession(), null, handler);
+
+ assertThat(result).extracting(EntityDto::getUuid)
+ .containsOnly(project.projectUuid(), application.projectUuid(), portfolio.getUuid());
+ }
+
+ @Test
+ public void scrollEntitiesForIndexing_whenEntityUuidSpecified_shouldReturnSpecificEntity() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ entityDao.scrollForIndexing(db.getSession(), project.projectUuid(), handler);
+
+ assertThat(result).extracting(EntityDto::getUuid)
+ .containsOnly(project.projectUuid());
+ }
+
+ @Test
+ public void scrollEntitiesForIndexing_whenNonExistingUuidSpecified_shouldReturnEmpty() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ entityDao.scrollForIndexing(db.getSession(), "unknown", handler);
+
+ assertThat(result).isEmpty();
+ }
+}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
index 219c9f4c13e..3941bb5b4f7 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
@@ -24,7 +24,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -32,7 +31,6 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
-import org.apache.ibatis.session.ResultHandler;
import org.assertj.core.api.Assertions;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
@@ -46,13 +44,10 @@ import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
-import org.sonar.db.entity.EntityDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.portfolio.PortfolioDto;
import org.sonar.db.qualityprofile.QProfileDto;
-import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThat;
@@ -344,111 +339,6 @@ public class ProjectDaoIT {
assertThat(projectUuids).containsExactlyInAnyOrder(project.projectUuid(), project2.projectUuid());
}
- @Test
- public void selectEntitiesByKeys_shouldReturnAllEntities() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- assertThat(projectDao.selectEntitiesByKeys(db.getSession(), List.of(application.projectKey(), project.projectKey(), portfolio.getKey(), "unknown")))
- .extracting(EntityDto::getUuid)
- .containsOnly(application.projectUuid(), project.projectUuid(), portfolio.getUuid());
- }
-
- @Test
- public void selectEntitiesByKeys_whenEmptyInput_shouldReturnEmptyList() {
- assertThat(projectDao.selectEntitiesByKeys(db.getSession(), emptyList())).isEmpty();
- }
-
- @Test
- public void selectEntitiesByUuids_shouldReturnAllEntities() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- assertThat(projectDao.selectEntitiesByUuids(db.getSession(), List.of(application.projectUuid(), project.projectUuid(), portfolio.getUuid(), "unknown")))
- .extracting(EntityDto::getKey)
- .containsOnly(application.projectKey(), project.projectKey(), portfolio.getKey());
- }
-
- @Test
- public void selectEntitiesByUuids_whenEmptyInput_shouldReturnEmptyList() {
- assertThat(projectDao.selectEntitiesByUuids(db.getSession(), emptyList())).isEmpty();
- }
-
- @Test
- public void selectEntityByUuid_shouldReturnAllEntities() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- assertThat(projectDao.selectEntityByUuid(db.getSession(), application.projectUuid()).get().getKey()).isEqualTo(application.projectKey());
- assertThat(projectDao.selectEntityByUuid(db.getSession(), project.projectUuid()).get().getKey()).isEqualTo(project.projectKey());
- assertThat(projectDao.selectEntityByUuid(db.getSession(), portfolio.getUuid()).get().getKey()).isEqualTo(portfolio.getKey());
- }
-
- @Test
- public void selectEntityByUuid_whenNoMatch_shouldReturnEmpty() {
- assertThat(projectDao.selectEntityByUuid(db.getSession(), "unknown")).isEmpty();
- }
-
- @Test
- public void selectEntityByKey_shouldReturnAllEntities() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- assertThat(projectDao.selectEntityByKey(db.getSession(), application.projectKey()).get().getUuid()).isEqualTo(application.projectUuid());
- assertThat(projectDao.selectEntityByKey(db.getSession(), project.projectKey()).get().getUuid()).isEqualTo(project.projectUuid());
- assertThat(projectDao.selectEntityByKey(db.getSession(), portfolio.getKey()).get().getUuid()).isEqualTo(portfolio.getUuid());
- }
-
- @Test
- public void selectEntityByKey_whenNoMatch_shouldReturnEmpty() {
- assertThat(projectDao.selectEntityByKey(db.getSession(), "unknown")).isEmpty();
- }
-
- @Test
- public void scrollEntitiesForIndexing_shouldReturnAllEntities() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- List<EntityDto> result = new LinkedList<>();
- ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
- projectDao.scrollEntitiesForIndexing(db.getSession(), null, handler);
-
- assertThat(result).extracting(EntityDto::getUuid)
- .containsOnly(project.projectUuid(), application.projectUuid(), portfolio.getUuid());
- }
-
- @Test
- public void scrollEntitiesForIndexing_whenEntityUuidSpecified_shouldReturnSpecificEntity() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- List<EntityDto> result = new LinkedList<>();
- ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
- projectDao.scrollEntitiesForIndexing(db.getSession(), project.projectUuid(), handler);
-
- assertThat(result).extracting(EntityDto::getUuid)
- .containsOnly(project.projectUuid());
- }
-
- @Test
- public void scrollEntitiesForIndexing_whenNonExistingUuidSpecified_shouldReturnEmpty() {
- ProjectData application = db.components().insertPrivateApplication();
- ProjectData project = db.components().insertPrivateProject();
- PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
-
- List<EntityDto> result = new LinkedList<>();
- ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
- projectDao.scrollEntitiesForIndexing(db.getSession(), "unknown", handler);
-
- assertThat(result).isEmpty();
- }
-
private void insertDefaultQualityProfile(String language) {
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().setAsDefault(profile);
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 a58e3b8d522..44a996e4b41 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
@@ -39,6 +39,7 @@ import org.sonar.db.component.ComponentKeyUpdaterDao;
import org.sonar.db.component.ProjectLinkDao;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.duplication.DuplicationDao;
+import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
import org.sonar.db.event.EventComponentChangeDao;
import org.sonar.db.event.EventDao;
@@ -118,6 +119,7 @@ public class DaoModule extends Module {
ComponentKeyUpdaterDao.class,
DefaultQProfileDao.class,
DuplicationDao.class,
+ EntityDao.class,
EsQueueDao.class,
EventDao.class,
EventComponentChangeDao.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 4179b7dc7e1..80add385af8 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
@@ -39,6 +39,7 @@ import org.sonar.db.component.ComponentKeyUpdaterDao;
import org.sonar.db.component.ProjectLinkDao;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.duplication.DuplicationDao;
+import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
import org.sonar.db.event.EventComponentChangeDao;
import org.sonar.db.event.EventDao;
@@ -178,6 +179,7 @@ public class DbClient {
private final ScannerAnalysisCacheDao scannerAnalysisCacheDao;
private final ScimUserDao scimUserDao;
private final ScimGroupDao scimGroupDao;
+ private final EntityDao entityDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
@@ -263,6 +265,7 @@ public class DbClient {
scannerAnalysisCacheDao = getDao(map, ScannerAnalysisCacheDao.class);
scimUserDao = getDao(map, ScimUserDao.class);
scimGroupDao = getDao(map, ScimGroupDao.class);
+ entityDao = getDao(map, EntityDao.class);
}
public DbSession openSession(boolean batch) {
@@ -582,5 +585,9 @@ public class DbClient {
public ScimGroupDao scimGroupDao() {
return scimGroupDao;
}
+
+ public EntityDao entityDao() {
+ return entityDao;
+ }
}
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 a36feeb394e..f2aeefdcc27 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
@@ -65,6 +65,7 @@ import org.sonar.db.component.ViewsSnapshotDto;
import org.sonar.db.duplication.DuplicationMapper;
import org.sonar.db.duplication.DuplicationUnitDto;
import org.sonar.db.entity.EntityDto;
+import org.sonar.db.entity.EntityMapper;
import org.sonar.db.es.EsQueueMapper;
import org.sonar.db.event.EventComponentChangeMapper;
import org.sonar.db.event.EventDto;
@@ -271,6 +272,7 @@ public class MyBatis {
LiveMeasureMapper.class,
DefaultQProfileMapper.class,
DuplicationMapper.class,
+ EntityMapper.class,
EsQueueMapper.class,
EventMapper.class,
EventComponentChangeMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDao.java
new file mode 100644
index 00000000000..f0268ec9de5
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDao.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.entity;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.ibatis.session.ResultHandler;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+import static java.util.Collections.emptyList;
+import static org.sonar.db.DatabaseUtils.executeLargeInputs;
+
+public class EntityDao implements Dao {
+ public Optional<EntityDto> selectByUuid(DbSession dbSession, String uuid) {
+ return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid));
+ }
+
+ public List<EntityDto> selectByUuids(DbSession dbSession, Collection<String> uuids) {
+ if (uuids.isEmpty()) {
+ return emptyList();
+ }
+
+ return executeLargeInputs(uuids, partition -> mapper(dbSession).selectByUuids(partition));
+ }
+
+ public Optional<EntityDto> selectByKey(DbSession dbSession, String key) {
+ return Optional.ofNullable(mapper(dbSession).selectByKey(key));
+ }
+
+ public List<EntityDto> selectByKeys(DbSession dbSession, Collection<String> keys) {
+ if (keys.isEmpty()) {
+ return emptyList();
+ }
+ return executeLargeInputs(keys, partition -> mapper(dbSession).selectByKeys(partition));
+ }
+
+ public void scrollForIndexing(DbSession session, @Nullable String entityUuid, ResultHandler<EntityDto> handler) {
+ mapper(session).scrollForIndexing(entityUuid, handler);
+ }
+
+ private static EntityMapper mapper(DbSession session) {
+ return session.getMapper(EntityMapper.class);
+ }
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDto.java
index 03e0b564dc3..aa031c0787a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityDto.java
@@ -20,6 +20,7 @@
package org.sonar.db.entity;
import java.util.Objects;
+import javax.annotation.CheckForNull;
/**
* Represents a project, an application, a portfolio or a sub-portfolio.
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityMapper.java
new file mode 100644
index 00000000000..1ca0041731a
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/EntityMapper.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.entity;
+
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
+
+public interface EntityMapper {
+ @CheckForNull
+ EntityDto selectByUuid(String uuid);
+
+ List<EntityDto> selectByUuids(@Param("uuids") Collection<String> uuids);
+
+ @CheckForNull
+ EntityDto selectByKey(String key);
+
+ List<EntityDto> selectByKeys(@Param("keys") Collection<String> keys);
+
+ void scrollForIndexing(@Param("entityUuid") @Nullable String entityUuid, ResultHandler<EntityDto> handler);
+}
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
index 1d354a8487a..44ef0ff0e8b 100644
--- 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
@@ -19,18 +19,15 @@
*/
package org.sonar.db.project;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
-import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.ComponentNewValue;
-import org.sonar.db.entity.EntityDto;
import static java.util.Collections.emptyList;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
@@ -146,31 +143,4 @@ public class ProjectDao implements Dao {
public long getNclocSum(DbSession dbSession, @Nullable String projectUuidToExclude) {
return Optional.ofNullable(mapper(dbSession).getNclocSum(projectUuidToExclude)).orElse(0L);
}
-
- public Optional<EntityDto> selectEntityByUuid(DbSession dbSession, String uuid) {
- return Optional.ofNullable(mapper(dbSession).selectEntityByUuid(uuid));
- }
-
- public List<EntityDto> selectEntitiesByUuids(DbSession dbSession, Collection<String> uuids) {
- if (uuids.isEmpty()) {
- return emptyList();
- }
-
- return executeLargeInputs(uuids, partition -> mapper(dbSession).selectEntitiesByUuids(partition));
- }
-
- public Optional<EntityDto> selectEntityByKey(DbSession dbSession, String key) {
- return Optional.ofNullable(mapper(dbSession).selectEntityByKey(key));
- }
-
- public List<EntityDto> selectEntitiesByKeys(DbSession dbSession, Collection<String> keys) {
- if (keys.isEmpty()) {
- return emptyList();
- }
- return executeLargeInputs(keys, partition -> mapper(dbSession).selectEntitiesByKeys(partition));
- }
-
- public void scrollEntitiesForIndexing(DbSession session, @Nullable String entityUuid, ResultHandler<EntityDto> handler) {
- mapper(session).scrollEntitiesForIndexing(entityUuid, handler);
- }
}
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
index 6ffcf920733..c4ddb661141 100644
--- 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
@@ -73,16 +73,4 @@ public interface ProjectMapper {
@CheckForNull
Long getNclocSum(@Nullable @Param("projectUuidToExclude") String projectUuidToExclude);
-
- @CheckForNull
- EntityDto selectEntityByUuid(String uuid);
-
- List<EntityDto> selectEntitiesByUuids(@Param("uuids") Collection<String> uuids);
-
- @CheckForNull
- EntityDto selectEntityByKey(String key);
-
- List<EntityDto> selectEntitiesByKeys(@Param("keys") Collection<String> keys);
-
- void scrollEntitiesForIndexing(@Param("entityUuid") @Nullable String entityUuid, ResultHandler<EntityDto> handler);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/entity/EntityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/entity/EntityMapper.xml
new file mode 100644
index 00000000000..794d65709ff
--- /dev/null
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/entity/EntityMapper.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+<mapper namespace="org.sonar.db.entity.EntityMapper">
+ <sql id="entityProjectColumns">
+ p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate, p.qualifier as qualifier, null as authUuid
+ </sql>
+
+ <sql id="entityPortfolioColumns">
+ p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate,
+ case when p.parent_uuid is null then 'VW' else 'SVW' end as qualifier,
+ case when p.root_uuid != p.uuid then p.root_uuid else null end as authUuid
+ </sql>
+
+ <select id="selectByUuid" parameterType="string" resultType="Entity">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ where p.uuid = #{uuid,jdbcType=VARCHAR})
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ where p.uuid = #{uuid,jdbcType=VARCHAR})
+ </select>
+
+ <select id="selectByUuids" resultType="Entity">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ where p.uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
+ #{uuid,jdbcType=VARCHAR}
+ </foreach>)
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ where p.uuid in
+ <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
+ #{uuid,jdbcType=VARCHAR}
+ </foreach>)
+ </select>
+
+ <select id="selectByKey" parameterType="string" resultType="Entity">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ where p.kee = #{key,jdbcType=VARCHAR})
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ where p.kee = #{key,jdbcType=VARCHAR})
+ </select>
+
+ <select id="selectByKeys" parameterType="string" resultType="Entity">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ where p.kee in
+ <foreach collection="keys" open="(" close=")" item="kee" separator=",">
+ #{kee,jdbcType=VARCHAR}
+ </foreach>)
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ where p.kee in
+ <foreach collection="keys" open="(" close=")" item="kee" separator=",">
+ #{kee,jdbcType=VARCHAR}
+ </foreach>)
+ </select>
+
+ <select id="scrollForIndexing" parameterType="map" resultType="Entity" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ <if test="entityUuid != null">
+ where p.uuid = #{entityUuid,jdbcType=VARCHAR}
+ </if>)
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ <if test="entityUuid != null">
+ where p.uuid = #{entityUuid,jdbcType=VARCHAR}
+ </if>)
+ </select>
+</mapper> \ No newline at end of file
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
index e623ae82be7..36bb101f9ae 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
@@ -201,81 +201,4 @@
and uuid &lt;&gt; #{projectUuidToExclude,jdbcType=VARCHAR}
</if>
</select>
-
- <sql id="entityProjectColumns">
- p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate, p.qualifier as qualifier, null as authUuid
- </sql>
-
- <sql id="entityPortfolioColumns">
- p.uuid as uuid, p.kee as kee, p.name as name, p.private as isPrivate,
- case when p.parent_uuid is null then 'VW' else 'SVW' end as qualifier,
- case when p.root_uuid != p.uuid then p.root_uuid else null end as authUuid
- </sql>
-
- <select id="selectEntityByUuid" parameterType="string" resultType="Entity">
- (select <include refid="entityProjectColumns"/>
- from projects p
- where p.uuid = #{uuid,jdbcType=VARCHAR})
- UNION
- (select <include refid="entityPortfolioColumns"/>
- from portfolios p
- where p.uuid = #{uuid,jdbcType=VARCHAR})
- </select>
-
- <select id="selectEntitiesByUuids" resultType="Entity">
- (select <include refid="entityProjectColumns"/>
- from projects p
- where p.uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
- #{uuid,jdbcType=VARCHAR}
- </foreach>)
- UNION
- (select <include refid="entityPortfolioColumns"/>
- from portfolios p
- where p.uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
- #{uuid,jdbcType=VARCHAR}
- </foreach>)
- </select>
-
- <select id="selectEntityByKey" parameterType="string" resultType="Entity">
- (select <include refid="entityProjectColumns"/>
- from projects p
- where p.kee = #{key,jdbcType=VARCHAR})
- UNION
- (select <include refid="entityPortfolioColumns"/>
- from portfolios p
- where p.kee = #{key,jdbcType=VARCHAR})
- </select>
-
- <select id="selectEntitiesByKeys" parameterType="string" resultType="Entity">
- (select <include refid="entityProjectColumns"/>
- from projects p
- where p.kee in
- <foreach collection="keys" open="(" close=")" item="kee" separator=",">
- #{kee,jdbcType=VARCHAR}
- </foreach>)
- UNION
- (select <include refid="entityPortfolioColumns"/>
- from portfolios p
- where p.kee in
- <foreach collection="keys" open="(" close=")" item="kee" separator=",">
- #{kee,jdbcType=VARCHAR}
- </foreach>)
- </select>
-
- <select id="scrollEntitiesForIndexing" parameterType="map" resultType="Entity" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- (select <include refid="entityProjectColumns"/>
- from projects p
- <if test="entityUuid != null">
- where p.uuid = #{entityUuid,jdbcType=VARCHAR}
- </if>)
- UNION
- (select <include refid="entityPortfolioColumns"/>
- from portfolios p
- <if test="entityUuid != null">
- where p.uuid = #{entityUuid,jdbcType=VARCHAR}
- </if>)
- </select>
-
</mapper>
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentHit.java b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentHit.java
index d27bfcf09fd..c9e3609592e 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentHit.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentHit.java
@@ -36,7 +36,7 @@ public class ComponentHit {
public ComponentHit(String uuid) {
this.uuid = uuid;
- highlightedText = Optional.empty();
+ this.highlightedText = Optional.empty();
}
public ComponentHit(SearchHit hit) {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
index 5051ed8284c..5b47fb11c89 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
@@ -27,8 +27,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -37,7 +35,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.es.EsQueueDto;
-import org.sonar.db.portfolio.PortfolioDto;
import org.sonar.server.es.BaseDoc;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.BulkIndexer.Size;
@@ -125,7 +122,7 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
Set<String> remaining = new HashSet<>(entityUuids);
for (String entityUuid : entityUuids) {
- dbClient.projectDao().scrollEntitiesForIndexing(dbSession, entityUuid, context -> {
+ dbClient.entityDao().scrollForIndexing(dbSession, entityUuid, context -> {
EntityDto dto = context.getResultObject();
remaining.remove(dto.getUuid());
bulkIndexer.add(toDocument(dto).toIndexRequest());
@@ -148,7 +145,7 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
bulk.start();
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<EntityDto> entityDto = dbClient.projectDao().selectEntityByUuid(dbSession, entityUuid);
+ Optional<EntityDto> entityDto = dbClient.entityDao().selectByUuid(dbSession, entityUuid);
if (entityDto.isEmpty()) {
return;
@@ -170,7 +167,7 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
BulkIndexer bulk = new BulkIndexer(esClient, TYPE_COMPONENT, bulkSize);
bulk.start();
try (DbSession dbSession = dbClient.openSession(false)) {
- dbClient.projectDao().scrollEntitiesForIndexing(dbSession, null, context -> {
+ dbClient.entityDao().scrollForIndexing(dbSession, null, context -> {
EntityDto dto = context.getResultObject();
bulk.add(toDocument(dto).toIndexRequest());
});
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
index 5e48e0c3733..41c8abcaa1e 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
@@ -22,15 +22,11 @@ package org.sonar.server.component.index;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
-import java.util.stream.Collectors;
import org.assertj.core.api.ListAssert;
import org.junit.Rule;
-import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.EsTester;
@@ -65,8 +61,7 @@ public abstract class ComponentIndexTest {
protected void assertResultOrder(String query, String... resultsInOrder) {
indexProject("key-1", "Quality Product");
List<ProjectDto> projects = Arrays.stream(resultsInOrder)
- .map(r -> componentDbTester.insertPublicProject(c -> c.setName(r).setKey(r)).getProjectDto())
- .peek(p -> p.setUuid(p.getUuid() + "_" + p.getName().replaceAll("[^a-zA-Z0-9]", "")))
+ .map(r -> componentDbTester.insertPublicProject(c -> c.setName(r)).getProjectDto())
.toList();
// index them, but not in the expected order
@@ -103,7 +98,7 @@ public abstract class ComponentIndexTest {
assertSearch(query).containsExactly(uuids(expectedComponents));
}
- protected void assertNoSearchResults(String query, String ... qualifiers) {
+ protected void assertNoSearchResults(String query, String... qualifiers) {
assertSearchResults(query, List.of(qualifiers));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index 325bdfb9c16..4462634a79f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -34,7 +34,7 @@ import org.sonar.api.utils.Paging;
import org.sonar.core.i18n.I18n;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.server.component.index.ComponentIndex;
import org.sonar.server.component.index.ComponentQuery;
import org.sonar.server.es.SearchIdResult;
@@ -43,7 +43,6 @@ import org.sonarqube.ws.Components;
import org.sonarqube.ws.Components.SearchWsResponse;
import static java.util.Objects.requireNonNull;
-import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;
import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.PROJECT;
@@ -117,7 +116,7 @@ public class SearchAction implements ComponentsWsAction {
ComponentQuery esQuery = buildEsQuery(request);
SearchIdResult<String> results = componentIndex.search(esQuery, new SearchOptions().setPage(request.getPage(), request.getPageSize()));
- List<ComponentDto> components = dbClient.componentDao().selectByUuids(dbSession, results.getUuids());
+ List<EntityDto> components = dbClient.entityDao().selectByUuids(dbSession, results.getUuids());
Map<String, String> projectKeysByUuids = searchProjectsKeysByUuids(dbSession, components);
return buildResponse(components, projectKeysByUuids,
@@ -125,12 +124,12 @@ public class SearchAction implements ComponentsWsAction {
}
}
- private Map<String, String> searchProjectsKeysByUuids(DbSession dbSession, List<ComponentDto> components) {
- Set<String> projectUuidsToSearch = components.stream()
- .map(ComponentDto::branchUuid)
+ private Map<String, String> searchProjectsKeysByUuids(DbSession dbSession, List<EntityDto> entities) {
+ Set<String> projectUuidsToSearch = entities.stream()
+ .map(EntityDto::getAuthUuid)
.collect(toHashSet());
- List<ComponentDto> projects = dbClient.componentDao().selectByUuids(dbSession, projectUuidsToSearch);
- return projects.stream().collect(toMap(ComponentDto::uuid, ComponentDto::getKey));
+ List<EntityDto> projects = dbClient.entityDao().selectByUuids(dbSession, projectUuidsToSearch);
+ return projects.stream().collect(toMap(EntityDto::getUuid, EntityDto::getKey));
}
private static ComponentQuery buildEsQuery(SearchRequest request) {
@@ -140,7 +139,7 @@ public class SearchAction implements ComponentsWsAction {
.build();
}
- private static SearchWsResponse buildResponse(List<ComponentDto> components, Map<String, String> projectKeysByUuids, Paging paging) {
+ private static SearchWsResponse buildResponse(List<EntityDto> components, Map<String, String> projectKeysByUuids, Paging paging) {
SearchWsResponse.Builder responseBuilder = SearchWsResponse.newBuilder();
responseBuilder.getPagingBuilder()
.setPageIndex(paging.pageIndex())
@@ -149,19 +148,18 @@ public class SearchAction implements ComponentsWsAction {
.build();
components.stream()
- .map(dto -> dtoToComponent(dto, projectKeysByUuids.get(dto.branchUuid())))
+ .map(dto -> dtoToComponent(dto, projectKeysByUuids.get(dto.getAuthUuid())))
.forEach(responseBuilder::addComponents);
return responseBuilder.build();
}
- private static Components.Component dtoToComponent(ComponentDto dto, String projectKey) {
+ private static Components.Component dtoToComponent(EntityDto dto, String projectKey) {
Components.Component.Builder builder = Components.Component.newBuilder()
.setKey(dto.getKey())
.setProject(projectKey)
- .setName(dto.name())
- .setQualifier(dto.qualifier());
- ofNullable(dto.language()).ifPresent(builder::setLanguage);
+ .setName(dto.getName())
+ .setQualifier(dto.getQualifier());
return builder.build();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index d59f089cb3b..dc9ed01a120 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -169,7 +169,7 @@ public class SuggestionsAction implements ComponentsWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
Set<EntityDto> entities = new HashSet<>(favorites);
if (!recentlyBrowsedKeys.isEmpty()) {
- entities.addAll(dbClient.projectDao().selectEntitiesByKeys(dbSession, recentlyBrowsedKeys));
+ entities.addAll(dbClient.entityDao().selectByKeys(dbSession, recentlyBrowsedKeys));
}
List<EntityDto> authorizedEntities = userSession.keepAuthorizedEntities(USER, entities);
ListMultimap<String, EntityDto> entityPerQualifier = authorizedEntities.stream()
@@ -226,7 +226,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.flatMap(Collection::stream)
.map(ComponentHit::getUuid)
.collect(toSet());
- List<EntityDto> entities = dbClient.projectDao().selectEntitiesByUuids(dbSession, entityUuids);
+ List<EntityDto> entities = dbClient.entityDao().selectByUuids(dbSession, entityUuids);
Set<String> favoriteUuids = favorites.stream().map(EntityDto::getUuid).collect(MoreCollectors.toSet(favorites.size()));
SuggestionsWsResponse.Builder searchWsResponse = buildResponse(recentlyBrowsedKeys, favoriteUuids, componentsPerQualifiers, entities, skip + limit);
getWarning(query).ifPresent(searchWsResponse::setWarning);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
index 5e35111dbf3..f4ff21dc83f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/FavoriteFinder.java
@@ -57,7 +57,7 @@ public class FavoriteFinder {
.build();
Set<String> entitiesUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet());
- List<EntityDto> entities = dbClient.projectDao().selectEntitiesByUuids(dbSession, entitiesUuids);
+ List<EntityDto> entities = dbClient.entityDao().selectByUuids(dbSession, entitiesUuids);
return entities.stream()
.sorted(Comparator.comparing(EntityDto::getName))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java
index a5618d94905..693b0a3235a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/AddAction.java
@@ -27,9 +27,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.favorite.FavoriteUpdater;
import org.sonar.server.user.UserSession;
@@ -92,7 +90,7 @@ public class AddAction implements FavoritesWsAction {
private Consumer<Request> addFavorite() {
return request -> {
try (DbSession dbSession = dbClient.openSession(false)) {
- EntityDto entity = dbClient.projectDao().selectEntityByKey(dbSession, request.mandatoryParam(PARAM_COMPONENT))
+ EntityDto entity = dbClient.entityDao().selectByKey(dbSession, request.mandatoryParam(PARAM_COMPONENT))
.orElseThrow(() -> new NotFoundException(format("Entity with key '%s' not found", request.mandatoryParam(PARAM_COMPONENT))));
checkArgument(SUPPORTED_QUALIFIERS.contains(entity.getQualifier()), "Only components with qualifiers %s are supported", SUPPORTED_QUALIFIERS_AS_STRING);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java
index 85cc8d60a11..2459a631942 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/favorite/ws/RemoveAction.java
@@ -27,7 +27,6 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.entity.EntityDto;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.favorite.FavoriteUpdater;
import org.sonar.server.user.UserSession;
@@ -75,7 +74,7 @@ public class RemoveAction implements FavoritesWsAction {
return request -> {
try (DbSession dbSession = dbClient.openSession(false)) {
String key = request.mandatoryParam(PARAM_COMPONENT);
- EntityDto entity = dbClient.projectDao().selectEntityByKey(dbSession, key)
+ EntityDto entity = dbClient.entityDao().selectByKey(dbSession, key)
.orElseThrow(() -> new NotFoundException(format("Component with key '%s' not found", key)));
userSession.checkLoggedIn();
favoriteUpdater.remove(dbSession, entity,
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java
index cc68222591b..8c59f316226 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ListDefinitionsAction.java
@@ -115,7 +115,7 @@ public class ListDefinitionsAction implements SettingsWsAction {
if (entityKey == null) {
return Optional.empty();
}
- EntityDto entity = dbClient.projectDao().selectEntityByKey(dbSession, entityKey)
+ EntityDto entity = dbClient.entityDao().selectByKey(dbSession, entityKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", entityKey)));
userSession.checkEntityPermission(USER, entity);
return Optional.of(entity);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java
index e8093749264..8fae7a82c42 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java
@@ -134,7 +134,7 @@ public class ResetAction implements SettingsWsAction {
return Optional.empty();
}
- return Optional.of(dbClient.projectDao().selectEntityByKey(dbSession, componentKey)
+ return Optional.of(dbClient.entityDao().selectByKey(dbSession, componentKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey))));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
index c7d50a66de0..c6b285a1a47 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java
@@ -319,7 +319,7 @@ public class SetAction implements SettingsWsAction {
if (componentKey == null) {
return Optional.empty();
}
- return Optional.of(dbClient.projectDao().selectEntityByKey(dbSession, componentKey)
+ return Optional.of(dbClient.entityDao().selectByKey(dbSession, componentKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey))));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
index 6c996322b28..f0076b66a09 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
@@ -144,7 +144,7 @@ public class ValuesAction implements SettingsWsAction {
return Optional.empty();
}
- EntityDto component = dbClient.projectDao().selectEntityByKey(dbSession, componentKey)
+ EntityDto component = dbClient.entityDao().selectByKey(dbSession, componentKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey)));
if (!userSession.hasEntityPermission(USER, component) &&