]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21259 Add Dao methods for issues_fixed table
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Mon, 18 Dec 2023 10:25:08 +0000 (11:25 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 17 Jan 2024 20:02:43 +0000 (20:02 +0000)
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueFixedDaoIT.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDao.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedMapper.java [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueFixedMapper.xml [new file with mode: 0644]

index d2d86adc25b2d726ec43f3d4d834a2dc8655a35d..6a33f544b461b9c576890edf9100d53b94186d57 100644 (file)
@@ -60,6 +60,7 @@ public final class SqTables {
     "internal_component_props",
     "internal_properties",
     "issues",
+    "issues_fixed",
     "issues_impacts",
     "issue_changes",
     "live_measures",
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueFixedDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueFixedDaoIT.java
new file mode 100644 (file)
index 0000000..8a42145
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.issue;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class IssueFixedDaoIT {
+  @Rule
+  public DbTester db = DbTester.create(System2.INSTANCE);
+
+  private final IssueFixedDao underTest = db.getDbClient().issueFixedDao();
+
+  @Test
+  public void insert_shouldPersistFixedIssue() {
+    IssueFixedDto fixedIssue = new IssueFixedDto("PR-1", "ISSUE-1");
+    underTest.insert(db.getSession(), fixedIssue);
+    assertThat(underTest.selectByPullRequest(db.getSession(), "PR-1")).containsOnly(fixedIssue);
+  }
+
+  @Test
+  public void insert_shouldThrowException_whenDuplicateRecord() {
+    IssueFixedDto fixedIssue = new IssueFixedDto("PR-1", "ISSUE-1");
+    DbSession session = db.getSession();
+    underTest.insert(session, fixedIssue);
+
+    assertThatThrownBy(() -> underTest.insert(session, fixedIssue))
+      .isInstanceOf(RuntimeException.class);
+  }
+
+  @Test
+  public void selectByPullRequest_shouldReturnAllFixedIssuesOfPullRequest() {
+    IssueFixedDto fixedIssue1 = new IssueFixedDto("PR-1", "ISSUE-1");
+    IssueFixedDto fixedIssue2 = new IssueFixedDto("PR-1", "ISSUE-2");
+    IssueFixedDto fixedIssue3 = new IssueFixedDto("PR-2", "ISSUE-3");
+    underTest.insert(db.getSession(), fixedIssue1);
+    underTest.insert(db.getSession(), fixedIssue2);
+    underTest.insert(db.getSession(), fixedIssue3);
+
+    assertThat(underTest.selectByPullRequest(db.getSession(), "PR-1")).containsOnly(fixedIssue1, fixedIssue2);
+  }
+
+}
index a83bc82405858250e283439d67c549960439c204..83ef19a51853095ebd0e5bdc7d79b51ca4dce5b5 100644 (file)
@@ -46,6 +46,7 @@ import org.sonar.db.event.EventDao;
 import org.sonar.db.issue.AnticipatedTransitionDao;
 import org.sonar.db.issue.IssueChangeDao;
 import org.sonar.db.issue.IssueDao;
+import org.sonar.db.issue.IssueFixedDao;
 import org.sonar.db.measure.LiveMeasureDao;
 import org.sonar.db.measure.MeasureDao;
 import org.sonar.db.metric.MetricDao;
@@ -144,6 +145,7 @@ public class DaoModule extends Module {
     InternalPropertiesDao.class,
     IssueChangeDao.class,
     IssueDao.class,
+    IssueFixedDao.class,
     LiveMeasureDao.class,
     MeasureDao.class,
     MetricDao.class,
index 159beb8374520cbea1761db8809b8b4be0807337..a670f4fbca160c3402e9869b3faed591cf968d92 100644 (file)
@@ -46,6 +46,7 @@ import org.sonar.db.event.EventDao;
 import org.sonar.db.issue.AnticipatedTransitionDao;
 import org.sonar.db.issue.IssueChangeDao;
 import org.sonar.db.issue.IssueDao;
+import org.sonar.db.issue.IssueFixedDao;
 import org.sonar.db.measure.LiveMeasureDao;
 import org.sonar.db.measure.MeasureDao;
 import org.sonar.db.metric.MetricDao;
@@ -193,6 +194,7 @@ public class DbClient {
   private final GithubPermissionsMappingDao githubPermissionsMappingDao;
   private final RuleChangeDao ruleChangeDao;
   private final ProjectExportDao projectExportDao;
+  private final IssueFixedDao issueFixedDao;
 
   public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
     this.database = database;
@@ -285,6 +287,7 @@ public class DbClient {
     anticipatedTransitionDao = getDao(map, AnticipatedTransitionDao.class);
     ruleChangeDao = getDao(map, RuleChangeDao.class);
     projectExportDao = getDao(map, ProjectExportDao.class);
+    issueFixedDao = getDao(map, IssueFixedDao.class);
   }
 
   public DbSession openSession(boolean batch) {
@@ -335,6 +338,10 @@ public class DbClient {
     return issueChangeDao;
   }
 
+  public IssueFixedDao issueFixedDao() {
+    return issueFixedDao;
+  }
+
   public QualityProfileDao qualityProfileDao() {
     return qualityProfileDao;
   }
index 0d920488076ed61f8c1769c584ba9ebd1c635e9e..28b941519ce90f48d908867dfdab9703c086720e 100644 (file)
@@ -77,6 +77,7 @@ import org.sonar.db.issue.ImpactDto;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueChangeMapper;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.issue.IssueFixedMapper;
 import org.sonar.db.issue.IssueMapper;
 import org.sonar.db.issue.NewCodeReferenceIssueDto;
 import org.sonar.db.issue.PrIssueDto;
@@ -301,6 +302,7 @@ public class MyBatis {
       IsAliveMapper.class,
       IssueChangeMapper.class,
       IssueMapper.class,
+      IssueFixedMapper.class,
       MeasureMapper.class,
       MetricMapper.class,
       NewCodePeriodMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDao.java
new file mode 100644 (file)
index 0000000..e0cd662
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.issue;
+
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class IssueFixedDao implements Dao {
+
+  public void insert(DbSession dbSession, IssueFixedDto fixedIssue) {
+    mapper(dbSession).insert(fixedIssue);
+  }
+
+  private static IssueFixedMapper mapper(DbSession session) {
+    return session.getMapper(IssueFixedMapper.class);
+  }
+
+  public List<IssueFixedDto> selectByPullRequest(DbSession dbSession, @Param("pullRequestUuid") String pullRequestUuid) {
+    return mapper(dbSession).selectByPullRequest(pullRequestUuid);
+  }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedDto.java
new file mode 100644 (file)
index 0000000..aeb1997
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.issue;
+
+public record IssueFixedDto(String pullRequestUuid, String issueKey) {
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueFixedMapper.java
new file mode 100644 (file)
index 0000000..1970440
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.issue;
+
+import java.util.List;
+
+public interface IssueFixedMapper {
+  void insert(IssueFixedDto dto);
+
+  List<IssueFixedDto> selectByPullRequest(String pullRequestUuid);
+}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueFixedMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueFixedMapper.xml
new file mode 100644 (file)
index 0000000..54602a4
--- /dev/null
@@ -0,0 +1,22 @@
+<?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.issue.IssueFixedMapper">
+  <insert id="insert" parameterType="org.sonar.db.issue.IssueFixedDto">
+    INSERT INTO issues_fixed (
+      pull_request_uuid,
+      issue_key
+    ) VALUES (
+      #{pullRequestUuid,jdbcType=VARCHAR},
+      #{issueKey,jdbcType=VARCHAR}
+    )
+  </insert>
+  <select id="selectByPullRequest" resultType="org.sonar.db.issue.IssueFixedDto">
+    SELECT
+      pull_request_uuid as pullRequestUuid,
+      issue_key as issueKey
+    FROM issues_fixed
+    WHERE pull_request_uuid = #{pullRequestUuid,jdbcType=VARCHAR}
+  </select>
+</mapper>