diff options
author | antoine.vinot <antoine.vinot@sonarsource.com> | 2024-10-11 15:54:52 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-21 20:03:59 +0000 |
commit | 596b193a1a2d64c50c728ff8051721f61cd79d0c (patch) | |
tree | 530b28376d5313c83d818c41dfae2273edbc4a54 /server/sonar-db-dao/src/main/java | |
parent | 65d606200841e8d63af5e2ad5039cefdd69bc72a (diff) | |
download | sonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.tar.gz sonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.zip |
SONAR-23098 Create Project Dependencies DB model
Diffstat (limited to 'server/sonar-db-dao/src/main/java')
7 files changed, 190 insertions, 0 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 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 + ) { +} |