aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorantoine.vinot <antoine.vinot@sonarsource.com>2024-10-11 15:54:52 +0200
committersonartech <sonartech@sonarsource.com>2024-10-21 20:03:59 +0000
commit596b193a1a2d64c50c728ff8051721f61cd79d0c (patch)
tree530b28376d5313c83d818c41dfae2273edbc4a54 /server/sonar-db-dao/src
parent65d606200841e8d63af5e2ad5039cefdd69bc72a (diff)
downloadsonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.tar.gz
sonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.zip
SONAR-23098 Create Project Dependencies DB model
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/dependency/ProjectDependenciesDaoIT.java183
-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/dependency/ProjectDependenciesDao.java52
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesMapper.java36
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesQuery.java57
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependencyDto.java32
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/dependency/ProjectDependenciesMapper.xml72
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl10
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java7
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java1
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java64
13 files changed, 526 insertions, 1 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/dependency/ProjectDependenciesDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/dependency/ProjectDependenciesDaoIT.java
new file mode 100644
index 00000000000..5d0f7c8ca65
--- /dev/null
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/dependency/ProjectDependenciesDaoIT.java
@@ -0,0 +1,183 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.Pagination;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ProjectDependenciesDaoIT {
+
+ private static final String PROJECT_BRANCH_UUID = "branchUuid";
+
+ @RegisterExtension
+ private final DbTester db = DbTester.create(System2.INSTANCE);
+
+ private final ProjectDependenciesDao projectDependenciesDao = db.getDbClient().projectDependenciesDao();
+
+ @Test
+ void insert_shouldPersistProjectDependencies() {
+ var projectDependencyDto = new ProjectDependencyDto("projectUuid", "version", "includePaths", "packageManager", 1L, 2L);
+
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).hasSize(1);
+ Map<String, Object> stringObjectMap = select.get(0);
+ assertThat(stringObjectMap).containsExactlyInAnyOrderEntriesOf(
+ Map.of(
+ "uuid", projectDependencyDto.uuid(),
+ "version", projectDependencyDto.version(),
+ "include_paths", projectDependencyDto.includePaths(),
+ "package_manager", projectDependencyDto.packageManager(),
+ "created_at", projectDependencyDto.createdAt(),
+ "updated_at", projectDependencyDto.updatedAt())
+ );
+ }
+
+ @Test
+ void deleteByUuid_shoudDeleteProjectDependencies() {
+ var projectDependencyDto = new ProjectDependencyDto("projectUuid", "version", "includePaths", "packageManager", 1L, 2L);
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ projectDependenciesDao.deleteByUuid(db.getSession(), projectDependencyDto.uuid());
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).isEmpty();
+ }
+
+ @Test
+ void selectByQuery_shouldReturnProjectDependencies_whenQueryByBranchUuid() {
+ ProjectData projectData = db.components().insertPublicProject();
+ var projectDependencyDto = new ProjectDependencyDto(projectData.getMainBranchComponent().uuid(), "version", "includePaths", "packageManager", 1L, 2L);
+ projectDependenciesDao.insert(db.getSession(), projectDependencyDto);
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(projectData.mainBranchUuid(), null);
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto);
+ }
+
+ @Test
+ void selectByQuery_shouldReturnPaginatedProjectDependencies() {
+ ProjectDependencyDto projectDependencyDto1 = insertProjectDependency("1");
+ ProjectDependencyDto projectDependencyDto2 = insertProjectDependency("2");
+ ProjectDependencyDto projectDependencyDto3 = insertProjectDependency("3");
+ ProjectDependencyDto projectDependencyDto4 = insertProjectDependency("4");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, null);
+ List<ProjectDependencyDto> page1Results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.forPage(1).andSize(2));
+ List<ProjectDependencyDto> page2Results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.forPage(2).andSize(2));
+
+ assertThat(page1Results).hasSize(2);
+ assertThat(page1Results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto1);
+ assertThat(page1Results.get(1)).usingRecursiveComparison().isEqualTo(projectDependencyDto2);
+ assertThat(page2Results).hasSize(2);
+ assertThat(page2Results.get(0)).usingRecursiveComparison().isEqualTo(projectDependencyDto3);
+ assertThat(page2Results.get(1)).usingRecursiveComparison().isEqualTo(projectDependencyDto4);
+ }
+
+ @Test
+ void selectByQuery_shouldPartiallyMatchLongName_whenQueriedByText() {
+ ProjectDependencyDto projectDepSearched = insertProjectDependency("sEArched");
+ insertProjectDependency("notWanted");
+ ProjectDependencyDto projectDepSearchAsWell = insertProjectDependency("sEArchedAsWell");
+ insertProjectDependency("notwantedeither");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "long_nameSearCHed");
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(2);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDepSearched);
+ assertThat(results.get(1)).usingRecursiveComparison().isEqualTo(projectDepSearchAsWell);
+ }
+
+ @Test
+ void selectByQuery_shouldExactlyMatchKee_whenQueriedByText() {
+ ProjectDependencyDto projectDepSearched = insertProjectDependency("1", dto -> dto.setKey("keySearched"));
+ insertProjectDependency("2", dto -> dto.setKey("KEySearCHed"));
+ insertProjectDependency("3", dto -> dto.setKey("some_keySearched"));
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "keySearched");
+ List<ProjectDependencyDto> results = projectDependenciesDao.selectByQuery(db.getSession(), projectDependenciesQuery, Pagination.all());
+
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0)).usingRecursiveComparison().isEqualTo(projectDepSearched);
+ }
+
+ @Test
+ void update_shouldUpdateProjectDependency() {
+ ProjectDependencyDto projectDependencyDto = insertProjectDependency();
+ ProjectDependencyDto updatedProjectDependency =
+ new ProjectDependencyDto(projectDependencyDto.uuid(), "updatedVersion", "updatedIncludePaths", "updatedPackageManager", 2L, 3L);
+
+ projectDependenciesDao.update(db.getSession(), updatedProjectDependency);
+
+ List<Map<String, Object>> select = db.select(db.getSession(), "select * from project_dependencies");
+ assertThat(select).hasSize(1);
+ Map<String, Object> stringObjectMap = select.get(0);
+ assertThat(stringObjectMap).containsExactlyInAnyOrderEntriesOf(
+ Map.of(
+ "uuid", updatedProjectDependency.uuid(),
+ "version", updatedProjectDependency.version(),
+ "include_paths", updatedProjectDependency.includePaths(),
+ "package_manager", updatedProjectDependency.packageManager(),
+ "created_at", projectDependencyDto.createdAt(),
+ "updated_at", updatedProjectDependency.updatedAt())
+ );
+ }
+
+ @Test
+ void countByQuery_shouldReturnTheTotalOfDependencies() {
+ insertProjectDependency("sEArched");
+ insertProjectDependency("notWanted");
+ insertProjectDependency("sEArchedAsWell");
+ db.projectDependencies().insertProjectDependency("another_branch_uuid", "searched");
+
+ ProjectDependenciesQuery projectDependenciesQuery = new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, "long_nameSearCHed");
+
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), projectDependenciesQuery)).isEqualTo(2);
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), new ProjectDependenciesQuery(PROJECT_BRANCH_UUID, null))).isEqualTo(3);
+ assertThat(projectDependenciesDao.countByQuery(db.getSession(), new ProjectDependenciesQuery("another_branch_uuid", null))).isEqualTo(1);
+ }
+
+ private ProjectDependencyDto insertProjectDependency() {
+ return db.projectDependencies().insertProjectDependency(PROJECT_BRANCH_UUID);
+ }
+
+ private ProjectDependencyDto insertProjectDependency(String suffix) {
+ return insertProjectDependency(suffix, null);
+ }
+
+ private ProjectDependencyDto insertProjectDependency(String suffix, @Nullable Consumer<ComponentDto> dtoPopulator) {
+ return db.projectDependencies().insertProjectDependency(PROJECT_BRANCH_UUID, suffix, dtoPopulator);
+ }
+}
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 2913c653a97..9f3ed9ab4fe 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
@@ -41,6 +41,7 @@ import org.sonar.db.component.SnapshotDao;
import org.sonar.db.dependency.CveCweDao;
import org.sonar.db.dependency.CveDao;
import org.sonar.db.dependency.IssuesDependencyDao;
+import org.sonar.db.dependency.ProjectDependenciesDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
@@ -163,6 +164,7 @@ public class DaoModule extends Module {
PluginDao.class,
ProjectDao.class,
ProjectBadgeTokenDao.class,
+ ProjectDependenciesDao.class,
ProjectExportDao.class,
PortfolioDao.class,
ProjectLinkDao.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 46cb3d67623..fc0faf5c348 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
@@ -41,6 +41,7 @@ import org.sonar.db.component.SnapshotDao;
import org.sonar.db.dependency.CveCweDao;
import org.sonar.db.dependency.CveDao;
import org.sonar.db.dependency.IssuesDependencyDao;
+import org.sonar.db.dependency.ProjectDependenciesDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
@@ -202,6 +203,7 @@ public class DbClient {
private final CveDao cveDao;
private final CveCweDao cveCweDao;
private final IssuesDependencyDao issuesDependencyDao;
+ private final ProjectDependenciesDao projectDependenciesDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
@@ -299,6 +301,7 @@ public class DbClient {
cveDao = getDao(map, CveDao.class);
cveCweDao = getDao(map, CveCweDao.class);
issuesDependencyDao = getDao(map, IssuesDependencyDao.class);
+ projectDependenciesDao = getDao(map, ProjectDependenciesDao.class);
}
public DbSession openSession(boolean batch) {
@@ -666,4 +669,8 @@ public class DbClient {
public IssuesDependencyDao issuesDependencyDao() {
return issuesDependencyDao;
}
+
+ public ProjectDependenciesDao projectDependenciesDao() {
+ return projectDependenciesDao;
+ }
}
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 6239cb6bde9..84223ad785c 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
@@ -69,6 +69,8 @@ import org.sonar.db.dependency.CveDto;
import org.sonar.db.dependency.CveMapper;
import org.sonar.db.dependency.IssuesDependencyDto;
import org.sonar.db.dependency.IssuesDependencyMapper;
+import org.sonar.db.dependency.ProjectDependenciesMapper;
+import org.sonar.db.dependency.ProjectDependencyDto;
import org.sonar.db.duplication.DuplicationMapper;
import org.sonar.db.duplication.DuplicationUnitDto;
import org.sonar.db.entity.EntityDto;
@@ -250,6 +252,7 @@ public class MyBatis {
confBuilder.loadAlias("ProjectQgateAssociation", ProjectQgateAssociationDto.class);
confBuilder.loadAlias("Project", ProjectDto.class);
confBuilder.loadAlias("ProjectBadgeToken", ProjectBadgeTokenDto.class);
+ confBuilder.loadAlias("ProjectDependency", ProjectDependencyDto.class);
confBuilder.loadAlias("AnalysisPropertyValuePerProject", AnalysisPropertyValuePerProject.class);
confBuilder.loadAlias("ProjectAlmKeyAndProject", ProjectAlmKeyAndProject.class);
confBuilder.loadAlias("PrAndBranchCountByProjectDto", PrBranchAnalyzedLanguageCountByProjectDto.class);
@@ -325,6 +328,7 @@ public class MyBatis {
PluginMapper.class,
PortfolioMapper.class,
ProjectAlmSettingMapper.class,
+ ProjectDependenciesMapper.class,
ProjectLinkMapper.class,
ProjectMapper.class,
ProjectBadgeTokenMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesDao.java
new file mode 100644
index 00000000000..ae518d1217c
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesDao.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
+
+public class ProjectDependenciesDao implements Dao {
+
+ private static ProjectDependenciesMapper mapper(DbSession session) {
+ return session.getMapper(ProjectDependenciesMapper.class);
+ }
+
+ public void insert(DbSession session, ProjectDependencyDto projectDependencyDto) {
+ mapper(session).insert(projectDependencyDto);
+ }
+
+ public void deleteByUuid(DbSession session, String uuid) {
+ mapper(session).deleteByUuid(uuid);
+ }
+
+ public List<ProjectDependencyDto> selectByQuery(DbSession session, ProjectDependenciesQuery projectDependenciesQuery, Pagination pagination) {
+ return mapper(session).selectByQuery(projectDependenciesQuery, pagination);
+ }
+
+ public int countByQuery(DbSession session, ProjectDependenciesQuery projectDependenciesQuery) {
+ return mapper(session).countByQuery(projectDependenciesQuery);
+ }
+
+ public void update(DbSession session, ProjectDependencyDto projectDependencyDto) {
+ mapper(session).update(projectDependencyDto);
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesMapper.java
new file mode 100644
index 00000000000..e1d8a2b9bda
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesMapper.java
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+import org.sonar.db.Pagination;
+
+public interface ProjectDependenciesMapper {
+ void insert(ProjectDependencyDto dto);
+
+ void deleteByUuid(String uuid);
+
+ List<ProjectDependencyDto> selectByQuery(@Param("query") ProjectDependenciesQuery query, @Param("pagination") Pagination pagination);
+
+ void update(ProjectDependencyDto dto);
+
+ int countByQuery(@Param("query") ProjectDependenciesQuery query);
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesQuery.java
new file mode 100644
index 00000000000..16f4c8201e5
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependenciesQuery.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.Locale;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static org.sonar.db.DaoUtils.buildLikeValue;
+import static org.sonar.db.WildcardPosition.BEFORE_AND_AFTER;
+
+public final class ProjectDependenciesQuery {
+ private final String branchUuid;
+ @Nullable
+ private final String query;
+
+ public ProjectDependenciesQuery(String branchUuid, @Nullable String query) {
+ this.branchUuid = branchUuid;
+ this.query = query;
+ }
+
+ /**
+ * Used by MyBatis mapper
+ */
+ @CheckForNull
+ public String getLikeQuery() {
+ return query == null ? null : buildLikeValue(query, BEFORE_AND_AFTER).toLowerCase(Locale.ENGLISH);
+ }
+
+ public String branchUuid() {
+ return branchUuid;
+ }
+
+ @Nullable
+ public String query() {
+ return query;
+ }
+
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependencyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependencyDto.java
new file mode 100644
index 00000000000..6c9b6550063
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/dependency/ProjectDependencyDto.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import javax.annotation.Nullable;
+
+public record ProjectDependencyDto(
+ String uuid,
+ @Nullable String version,
+ @Nullable String includePaths,
+ @Nullable String packageManager,
+ Long createdAt,
+ Long updatedAt
+ ) {
+}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/dependency/ProjectDependenciesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/dependency/ProjectDependenciesMapper.xml
new file mode 100644
index 00000000000..e48e7973767
--- /dev/null
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/dependency/ProjectDependenciesMapper.xml
@@ -0,0 +1,72 @@
+<?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.dependency.ProjectDependenciesMapper">
+ <sql id="projectDependenciesColumns">
+ pd.uuid as uuid,
+ pd.version as version,
+ pd.include_paths as includePaths,
+ pd.package_manager as packageManager,
+ pd.created_at as createdAt,
+ pd.updated_at as updatedAt
+ </sql>
+
+ <insert id="insert" parameterType="ProjectDependency" useGeneratedKeys="false">
+ insert into project_dependencies (
+ uuid,
+ version,
+ include_paths,
+ package_manager,
+ created_at,
+ updated_at
+ ) values (
+ #{uuid,jdbcType=VARCHAR},
+ #{version,jdbcType=CLOB},
+ #{includePaths,jdbcType=CLOB},
+ #{packageManager,jdbcType=VARCHAR},
+ #{createdAt,jdbcType=BIGINT},
+ #{updatedAt,jdbcType=BIGINT}
+ )
+ </insert>
+
+ <delete id="deleteByUuid" parameterType="string">
+ delete from project_dependencies
+ where uuid = #{uuid,jdbcType=VARCHAR}
+ </delete>
+
+ <select id="selectByQuery" parameterType="map" resultType="ProjectDependency">
+ select <include refid="projectDependenciesColumns"/>
+ <include refid="sqlSelectByQuery" />
+ ORDER BY c.kee ASC
+ <include refid="org.sonar.db.common.Common.pagination"/>
+ </select>
+
+ <select id="countByQuery" resultType="int">
+ select count(pd.uuid)
+ <include refid="sqlSelectByQuery" />
+ </select>
+
+ <sql id="sqlSelectByQuery">
+ from project_dependencies pd
+ inner join components c on pd.uuid = c.uuid
+ where c.branch_uuid = #{query.branchUuid,jdbcType=VARCHAR}
+ <if test="query.query() != null">
+ AND (
+ c.kee = #{query.query,jdbcType=VARCHAR}
+ OR lower(c.long_name) LIKE #{query.likeQuery} ESCAPE '/'
+ )
+ </if>
+ </sql>
+
+ <update id="update" parameterType="ProjectDependency" useGeneratedKeys="false">
+ update project_dependencies
+ set
+ uuid = #{uuid, jdbcType=VARCHAR},
+ version = #{version, jdbcType=CLOB},
+ include_paths = #{includePaths, jdbcType=CLOB},
+ package_manager = #{packageManager, jdbcType=VARCHAR},
+ updated_at = #{updatedAt, jdbcType=BIGINT}
+ where
+ uuid = #{uuid, jdbcType=VARCHAR}
+ </update>
+
+</mapper>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index c18d6e54072..8d87b6f6d02 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -732,6 +732,16 @@ ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY(
CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROJECT_BRANCHES" ON "PROJECT_BRANCHES"("BRANCH_TYPE" NULLS FIRST, "PROJECT_UUID" NULLS FIRST, "KEE" NULLS FIRST);
CREATE INDEX "PROJECT_BRANCHES_PROJECT_UUID" ON "PROJECT_BRANCHES"("PROJECT_UUID" NULLS FIRST);
+CREATE TABLE "PROJECT_DEPENDENCIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "VERSION" CHARACTER LARGE OBJECT,
+ "INCLUDE_PATHS" CHARACTER LARGE OBJECT,
+ "PACKAGE_MANAGER" CHARACTER VARYING(50),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROJECT_DEPENDENCIES" ADD CONSTRAINT "PK_PROJECT_DEPENDENCIES" PRIMARY KEY("UUID");
+
CREATE TABLE "PROJECT_LINKS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
index 041cf9ffc84..9e6a46fecd5 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
@@ -42,6 +42,7 @@ import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ProjectLinkDbTester;
+import org.sonar.db.dependency.ProjectDependenciesDbTester;
import org.sonar.db.event.EventDbTester;
import org.sonar.db.favorite.FavoriteDbTester;
import org.sonar.db.issue.IssueDbTester;
@@ -94,6 +95,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
private final AlmPatsDbTester almPatsDbtester;
private final AuditDbTester auditDbTester;
private final AnticipatedTransitionDbTester anticipatedTransitionDbTester;
+ private final ProjectDependenciesDbTester projectDependenciesDbTester;
private DbTester(UuidFactory uuidFactory, System2 system2, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) {
super(TestDbImpl.create(schemaPath, confExtensions));
@@ -125,6 +127,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
this.almPatsDbtester = new AlmPatsDbTester(this);
this.auditDbTester = new AuditDbTester(this);
this.anticipatedTransitionDbTester = new AnticipatedTransitionDbTester(this);
+ this.projectDependenciesDbTester = new ProjectDependenciesDbTester(this);
}
public static DbTester create() {
@@ -268,6 +271,10 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
return anticipatedTransitionDbTester;
}
+ public ProjectDependenciesDbTester projectDependencies() {
+ return projectDependenciesDbTester;
+ }
+
@Override
public void afterEach(ExtensionContext context) throws Exception {
after();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index c4fd31374e0..7990f52e503 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -27,7 +27,6 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.portfolio.PortfolioDto;
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java
new file mode 100644
index 00000000000..edd64b6013e
--- /dev/null
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+
+public class ProjectDependenciesDbTester {
+ private final DbTester db;
+ private final DbClient dbClient;
+
+ public ProjectDependenciesDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid) {
+ return insertProjectDependency(branchUuid, EMPTY, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix) {
+ return insertProjectDependency(branchUuid, suffix, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix, @Nullable Consumer<ComponentDto> dtoPopulator) {
+ ComponentDto componentDto = new ComponentDto().setUuid("uuid" + suffix)
+ .setKey("key" + suffix)
+ .setUuidPath("uuidPath" + suffix)
+ .setName("name" + suffix)
+ .setLongName("long_name" + suffix)
+ .setBranchUuid(branchUuid);
+
+ if (dtoPopulator != null) {
+ dtoPopulator.accept(componentDto);
+ }
+
+ db.components().insertComponent(componentDto);
+ var projectDependencyDto = new ProjectDependencyDto(componentDto.uuid(), "version" + suffix, "includePaths" + suffix, "packageManager" + suffix, 1L, 2L);
+ dbClient.projectDependenciesDao().insert(db.getSession(), projectDependencyDto);
+ return projectDependencyDto;
+ }
+}