]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19558 enabled snapshots to correctly use project/branch uuid
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Tue, 27 Jun 2023 08:24:50 +0000 (10:24 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 29 Jun 2023 20:05:14 +0000 (20:05 +0000)
65 files changed:
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodePeriodResolver.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportEventsStep.java
server/sonar-ce/src/it/java/org/sonar/ce/analysis/cache/cleaning/AnalysisCacheCleaningSchedulerImplIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/component/SnapshotDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/event/EventDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/measure/MeasureDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/scannercache/ScannerAnalysisCacheDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/AnalysisPropertiesMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/event/EventMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/scannercache/ScannerAnalysisCacheMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/event/EventTesting.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshots.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshots.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshots.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest/schema.sql [new file with mode: 0644]
server/sonar-server-common/src/it/java/org/sonar/server/measure/index/ProjectMeasuresIndexerIT.java
server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java
server/sonar-webserver-core/src/main/java/org/sonar/server/project/ProjectQGChangeEventListener.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/issue/index/AsyncIssueIndexingImplTest.java
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/CreateEventActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/branch/ws/ListAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsData.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectdump/ws/StatusAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java

index 47412e095b3e0a29ad3ca8f09c522a08109b23d7..e7caa7ab9e351e53f6fb3f607bf349db4b2a4fc1 100644 (file)
@@ -120,7 +120,7 @@ public class ReportPersistAnalysisStepIT extends BaseStepTest {
 
     SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
     assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
-    assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
+    assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid());
     assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion);
     assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString);
     assertThat(projectSnapshot.getLast()).isFalse();
@@ -199,7 +199,7 @@ public class ReportPersistAnalysisStepIT extends BaseStepTest {
 
   private SnapshotDto getUnprocessedSnapshot(String componentUuid) {
     List<SnapshotDto> projectSnapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbTester.getSession(),
-      new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED));
+      new SnapshotQuery().setRootComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED));
     assertThat(projectSnapshots).hasSize(1);
     return projectSnapshots.get(0);
   }
index 5f93479a6a580ad434e9f100020b9ad9b0fc3ff6..4c28414e9b334b498d3f1a82e248e9536c79f223 100644 (file)
@@ -106,7 +106,7 @@ public class ViewsPersistAnalysisStepIT extends BaseStepTest {
 
     SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
     assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
-    assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid());
+    assertThat(viewSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid());
     assertThat(viewSnapshot.getProjectVersion()).isNull();
     assertThat(viewSnapshot.getLast()).isFalse();
     assertThat(viewSnapshot.getStatus()).isEqualTo("U");
@@ -140,7 +140,7 @@ public class ViewsPersistAnalysisStepIT extends BaseStepTest {
 
   private SnapshotDto getUnprocessedSnapshot(String componentUuid) {
     List<SnapshotDto> projectSnapshots = dbClient.snapshotDao().selectAnalysesByQuery(dbTester.getSession(),
-      new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED));
+      new SnapshotQuery().setRootComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED));
     assertThat(projectSnapshots).hasSize(1);
     return projectSnapshots.get(0);
   }
index 6c96fe0ac008270d44f6fb3807ad2b3be9525090..99176b7efae56cf07a81a6c2f90abb36bf116053 100644 (file)
@@ -196,7 +196,7 @@ public class ExportAnalysesStepIT {
     return new SnapshotDto()
       .setUuid(uuid)
       .setCreatedAt(date)
-      .setComponentUuid(componentUuid)
+      .setRootComponentUuid(componentUuid)
       .setProjectVersion(version)
       .setBuildString(buildString)
       .setLast(isLast)
index b1ffa6fabbf8fb3df2a57ea7cf51abc5adbdc48e..d96797304a169cc13cd83b42fc33d3b9e9440f92 100644 (file)
@@ -117,7 +117,7 @@ public class ExportEventsStepIT {
     dbTester.getDbClient().eventDao().insert(dbTester.getSession(), new EventDto()
       .setUuid("E1")
       .setAnalysisUuid(snapshot.getUuid())
-      .setComponentUuid(snapshot.getComponentUuid())
+      .setComponentUuid(snapshot.getRootComponentUuid())
       .setDate(IN_THE_PAST)
       .setCreatedAt(NOW)
       .setData("data")
@@ -148,7 +148,7 @@ public class ExportEventsStepIT {
     dbTester.getDbClient().eventDao().insert(dbTester.getSession(), new EventDto()
       .setUuid(uuid)
       .setAnalysisUuid(snapshot.getUuid())
-      .setComponentUuid(snapshot.getComponentUuid())
+      .setComponentUuid(snapshot.getRootComponentUuid())
       .setDate(IN_THE_PAST)
       .setCreatedAt(NOW)
       .setName(name));
@@ -158,7 +158,7 @@ public class ExportEventsStepIT {
   private SnapshotDto insertSnapshot() {
     SnapshotDto snapshot = new SnapshotDto()
       .setUuid("U1")
-      .setComponentUuid(PROJECT.uuid())
+      .setRootComponentUuid(PROJECT.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false);
     dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), snapshot);
index 136b2dd1501ceefb418844c8686539b502aad54b..86c0c0387e019c59817f3d26a60d333170da00d7 100644 (file)
@@ -244,7 +244,7 @@ public class ExportMeasuresStepIT {
   private SnapshotDto insertSnapshot(String snapshotUuid, ComponentDto project, String status) {
     SnapshotDto snapshot = new SnapshotDto()
       .setUuid(snapshotUuid)
-      .setComponentUuid(project.uuid())
+      .setRootComponentUuid(project.uuid())
       .setStatus(status)
       .setLast(true);
     dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), snapshot);
index c3480c7e87259dd44b667954dba3ba1f592d14f5..41862ff63ef0df54787d014c735da82b67917007 100644 (file)
@@ -90,24 +90,24 @@ public class NewCodePeriodResolver {
 
   private Period resolveBySpecificAnalysis(DbSession dbSession, String rootUuid, String value) {
     SnapshotDto baseline = dbClient.snapshotDao().selectByUuid(dbSession, value)
-      .filter(t -> t.getComponentUuid().equals(rootUuid))
+      .filter(t -> t.getRootComponentUuid().equals(rootUuid))
       .orElseThrow(() -> new IllegalStateException("Analysis '" + value + "' of project '" + rootUuid
         + "' defined as the baseline does not exist"));
     LOG.debug("Resolving new code period with a specific analysis");
     return newPeriod(NewCodePeriodType.SPECIFIC_ANALYSIS, value, baseline.getCreatedAt());
   }
 
-  private Period resolveByPreviousVersion(DbSession dbSession, String projectUuid, String projectVersion) {
-    List<EventDto> versions = dbClient.eventDao().selectVersionsByMostRecentFirst(dbSession, projectUuid);
+  private Period resolveByPreviousVersion(DbSession dbSession, String rootComponentUuid, String projectVersion) {
+    List<EventDto> versions = dbClient.eventDao().selectVersionsByMostRecentFirst(dbSession, rootComponentUuid);
     if (versions.isEmpty()) {
-      return findOldestAnalysis(dbSession, projectUuid);
+      return findOldestAnalysis(dbSession, rootComponentUuid);
     }
 
     String mostRecentVersion = Optional.ofNullable(versions.iterator().next().getName())
       .orElseThrow(() -> new IllegalStateException("selectVersionsByMostRecentFirst returned a DTO which didn't have a name"));
 
     if (versions.size() == 1 && projectVersion.equals(mostRecentVersion)) {
-      return findOldestAnalysis(dbSession, projectUuid);
+      return findOldestAnalysis(dbSession, rootComponentUuid);
     }
 
     return resolvePreviousVersion(dbSession, projectVersion, versions, mostRecentVersion);
@@ -130,9 +130,9 @@ public class NewCodePeriodResolver {
     return newPeriod(dbSession, previousVersion);
   }
 
-  private Period findOldestAnalysis(DbSession dbSession, String projectUuid) {
+  private Period findOldestAnalysis(DbSession dbSession, String rootComponentUuid) {
     LOG.debug("Resolving first analysis as new code period as there is only one existing version");
-    Optional<Period> period = dbClient.snapshotDao().selectOldestAnalysis(dbSession, projectUuid)
+    Optional<Period> period = dbClient.snapshotDao().selectOldestAnalysis(dbSession, rootComponentUuid)
       .map(dto -> newPeriod(NewCodePeriodType.PREVIOUS_VERSION, null, dto.getCreatedAt()));
     ensureNotOnFirstAnalysis(period.isPresent());
     return period.get();
@@ -162,7 +162,7 @@ public class NewCodePeriodResolver {
   }
 
   private static SnapshotQuery createCommonQuery(String projectUuid) {
-    return new SnapshotQuery().setComponentUuid(projectUuid).setStatus(STATUS_PROCESSED);
+    return new SnapshotQuery().setRootComponentUuid(projectUuid).setStatus(STATUS_PROCESSED);
   }
 
   private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Instant targetDate) {
index 4fe25256b75ac00532cb23d4fdd10f38f03ec552..2b8e262b9baec4606e3ca57988b3aeaa170656ce 100644 (file)
@@ -107,7 +107,7 @@ public class PersistAnalysisStep implements ComputationStep {
         .setUuid(snapshotUuid)
         .setProjectVersion(projectVersion)
         .setBuildString(buildString)
-        .setComponentUuid(componentUuid)
+        .setRootComponentUuid(componentUuid)
         .setLast(false)
         .setStatus(SnapshotDto.STATUS_UNPROCESSED)
         .setCreatedAt(analysisDate)
index 5d88ab818b6651bb7a6dcf609b5a5f8747fb434d..2db9737900c4467d0d202e90c30297edd899b6c8 100644 (file)
@@ -49,7 +49,7 @@ public class ExportAnalysesStep implements ComputationStep {
     " s.period1_mode, s.period1_param, s.period1_date," +
     " s.uuid, s.build_string" +
     " from snapshots s" +
-    " inner join components p on s.component_uuid=p.uuid" +
+    " inner join components p on s.root_component_uuid=p.uuid" +
     " inner join project_branches pb on pb.uuid=p.uuid" +
     " where pb.project_uuid=? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge=? and s.status=? and p.enabled=?" +
     " order by s.build_date asc";
index e4e9f97ed2d1f91d32c69042a1d323b6e033b50f..d1fcf70629bb5e29a586f9bb23c3c9e2e0a4f274 100644 (file)
@@ -41,7 +41,7 @@ public class ExportEventsStep implements ComputationStep {
     " p.uuid, e.name, e.analysis_uuid, e.category, e.description, e.event_data, e.event_date, e.uuid" +
     " from events e" +
     " join snapshots s on s.uuid=e.analysis_uuid" +
-    " join components p on p.uuid=s.component_uuid" +
+    " join components p on p.uuid=s.root_component_uuid" +
     " join project_branches pb on pb.uuid=p.uuid" +
     " where pb.project_uuid=? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge=? and s.status=? and p.enabled=?";
 
index 8aa991e6f11ffa104509dfca144eaa8b4929212b..fe6683c7753e57d2dd19616fd8b4894f6921d64e 100644 (file)
@@ -66,32 +66,32 @@ public class AnalysisCacheCleaningSchedulerImplIT {
     var snapshotDao = dbTester.getDbClient().snapshotDao();
     var snapshot1 = createSnapshot(LocalDateTime.now().minusDays(1).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot1);
-    scannerAnalysisCacheDao.insert(dbSession, snapshot1.getComponentUuid(), new ByteArrayInputStream("data".getBytes()));
+    scannerAnalysisCacheDao.insert(dbSession, snapshot1.getRootComponentUuid(), new ByteArrayInputStream("data".getBytes()));
     var snapshot2 = createSnapshot(LocalDateTime.now().minusDays(6).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot2);
-    scannerAnalysisCacheDao.insert(dbSession, snapshot2.getComponentUuid(), new ByteArrayInputStream("data".getBytes()));
+    scannerAnalysisCacheDao.insert(dbSession, snapshot2.getRootComponentUuid(), new ByteArrayInputStream("data".getBytes()));
     var snapshot3 = createSnapshot(LocalDateTime.now().minusDays(8).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot3);
-    scannerAnalysisCacheDao.insert(dbSession, snapshot3.getComponentUuid(), new ByteArrayInputStream("data".getBytes()));
+    scannerAnalysisCacheDao.insert(dbSession, snapshot3.getRootComponentUuid(), new ByteArrayInputStream("data".getBytes()));
     var snapshot4 = createSnapshot(LocalDateTime.now().minusDays(30).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot4);
-    scannerAnalysisCacheDao.insert(dbSession, snapshot4.getComponentUuid(), new ByteArrayInputStream("data".getBytes()));
+    scannerAnalysisCacheDao.insert(dbSession, snapshot4.getRootComponentUuid(), new ByteArrayInputStream("data".getBytes()));
 
     assertThat(dbTester.countRowsOfTable("scanner_analysis_cache")).isEqualTo(4);
 
     underTest.clean();
 
     assertThat(dbTester.countRowsOfTable("scanner_analysis_cache")).isEqualTo(2);
-    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot1.getComponentUuid())).isNotNull();
-    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot2.getComponentUuid())).isNotNull();
-    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot3.getComponentUuid())).isNull();
-    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot4.getComponentUuid())).isNull();
+    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot1.getRootComponentUuid())).isNotNull();
+    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot2.getRootComponentUuid())).isNotNull();
+    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot3.getRootComponentUuid())).isNull();
+    assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot4.getRootComponentUuid())).isNull();
   }
 
   private static SnapshotDto createSnapshot(long buildtime) {
     return new SnapshotDto()
       .setUuid(uuidFactory.create())
-      .setComponentUuid(uuidFactory.create())
+      .setRootComponentUuid(uuidFactory.create())
       .setStatus("P")
       .setLast(true)
       .setProjectVersion("2.1-SNAPSHOT")
index 2361b2e81ed475d6046541a537fb7819b513190e..9193c7b86a606eb07fff4e7b2e93c0767de0745d 100644 (file)
@@ -65,7 +65,7 @@ import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 public class SnapshotDaoIT {
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
 
   private final DbClient dbClient = db.getDbClient();
   private final DbSession dbSession = db.getSession();
@@ -89,7 +89,7 @@ public class SnapshotDaoIT {
 
     SnapshotDto result = underTest.selectByUuid(db.getSession(), "ABCD").get();
     assertThat(result.getUuid()).isEqualTo("ABCD");
-    assertThat(result.getComponentUuid()).isEqualTo(project.uuid());
+    assertThat(result.getRootComponentUuid()).isEqualTo(project.uuid());
     assertThat(result.getStatus()).isEqualTo("P");
     assertThat(result.getLast()).isTrue();
     assertThat(result.getProjectVersion()).isEqualTo("2.1.0");
@@ -170,43 +170,43 @@ public class SnapshotDaoIT {
 
   @Test
   public void selectLastAnalysisDateByProjects_returns_all_existing_projects_with_a_snapshot() {
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData project1 = db.components().insertPrivateProject();
 
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto branch1 = db.components().insertProjectBranch(project2);
-    ComponentDto branch2 = db.components().insertProjectBranch(project2);
+    ProjectData project2 = db.components().insertPrivateProject();
+    ComponentDto branch1 = db.components().insertProjectBranch(project2.getMainBranchComponent());
+    ComponentDto branch2 = db.components().insertProjectBranch(project2.getMainBranchComponent());
 
-    ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData project3 = db.components().insertPrivateProject();
 
-    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1).setLast(false).setCreatedAt(2L));
-    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1).setLast(true).setCreatedAt(1L));
+    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1.getMainBranchComponent()).setLast(false).setCreatedAt(2L));
+    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1.getMainBranchComponent()).setLast(true).setCreatedAt(1L));
 
-    dbClient.snapshotDao().insert(dbSession, newAnalysis(project2).setLast(true).setCreatedAt(2L));
+    dbClient.snapshotDao().insert(dbSession, newAnalysis(project2.getMainBranchComponent()).setLast(true).setCreatedAt(2L));
     dbClient.snapshotDao().insert(dbSession, newAnalysis(branch2).setLast(false).setCreatedAt(5L));
     dbClient.snapshotDao().insert(dbSession, newAnalysis(branch1).setLast(true).setCreatedAt(4L));
 
     List<ProjectLastAnalysisDateDto> lastAnalysisByProject = underTest.selectLastAnalysisDateByProjectUuids(dbSession,
-      List.of(project1.uuid(), project2.uuid(), project3.uuid(), "non-existing"));
+      List.of(project1.projectUuid(), project2.projectUuid(), project3.projectUuid(), "non-existing"));
 
     assertThat(lastAnalysisByProject).extracting(ProjectLastAnalysisDateDto::getProjectUuid, ProjectLastAnalysisDateDto::getDate)
-      .containsOnly(tuple(project1.uuid(), 1L), tuple(project2.uuid(), 4L));
+      .containsOnly(tuple(project1.projectUuid(), 1L), tuple(project2.projectUuid(), 4L));
   }
 
   @Test
   public void selectLastAnalysisDateByProjects_returns_all_existing_projects_and_portfolios_with_a_snapshot() {
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto branch1 = db.components().insertProjectBranch(project1);
+    ProjectData project1 = db.components().insertPrivateProject();
+    ComponentDto branch1 = db.components().insertProjectBranch(project1.getMainBranchComponent());
     ComponentDto portfolio = db.components().insertPrivatePortfolio();
 
-    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1).setLast(true).setCreatedAt(1L));
+    dbClient.snapshotDao().insert(dbSession, newAnalysis(project1.getMainBranchComponent()).setLast(true).setCreatedAt(1L));
     dbClient.snapshotDao().insert(dbSession, newAnalysis(portfolio).setLast(true).setCreatedAt(2L));
     dbClient.snapshotDao().insert(dbSession, newAnalysis(branch1).setLast(true).setCreatedAt(3L));
 
     List<ProjectLastAnalysisDateDto> lastAnalysisByProject = underTest.selectLastAnalysisDateByProjectUuids(dbSession,
-      List.of(project1.uuid(), portfolio.uuid()));
+      List.of(project1.projectUuid(), portfolio.uuid()));
 
     assertThat(lastAnalysisByProject).extracting(ProjectLastAnalysisDateDto::getProjectUuid, ProjectLastAnalysisDateDto::getDate)
-      .containsOnly(tuple(project1.uuid(), 3L), tuple(portfolio.uuid(), 2L));
+      .containsOnly(tuple(project1.projectUuid(), 3L), tuple(portfolio.uuid(), 2L));
   }
 
   @Test
@@ -238,13 +238,13 @@ public class SnapshotDaoIT {
       .mapToObj(j -> db.components().insertSnapshot(project2))
       .toList();
 
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project1.uuid())))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project1.uuid())))
       .extracting(SnapshotDto::getUuid)
       .containsOnly(snapshots1.stream().map(SnapshotDto::getUuid).toArray(String[]::new));
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project2.uuid())))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project2.uuid())))
       .extracting(SnapshotDto::getUuid)
       .containsOnly(snapshots2.stream().map(SnapshotDto::getUuid).toArray(String[]::new));
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("does not exist")))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid("does not exist")))
       .isEmpty();
   }
 
@@ -258,13 +258,13 @@ public class SnapshotDaoIT {
     Collections.shuffle(snapshots);
     snapshots.forEach(db.components()::insertSnapshot);
 
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project.uuid()).setSort(BY_DATE, ASC)))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project.uuid()).setSort(BY_DATE, ASC)))
       .extracting(SnapshotDto::getUuid)
       .containsExactly(snapshots.stream()
         .sorted(Comparator.comparingLong(SnapshotDto::getCreatedAt))
         .map(SnapshotDto::getUuid)
         .toArray(String[]::new));
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project.uuid()).setSort(BY_DATE, DESC)))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project.uuid()).setSort(BY_DATE, DESC)))
       .extracting(SnapshotDto::getUuid)
       .containsExactly(snapshots.stream()
         .sorted(Comparator.comparingLong(SnapshotDto::getCreatedAt).reversed())
@@ -279,10 +279,10 @@ public class SnapshotDaoIT {
     SnapshotDto lastSnapshot = db.components().insertSnapshot(project1, t -> t.setLast(true));
     db.components().insertSnapshot(project1, t -> t.setLast(false));
 
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project1.uuid()).setIsLast(true)))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project1.uuid()).setIsLast(true)))
       .extracting(SnapshotDto::getUuid)
       .containsOnly(lastSnapshot.getUuid());
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("unknown").setIsLast(true)))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid("unknown").setIsLast(true)))
       .isEmpty();
   }
 
@@ -294,7 +294,7 @@ public class SnapshotDaoIT {
     SnapshotDto lastSnapshot2 = db.components().insertSnapshot(project1, t -> t.setLast(true));
     db.components().insertSnapshot(project1, t -> t.setLast(false));
 
-    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project1.uuid()).setIsLast(true)))
+    assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setRootComponentUuid(project1.uuid()).setIsLast(true)))
       .extracting(SnapshotDto::getUuid)
       .containsOnly(lastSnapshot1.getUuid(), lastSnapshot2.getUuid());
   }
@@ -319,22 +319,22 @@ public class SnapshotDaoIT {
   public void selectFinishedByComponentUuidsAndFromDates() {
     long from = 1_500_000_000_000L;
     long otherFrom = 1_200_000_000_000L;
-    ComponentDto firstProject = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto secondProject = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto thirdProject = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData firstProject = db.components().insertPublicProject();
+    ProjectData secondProject = db.components().insertPublicProject();
+    ProjectData thirdProject = db.components().insertPublicProject();
     SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
-    insertActivity(firstProject.uuid(), finishedAnalysis, SUCCESS);
+    insertActivity(firstProject.getMainBranchComponent().uuid(), finishedAnalysis, SUCCESS);
     SnapshotDto otherFinishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from + 1_000_000L));
-    insertActivity(firstProject.uuid(), otherFinishedAnalysis, SUCCESS);
+    insertActivity(firstProject.getMainBranchComponent().uuid(), otherFinishedAnalysis, SUCCESS);
     SnapshotDto oldAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from - 1L));
-    insertActivity(firstProject.uuid(), oldAnalysis, SUCCESS);
+    insertActivity(firstProject.getMainBranchComponent().uuid(), oldAnalysis, SUCCESS);
     SnapshotDto analysisOnSecondProject = db.components().insertSnapshot(secondProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(otherFrom));
-    insertActivity(secondProject.uuid(), analysisOnSecondProject, SUCCESS);
+    insertActivity(secondProject.getMainBranchComponent().uuid(), analysisOnSecondProject, SUCCESS);
     SnapshotDto oldAnalysisOnThirdProject = db.components().insertSnapshot(thirdProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(otherFrom - 1L));
-    insertActivity(thirdProject.uuid(), oldAnalysisOnThirdProject, SUCCESS);
+    insertActivity(thirdProject.getMainBranchComponent().uuid(), oldAnalysisOnThirdProject, SUCCESS);
 
     List<SnapshotDto> result = underTest.selectFinishedByProjectUuidsAndFromDates(dbSession,
-      Arrays.asList(firstProject.uuid(), secondProject.uuid(), thirdProject.uuid()),
+      Arrays.asList(firstProject.projectUuid(), secondProject.projectUuid(), thirdProject.projectUuid()),
       Arrays.asList(from, otherFrom, otherFrom));
 
     assertThat(result).extracting(SnapshotDto::getUuid)
@@ -344,36 +344,37 @@ public class SnapshotDaoIT {
   @Test
   public void selectFinishedByComponentUuidsAndFromDates_returns_processed_analysis_even_if_analysis_failed() {
     long from = 1_500_000_000_000L;
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData project = db.components().insertPublicProject();
     SnapshotDto unprocessedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_UNPROCESSED).setCreatedAt(from + 1_000_000L));
-    insertActivity(project.uuid(), unprocessedAnalysis, CANCELED);
+    insertActivity(project.getMainBranchComponent().uuid(), unprocessedAnalysis, CANCELED);
     SnapshotDto finishedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
-    insertActivity(project.uuid(), finishedAnalysis, SUCCESS);
+    insertActivity(project.getMainBranchComponent().uuid(), finishedAnalysis, SUCCESS);
     SnapshotDto canceledAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
-    insertActivity(project.uuid(), canceledAnalysis, CANCELED);
+    insertActivity(project.getMainBranchComponent().uuid(), canceledAnalysis, CANCELED);
 
-    List<SnapshotDto> result = underTest.selectFinishedByProjectUuidsAndFromDates(dbSession, singletonList(project.uuid()), singletonList(from));
+    List<SnapshotDto> result = underTest.selectFinishedByProjectUuidsAndFromDates(dbSession,
+      singletonList(project.getProjectDto().getUuid()), singletonList(from));
 
-    assertThat(result).extracting(SnapshotDto::getUuid)
-      .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), canceledAnalysis.getUuid());
+    assertThat(result).extracting(SnapshotDto::getUuid).containsExactlyInAnyOrder(finishedAnalysis.getUuid(), canceledAnalysis.getUuid());
   }
 
   @Test
   public void selectFinishedByComponentUuidsAndFromDates_return_branches_analysis() {
     long from = 1_500_000_000_000L;
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto firstBranch = db.components().insertProjectBranch(project);
-    ComponentDto secondBranch = db.components().insertProjectBranch(project);
+    ProjectData project = db.components().insertPublicProject();
+    ComponentDto firstBranch = db.components().insertProjectBranch(project.getMainBranchComponent());
+    ComponentDto secondBranch = db.components().insertProjectBranch(project.getMainBranchComponent());
     SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
-    insertActivity(project.uuid(), finishedAnalysis, SUCCESS);
+    insertActivity(project.getProjectDto().getUuid(), finishedAnalysis, SUCCESS);
     SnapshotDto otherFinishedAnalysis = db.components().insertSnapshot(firstBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from + 1_000_000L));
-    insertActivity(project.uuid(), otherFinishedAnalysis, SUCCESS);
+    insertActivity(project.getProjectDto().getUuid(), otherFinishedAnalysis, SUCCESS);
     SnapshotDto oldAnalysis = db.components().insertSnapshot(firstBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from - 1L));
-    insertActivity(project.uuid(), oldAnalysis, SUCCESS);
+    insertActivity(project.getProjectDto().getUuid(), oldAnalysis, SUCCESS);
     SnapshotDto analysisOnSecondBranch = db.components().insertSnapshot(secondBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
-    insertActivity(project.uuid(), analysisOnSecondBranch, SUCCESS);
+    insertActivity(project.getProjectDto().getUuid(), analysisOnSecondBranch, SUCCESS);
 
-    List<SnapshotDto> result = underTest.selectFinishedByProjectUuidsAndFromDates(dbSession, singletonList(project.uuid()), singletonList(from));
+    List<SnapshotDto> result = underTest.selectFinishedByProjectUuidsAndFromDates(dbSession, singletonList(project.getProjectDto().getUuid()),
+      singletonList(from));
 
     assertThat(result).extracting(SnapshotDto::getUuid)
       .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), otherFinishedAnalysis.getUuid(), analysisOnSecondBranch.getUuid());
@@ -413,7 +414,7 @@ public class SnapshotDaoIT {
       .setCreatedAt(1403042400000L));
 
     assertThat(dto.getUuid()).isNotNull();
-    assertThat(dto.getComponentUuid()).isEqualTo(project.uuid());
+    assertThat(dto.getRootComponentUuid()).isEqualTo(project.uuid());
     assertThat(dto.getStatus()).isEqualTo("P");
     assertThat(dto.getLast()).isTrue();
     assertThat(dto.getPeriodMode()).isEqualTo("days");
@@ -520,7 +521,7 @@ public class SnapshotDaoIT {
     SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false);
     db.commit();
     analysis
-      .setComponentUuid("P42")
+      .setRootComponentUuid("P42")
       .setProjectVersion("5.6.3")
       .setStatus(STATUS_UNPROCESSED);
 
@@ -529,7 +530,7 @@ public class SnapshotDaoIT {
     SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get();
     assertThat(result.getProjectVersion()).isEqualTo("5.6.3");
     assertThat(result.getStatus()).isEqualTo(STATUS_UNPROCESSED);
-    assertThat(result.getComponentUuid()).isEqualTo("P1");
+    assertThat(result.getRootComponentUuid()).isEqualTo("P1");
   }
 
   private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
@@ -550,7 +551,7 @@ public class SnapshotDaoIT {
   private static SnapshotDto defaultSnapshot() {
     return new SnapshotDto()
       .setUuid("u1")
-      .setComponentUuid("uuid_3")
+      .setRootComponentUuid("uuid_3")
       .setStatus("P")
       .setLast(true)
       .setProjectVersion("2.1-SNAPSHOT")
index 9ef4dacca8cb086def07b7a30e0f6f2409b018be..3501b5dcf2dd2b68b5b02f805dd79496b38a8d45 100644 (file)
@@ -72,7 +72,7 @@ public class EventDaoIT {
       .toArray(String[]::new);
     EventDto event2 = dbTester.events().insertEvent(new EventDto()
       .setAnalysisUuid(analysis2.getUuid())
-      .setComponentUuid(analysis2.getComponentUuid())
+      .setComponentUuid(analysis2.getRootComponentUuid())
       .setName("name_2_")
       .setUuid("2_")
       .setCategory("cat_2_")
index 446e093f2653504cd89db11a927507da91410b3f..fd7b4346fb01c31afd6bfb5ba3b6455fa099d76b 100644 (file)
@@ -218,7 +218,7 @@ public class MeasureDaoIT {
   private SnapshotDto insertAnalysis(String projectUuid, boolean isLast) {
     return db.getDbClient().snapshotDao().insert(db.getSession(), SnapshotTesting.newSnapshot()
       .setUuid(Uuids.createFast())
-      .setComponentUuid(projectUuid)
+      .setRootComponentUuid(projectUuid)
       .setLast(isLast));
   }
 
index f8105bd490dde7b64cd034e7e831725821e79835..b4715ba36f50857a3d750e55ce1b78492b435c8f 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.db.measure;
 
 import com.google.common.collect.Maps;
 import java.util.Map;
-import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
@@ -30,13 +29,10 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures;
 import org.sonar.db.metric.MetricDto;
-import org.sonar.db.project.ProjectDto;
 
-import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
@@ -47,8 +43,6 @@ import static org.sonar.api.measures.Metric.ValueType.DISTRIB;
 import static org.sonar.api.measures.Metric.ValueType.INT;
 import static org.sonar.api.measures.Metric.ValueType.LEVEL;
 import static org.sonar.api.measures.Metric.ValueType.STRING;
-import static org.sonar.db.component.ComponentDbTester.defaults;
-import static org.sonar.db.component.ComponentDbTester.toProjectDto;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 
 public class ProjectMeasuresIndexerIteratorIT {
index ae98a492771e1c13273916f4175e119ee697af43..43ab97549b50329e0f0fed44fb6b3770927872e2 100644 (file)
@@ -397,7 +397,7 @@ public class PurgeCommandsIT {
   }
 
   private Stream<String> uuidsOfAnalysesOfRoot(ComponentDto rootComponent) {
-    return dbTester.select("select uuid as \"UUID\" from snapshots where component_uuid='" + rootComponent.uuid() + "'")
+    return dbTester.select("select uuid as \"UUID\" from snapshots where root_component_uuid='" + rootComponent.uuid() + "'")
       .stream()
       .map(t -> (String) t.get("UUID"));
   }
@@ -887,13 +887,13 @@ public class PurgeCommandsIT {
   }
 
   private int countAnalysesOfRoot(ComponentDto projectOrView) {
-    return dbTester.countSql("select count(1) from snapshots where component_uuid='" + projectOrView.uuid() + "'");
+    return dbTester.countSql("select count(1) from snapshots where root_component_uuid='" + projectOrView.uuid() + "'");
   }
 
   private int countAnalysesOfRoot(ComponentDto projectOrView, String status, boolean isLast) {
     Dialect dialect = dbTester.getDbClient().getDatabase().getDialect();
     String bool = isLast ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue();
-    return dbTester.countSql("select count(1) from snapshots where component_uuid='" + projectOrView.uuid() + "' and status='" + status + "' and islast=" + bool);
+    return dbTester.countSql("select count(1) from snapshots where root_component_uuid='" + projectOrView.uuid() + "' and status='" + status + "' and islast=" + bool);
   }
 
   private List<String> getHugeNumberOfUuids() {
index 5739021ecfd9dcfb0c6b790978cf53606b9d0303..6ddf1800c4d0d8a071cbfc65e9523dcbf021210f 100644 (file)
@@ -437,31 +437,31 @@ public class PurgeDaoIT {
     SnapshotDto[] analyses = new SnapshotDto[] {
       newSnapshot()
         .setUuid("u1")
-        .setComponentUuid(PROJECT_UUID)
+        .setRootComponentUuid(PROJECT_UUID)
         .setStatus(STATUS_PROCESSED)
         .setLast(true),
       // not processed -> exclude
       newSnapshot()
         .setUuid("u2")
-        .setComponentUuid(PROJECT_UUID)
+        .setRootComponentUuid(PROJECT_UUID)
         .setStatus(STATUS_UNPROCESSED)
         .setLast(false),
       // on other resource -> exclude
       newSnapshot()
         .setUuid("u3")
-        .setComponentUuid("uuid_222")
+        .setRootComponentUuid("uuid_222")
         .setStatus(STATUS_PROCESSED)
         .setLast(true),
       // without event -> select
       newSnapshot()
         .setUuid("u4")
-        .setComponentUuid(PROJECT_UUID)
+        .setRootComponentUuid(PROJECT_UUID)
         .setStatus(STATUS_PROCESSED)
         .setLast(false),
       // with event -> select
       newSnapshot()
         .setUuid("u5")
-        .setComponentUuid(PROJECT_UUID)
+        .setRootComponentUuid(PROJECT_UUID)
         .setStatus(STATUS_PROCESSED)
         .setLast(false)
         .setProjectVersion("V5")
@@ -489,7 +489,7 @@ public class PurgeDaoIT {
   public void selectPurgeableAnalyses_does_not_return_the_baseline() {
     ComponentDto project1 = db.components().insertPublicProject("master").getMainBranchComponent();
     SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot()
-      .setComponentUuid(project1.uuid())
+      .setRootComponentUuid(project1.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false));
     dbClient.newCodePeriodDao().insert(dbSession,
@@ -500,7 +500,7 @@ public class PurgeDaoIT {
         .setValue(analysis1.getUuid()));
     ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
     SnapshotDto analysis2 = db.components().insertSnapshot(newSnapshot()
-      .setComponentUuid(project2.uuid())
+      .setRootComponentUuid(project2.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false));
     db.components().insertProjectBranch(project2);
@@ -515,7 +515,7 @@ public class PurgeDaoIT {
   public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() {
     ComponentDto project = db.components().insertPublicProject("master").getMainBranchComponent();
     SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot()
-      .setComponentUuid(project.uuid())
+      .setRootComponentUuid(project.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false));
     dbClient.newCodePeriodDao().insert(dbSession,
@@ -526,12 +526,12 @@ public class PurgeDaoIT {
         .setValue(analysisProject.getUuid()));
     ComponentDto branch1 = db.components().insertProjectBranch(project);
     SnapshotDto analysisBranch1 = db.components().insertSnapshot(newSnapshot()
-      .setComponentUuid(branch1.uuid())
+      .setRootComponentUuid(branch1.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false));
     ComponentDto branch2 = db.components().insertProjectBranch(project);
     SnapshotDto analysisBranch2 = db.components().insertSnapshot(newSnapshot()
-      .setComponentUuid(branch2.uuid())
+      .setRootComponentUuid(branch2.uuid())
       .setStatus(STATUS_PROCESSED)
       .setLast(false));
     dbClient.newCodePeriodDao().insert(dbSession,
@@ -1971,7 +1971,7 @@ public class PurgeDaoIT {
   }
 
   private Stream<String> uuidsOfAnalysesOfRoot(ComponentDto rootComponent) {
-    return db.select("select uuid as \"UUID\" from snapshots where component_uuid='" + rootComponent.uuid() + "'")
+    return db.select("select uuid as \"UUID\" from snapshots where root_component_uuid='" + rootComponent.uuid() + "'")
       .stream()
       .map(t -> (String) t.get("UUID"));
   }
index d426ba047962bb2a3156caea29b12280a01264a0..2dab8a159e095b1b27fd9e240a4ba5d3b1b30723 100644 (file)
@@ -97,16 +97,16 @@ public class ScannerAnalysisCacheDaoIT {
     var snapshotDao = dbTester.getDbClient().snapshotDao();
     var snapshot1 = createSnapshot(LocalDateTime.now().minusDays(1).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot1);
-    underTest.insert(dbSession, snapshot1.getComponentUuid(), stringToInputStream("test data"));
+    underTest.insert(dbSession, snapshot1.getRootComponentUuid(), stringToInputStream("test data"));
     var snapshot2 = createSnapshot(LocalDateTime.now().minusDays(6).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot2);
-    underTest.insert(dbSession, snapshot2.getComponentUuid(), stringToInputStream("test data"));
+    underTest.insert(dbSession, snapshot2.getRootComponentUuid(), stringToInputStream("test data"));
     var snapshot3 = createSnapshot(LocalDateTime.now().minusDays(8).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot3);
-    underTest.insert(dbSession, snapshot3.getComponentUuid(), stringToInputStream("test data"));
+    underTest.insert(dbSession, snapshot3.getRootComponentUuid(), stringToInputStream("test data"));
     var snapshot4 = createSnapshot(LocalDateTime.now().minusDays(30).toInstant(ZoneOffset.UTC).toEpochMilli());
     snapshotDao.insert(dbSession, snapshot4);
-    underTest.insert(dbSession, snapshot4.getComponentUuid(), stringToInputStream("test data"));
+    underTest.insert(dbSession, snapshot4.getRootComponentUuid(), stringToInputStream("test data"));
 
     assertThat(dbTester.countRowsOfTable("scanner_analysis_cache")).isEqualTo(4);
 
@@ -114,10 +114,10 @@ public class ScannerAnalysisCacheDaoIT {
     dbSession.commit();
 
     assertThat(dbTester.countRowsOfTable("scanner_analysis_cache")).isEqualTo(2);
-    assertThat(underTest.selectData(dbSession, snapshot1.getComponentUuid())).isNotNull();
-    assertThat(underTest.selectData(dbSession, snapshot2.getComponentUuid())).isNotNull();
-    assertThat(underTest.selectData(dbSession, snapshot3.getComponentUuid())).isNull();
-    assertThat(underTest.selectData(dbSession, snapshot4.getComponentUuid())).isNull();
+    assertThat(underTest.selectData(dbSession, snapshot1.getRootComponentUuid())).isNotNull();
+    assertThat(underTest.selectData(dbSession, snapshot2.getRootComponentUuid())).isNotNull();
+    assertThat(underTest.selectData(dbSession, snapshot3.getRootComponentUuid())).isNull();
+    assertThat(underTest.selectData(dbSession, snapshot4.getRootComponentUuid())).isNull();
   }
 
   private static String dataStreamToString(DbInputStream dbInputStream) throws IOException {
@@ -133,7 +133,7 @@ public class ScannerAnalysisCacheDaoIT {
   private static SnapshotDto createSnapshot(long buildtime) {
     return new SnapshotDto()
       .setUuid(uuidFactory.create())
-      .setComponentUuid(uuidFactory.create())
+      .setRootComponentUuid(uuidFactory.create())
       .setStatus("P")
       .setLast(true)
       .setProjectVersion("2.1-SNAPSHOT")
index 11e5544e4478fe19c41931911522447fbab47f13..aeff59bc395477f084c601b23dd0f39e26906327 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.db.component;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
 import java.util.Collection;
 import java.util.Collections;
@@ -76,20 +77,20 @@ public class SnapshotDao implements Dao {
     return mapper(session).selectLastAnalysisDateByProjectUuids(projectUuids);
   }
 
-  public Optional<SnapshotDto> selectLastAnalysisByRootComponentUuid(DbSession session, String componentUuid) {
-    return Optional.ofNullable(mapper(session).selectLastSnapshotByRootComponentUuid(componentUuid));
+  public Optional<SnapshotDto> selectLastAnalysisByRootComponentUuid(DbSession session, String rootComponentUuid) {
+    return Optional.ofNullable(mapper(session).selectLastSnapshotByRootComponentUuid(rootComponentUuid));
   }
 
-  public List<SnapshotDto> selectLastAnalysesByRootComponentUuids(DbSession dbSession, Collection<String> componentUuids) {
-    return executeLargeInputs(componentUuids, mapper(dbSession)::selectLastSnapshotsByRootComponentUuids);
+  public List<SnapshotDto> selectLastAnalysesByRootComponentUuids(DbSession dbSession, Collection<String> rootComponentUuids) {
+    return executeLargeInputs(rootComponentUuids, mapper(dbSession)::selectLastSnapshotsByRootComponentUuids);
   }
 
   public List<SnapshotDto> selectAnalysesByQuery(DbSession session, SnapshotQuery query) {
     return mapper(session).selectSnapshotsByQuery(query);
   }
 
-  public Optional<SnapshotDto> selectOldestAnalysis(DbSession session, String componentUuid) {
-    return mapper(session).selectOldestSnapshots(componentUuid, SnapshotDto.STATUS_PROCESSED, new RowBounds(0, 1))
+  public Optional<SnapshotDto> selectOldestAnalysis(DbSession session, String rootComponentUuid) {
+    return mapper(session).selectOldestSnapshots(rootComponentUuid, SnapshotDto.STATUS_PROCESSED, new RowBounds(0, 1))
       .stream()
       .findFirst();
   }
@@ -110,9 +111,9 @@ public class SnapshotDao implements Dao {
     return executeLargeInputs(projectUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByProjectUuidsAndFromDates(partition), i -> i / 2);
   }
 
-  public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String componentUuid, String analysisUuid) {
+  public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String rootComponentUuid, String analysisUuid) {
     SnapshotMapper mapper = mapper(dbSession);
-    mapper.unsetIsLastFlagForComponentUuid(componentUuid);
+    mapper.unsetIsLastFlagForRootComponentUuid(rootComponentUuid);
     mapper(dbSession).setIsLastFlagForAnalysisUuid(analysisUuid);
   }
 
@@ -121,12 +122,14 @@ public class SnapshotDao implements Dao {
     return item;
   }
 
+  @VisibleForTesting
   public void insert(DbSession session, Collection<SnapshotDto> items) {
     for (SnapshotDto item : items) {
       insert(session, item);
     }
   }
 
+  @VisibleForTesting
   public void insert(DbSession session, SnapshotDto item, SnapshotDto... others) {
     insert(session, Lists.asList(item, others));
   }
@@ -139,8 +142,8 @@ public class SnapshotDao implements Dao {
    * Used by Governance
    */
   @CheckForNull
-  public ViewsSnapshotDto selectSnapshotBefore(String componentUuid, long date, DbSession dbSession) {
-    return mapper(dbSession).selectSnapshotBefore(componentUuid, date).stream().findFirst().orElse(null);
+  public ViewsSnapshotDto selectSnapshotBefore(String rootComponentUuid, long date, DbSession dbSession) {
+    return mapper(dbSession).selectSnapshotBefore(rootComponentUuid, date).stream().findFirst().orElse(null);
   }
 
   private static SnapshotMapper mapper(DbSession session) {
index 9ff6e73c809d253350b8fb9090f1dcc2d27ddc06..b0f2b37e28b0f5a4585d00b7e6227b5bcd9ccb42 100644 (file)
@@ -38,7 +38,7 @@ public final class SnapshotDto {
   public static final int MAX_BUILD_STRING_LENGTH = 100;
 
   private String uuid;
-  private String componentUuid;
+  private String rootComponentUuid;
   private Long createdAt;
   private Long buildDate;
   private String status = STATUS_UNPROCESSED;
@@ -74,12 +74,12 @@ public final class SnapshotDto {
     return this;
   }
 
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getRootComponentUuid() {
+    return rootComponentUuid;
   }
 
-  public SnapshotDto setComponentUuid(String componentUuid) {
-    this.componentUuid = componentUuid;
+  public SnapshotDto setRootComponentUuid(String rootComponentUuid) {
+    this.rootComponentUuid = rootComponentUuid;
     return this;
   }
 
@@ -207,7 +207,7 @@ public final class SnapshotDto {
     }
     SnapshotDto that = (SnapshotDto) o;
     return Objects.equals(uuid, that.uuid) &&
-      Objects.equals(componentUuid, that.componentUuid) &&
+      Objects.equals(rootComponentUuid, that.rootComponentUuid) &&
       Objects.equals(createdAt, that.createdAt) &&
       Objects.equals(buildDate, that.buildDate) &&
       Objects.equals(status, that.status) &&
@@ -221,14 +221,14 @@ public final class SnapshotDto {
 
   @Override
   public int hashCode() {
-    return Objects.hash(uuid, componentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate);
+    return Objects.hash(uuid, rootComponentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate);
   }
 
   @Override
   public String toString() {
     return "SnapshotDto{" +
       "uuid='" + uuid + '\'' +
-      ", componentUuid='" + componentUuid + '\'' +
+      ", componentUuid='" + rootComponentUuid + '\'' +
       ", createdAt=" + createdAt +
       ", buildDate=" + buildDate +
       ", status='" + status + '\'' +
index 05186d5f7cfc96d6b9cb3c92f01539bfa0ada80e..7a9e64c2c57fa58b54751bd2e684dd699a8fd1d4 100644 (file)
@@ -36,17 +36,17 @@ public interface SnapshotMapper {
   SnapshotDto selectLastSnapshotByComponentUuid(@Param("componentUuid") String componentUuid);
 
   @CheckForNull
-  SnapshotDto selectLastSnapshotByRootComponentUuid(@Param("componentUuid") String componentUuid);
+  SnapshotDto selectLastSnapshotByRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);
 
-  List<SnapshotDto> selectLastSnapshotsByRootComponentUuids(@Param("componentUuids") Collection<String> componentUuids);
+  List<SnapshotDto> selectLastSnapshotsByRootComponentUuids(@Param("rootComponentUuids") Collection<String> rootComponentUuids);
 
   List<SnapshotDto> selectSnapshotsByQuery(@Param("query") SnapshotQuery query);
 
-  List<SnapshotDto> selectOldestSnapshots(@Param("componentUuid") String componentUuid, @Param("status") String status, RowBounds rowBounds);
+  List<SnapshotDto> selectOldestSnapshots(@Param("rootComponentUuid") String rootComponentUuid, @Param("status") String status, RowBounds rowBounds);
 
-  List<ViewsSnapshotDto> selectSnapshotBefore(@Param("componentUuid") String componentUuid, @Param("date") long date);
+  List<ViewsSnapshotDto> selectSnapshotBefore(@Param("rootComponentUuid") String rootComponentUuid, @Param("date") long date);
 
-  void unsetIsLastFlagForComponentUuid(@Param("componentUuid") String componentUuid);
+  void unsetIsLastFlagForRootComponentUuid(@Param("rootComponentUuid") String rootComponentUuid);
 
   void setIsLastFlagForAnalysisUuid(@Param("analysisUuid") String analysisUuid);
 
index 7d7f443a1fcfe6ab48cbe785bd6b07a252ab547b..08a9f53659b8b29610b20aa71f898fce8efcbdfd 100644 (file)
@@ -43,7 +43,7 @@ public final class SnapshotQuery {
     }
   }
 
-  private String componentUuid;
+  private String rootComponentUuid;
   private Long createdAfter;
   private Long createdBefore;
   private List<String> statuses;
@@ -89,12 +89,12 @@ public final class SnapshotQuery {
   }
 
   @CheckForNull
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getRootComponentUuid() {
+    return rootComponentUuid;
   }
 
-  public SnapshotQuery setComponentUuid(@Nullable String componentUuid) {
-    this.componentUuid = componentUuid;
+  public SnapshotQuery setRootComponentUuid(@Nullable String rootComponentUuid) {
+    this.rootComponentUuid = rootComponentUuid;
     return this;
   }
 
index 5cc3ea168a53f0f232a0974888cc0b083c56bbb2..8997ce77028e09531bb9aea7c208c46ed61b02f4 100644 (file)
@@ -72,13 +72,11 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
     CoreMetrics.NEW_LINES_KEY,
     CoreMetrics.NEW_RELIABILITY_RATING_KEY);
 
-  private static final String SQL_PROJECTS = """
-    SELECT p.uuid, p.kee, p.name, s.created_at, p.tags, p.qualifier
-    FROM projects p
-    INNER JOIN project_branches pb on p.uuid = pb.project_uuid
-    LEFT OUTER JOIN snapshots s ON s.component_uuid=pb.uuid AND s.islast=?
-    WHERE pb.is_main = ?
-    AND p.qualifier in (?, ?)""";
+  private static final String SQL_PROJECTS = "SELECT p.uuid, p.kee, p.name, s.created_at, p.tags, p.qualifier " +
+    "FROM projects p " +
+    "INNER JOIN project_branches pb ON pb.project_uuid = p.uuid AND pb.is_main = ? " +
+    "LEFT OUTER JOIN snapshots s ON s.root_component_uuid=pb.uuid AND s.islast=? " +
+    "WHERE p.qualifier in (?, ?)";
 
   private static final String PROJECT_FILTER = " AND pb.project_uuid=?";
 
index e323c6bdeaeadac56abaa1e34664e80043ac1c4d..b356165dcd141356e761b98153b7a114de07beb5 100644 (file)
@@ -35,7 +35,7 @@
     select
       cp.uuid as "projectUuid", ap.text_value as "propertyValue"
     from components cp
-    inner join snapshots s on s.component_uuid = cp.uuid
+    inner join snapshots s on s.root_component_uuid = cp.uuid
     inner join analysis_properties ap on ap.analysis_uuid = s.uuid
     inner join project_branches pb on pb.uuid = cp.branch_uuid
     where
index 409ac4a2103281b36c72e22e2bc23c54f4832ca9..b9dd92bcd4bfeac3a2b17f2315cacce5a9a9fc81 100644 (file)
   <sql id="sqlSelectByQuery">
     from components p
     <if test="query.analyzedBefore!=null">
-      inner join snapshots sa on sa.component_uuid=p.uuid
+      inner join snapshots sa on sa.root_component_uuid=p.uuid
         and sa.status='P' and sa.islast=${_true} and sa.created_at &lt; #{query.analyzedBefore,jdbcType=BIGINT}
     </if>
     left join project_branches pb on pb.uuid = p.branch_uuid
         </if>
       </if>
       <if test="query.isOnProvisionedOnly()">
-        and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid)
+        and not exists(select 1 from snapshots sp where sp.root_component_uuid=p.uuid)
         and not exists(
           select 1 from snapshots sp
-          inner join project_branches pb2 on sp.component_uuid = pb2.uuid
+          inner join project_branches pb2 on sp.root_component_uuid = pb2.uuid
           where pb2.project_uuid = pb.project_uuid
         )
       </if>
           exists(
             -- branches of projects and applications
             select 1 from snapshots s
-            inner join project_branches pb2 on s.component_uuid = pb2.uuid
+            inner join project_branches pb2 on s.root_component_uuid = pb2.uuid
             where pb2.project_uuid = pb.project_uuid
             and s.status='P'
             and s.islast = ${_true}
           or exists (
             -- portfolios
             select 1 from snapshots s
-            where s.component_uuid = p.uuid
+            where s.root_component_uuid = p.uuid
             and s.status='P'
             and s.islast = ${_true}
             and s.created_at &gt;= #{query.anyBranchAnalyzedAfter,jdbcType=BIGINT}
           exists(
           -- branches of projects and applications
           select 1 from snapshots s
-          inner join project_branches pb2 on s.component_uuid = pb2.uuid
+          inner join project_branches pb2 on s.root_component_uuid = pb2.uuid
           where pb2.project_uuid = pb.project_uuid
           and s.status='P'
           and s.islast = ${_true}
           or exists (
           -- portfolios
           select 1 from snapshots s
-          where s.component_uuid = p.uuid
+          where s.root_component_uuid = p.uuid
           and s.status='P'
           and s.islast = ${_true}
           and s.created_at &lt; #{query.anyBranchAnalyzedBefore,jdbcType=BIGINT}
         and
         (
             (select max(s.created_at) from snapshots s
-            inner join project_branches pb2 on s.component_uuid = pb2.uuid
+            inner join project_branches pb2 on s.root_component_uuid = pb2.uuid
             where pb2.project_uuid = pb.project_uuid
             and s.status='P'
             and s.islast = ${_true}
             exists (
             -- portfolios
             select 1 from snapshots s
-            where s.component_uuid = p.uuid
+            where s.root_component_uuid = p.uuid
             and p.qualifier = 'VW'
             and s.status='P'
             and s.islast = ${_true}
index 746a1efd27fe0809f18e08a0bf79cce9570a1a38..1d5fcc6abbd55d9d7a328fa2d845120c46c935d1 100644 (file)
@@ -4,7 +4,7 @@
 
   <sql id="snapshotColumns">
     s.uuid as uuid,
-    s.component_uuid as componentUuid,
+    s.root_component_uuid as rootComponentUuid,
     s.created_at as createdAt,
     s.build_date as buildDate,
     s.status as status,
@@ -38,7 +38,7 @@
   <select id="selectLastSnapshotByComponentUuid" resultType="Snapshot">
     select <include refid="snapshotColumns" />
     from snapshots s
-    inner join components p on s.component_uuid = p.branch_uuid
+    inner join components p on s.root_component_uuid = p.branch_uuid
     where
       s.islast=${_true}
       and p.uuid = #{componentUuid,jdbcType=VARCHAR}
@@ -47,7 +47,7 @@
   <select id="selectLastAnalysisDateByProject" resultType="long">
     select max(s.created_at)
     from snapshots s
-    inner join components p on s.component_uuid = p.branch_uuid
+    inner join components p on s.root_component_uuid = p.branch_uuid
     left join project_branches pb on pb.uuid = p.branch_uuid
     where
       s.islast=${_true}
@@ -65,7 +65,7 @@
         s.created_at as last_analysis_date
       from
         snapshots s
-      inner join components c on s.component_uuid = c.branch_uuid
+      inner join components c on s.root_component_uuid = c.branch_uuid
       left join project_branches pb on pb.uuid = c.branch_uuid
       where
         s.islast = ${_true}
@@ -89,7 +89,7 @@
   <select id="selectLastSnapshotByRootComponentUuid" resultType="Snapshot">
     select <include refid="snapshotColumns" />
     from snapshots s
-    where s.islast=${_true} and s.component_uuid = #{componentUuid,jdbcType=VARCHAR}
+    where s.islast=${_true} and s.root_component_uuid = #{rootComponentUuid,jdbcType=VARCHAR}
   </select>
 
   <select id="selectLastSnapshotsByRootComponentUuids" resultType="Snapshot">
@@ -97,9 +97,9 @@
     from snapshots s
     where
       s.islast=${_true}
-      and s.component_uuid in
-      <foreach collection="componentUuids" item="componentUuid" separator="," open="(" close=")">
-        #{componentUuid,jdbcType=VARCHAR}
+      and s.root_component_uuid in
+      <foreach collection="rootComponentUuids" item="rootComponentUuid" separator="," open="(" close=")">
+        #{rootComponentUuid,jdbcType=VARCHAR}
       </foreach>
   </select>
 
     SELECT
     <include refid="snapshotColumns" />
     FROM snapshots s
-    <if test="query.componentUuid != null">
-      INNER JOIN components p ON p.uuid=s.component_uuid AND p.enabled=${_true} AND s.component_uuid=#{query.componentUuid,jdbcType=VARCHAR}
+    <if test="query.rootComponentUuid != null">
+      INNER JOIN components p ON p.uuid=s.root_component_uuid AND p.enabled=${_true} AND s.root_component_uuid=#{query.rootComponentUuid,jdbcType=VARCHAR}
     </if>
     <where>
       <if test="query.status != null">
     select
     <include refid="snapshotColumns" />
     from snapshots s
-      inner join components p on p.uuid=s.component_uuid and p.enabled=${_true}
+      inner join components p on p.uuid=s.root_component_uuid and p.enabled=${_true}
       inner join project_branches pb on pb.uuid=p.uuid
     where
       <foreach collection="projectUuidFromDatePairs" open="(" close=")" item="projectUuidFromDatePair" separator=" or ">
     <include refid="snapshotColumns" />
     FROM snapshots s
     <where>
-      and s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
+      and s.root_component_uuid=#{rootComponentUuid,jdbcType=VARCHAR}
       and s.status = #{status,jdbcType=VARCHAR}
     </where>
     ORDER BY s.created_at ASC
     <include refid="viewsSnapshotColumns" />
     FROM snapshots s
     <where>
-      and s.component_uuid = #{componentUuid,jdbcType=VARCHAR}
+      and s.root_component_uuid = #{rootComponentUuid,jdbcType=VARCHAR}
       and s.status = 'P'
       and s.created_at &lt; #{date,jdbcType=BIGINT}
     </where>
     order by created_at desc
   </select>
 
-  <update id="unsetIsLastFlagForComponentUuid" parameterType="map">
+  <update id="unsetIsLastFlagForRootComponentUuid" parameterType="map">
     update snapshots
     set islast = ${_false}
-    where component_uuid = #{componentUuid,jdbcType=VARCHAR}
+    where root_component_uuid = #{rootComponentUuid,jdbcType=VARCHAR}
     and islast = ${_true}
   </update>
 
   <insert id="insert" parameterType="Snapshot" useGeneratedKeys="false">
     insert into snapshots (
       uuid,
-      component_uuid,
+      root_component_uuid,
       created_at,
       build_date,
       status,
     )
     values (
       #{uuid, jdbcType=VARCHAR},
-      #{componentUuid, jdbcType=VARCHAR},
+      #{rootComponentUuid, jdbcType=VARCHAR},
       #{createdAt, jdbcType=BIGINT},
       #{buildDate, jdbcType=BIGINT},
       #{status, jdbcType=VARCHAR},
index 9463f0c9e2c890c1db2fe22daffa110633bd837d..c367b2a7d0751b8fc26bd3ba88a6c486abb9b7e7 100644 (file)
@@ -57,7 +57,7 @@
     inner join snapshots s on
       s.uuid = e.analysis_uuid
       and s.status = 'P'
-      and s.component_uuid = #{componentUuid,jdbcType=VARCHAR}
+      and s.root_component_uuid = #{componentUuid,jdbcType=VARCHAR}
     where
       e.category = 'Version'
     order by
index 02bf75033f8385c68b321c661ec474624b74b3d3..79987cf193a3bc27ad76d00809f40ff9afd475a3 100644 (file)
@@ -9,7 +9,7 @@
     from
       snapshots s
     where
-      s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
+      s.root_component_uuid=#{componentUuid,jdbcType=VARCHAR}
       <if test="islast != null">
         and s.islast=#{islast}
       </if>
@@ -32,7 +32,7 @@
     from snapshots s
       left outer join events ve on ve.analysis_uuid=s.uuid
     where
-      s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
+      s.root_component_uuid=#{componentUuid,jdbcType=VARCHAR}
       and s.status='P'
   </select>
 
@@ -53,7 +53,7 @@
       project_branches pb
     left join snapshots s
     on
-        s.component_uuid = pb.uuid
+        s.root_component_uuid = pb.uuid
         and s.islast=${_true}
     where
         pb.project_uuid=#{projectUuid,jdbcType=VARCHAR}
index bdec0304244d2c89807cfc790d2ac4f710980749..2b641ed9b41a77ad513bbcd318bda40f0dcd8177 100644 (file)
@@ -16,7 +16,7 @@
     where branch_uuid in (
       select sac.branch_uuid from scanner_analysis_cache sac
       left outer join snapshots s on
-        sac.branch_uuid = s.component_uuid
+        sac.branch_uuid = s.root_component_uuid
       where
         s.build_date &lt; #{timestamp,jdbcType=BIGINT} and s.islast=${_true}
         or s.islast is null
index 7188c4d8c2efe8a9aac80c4f51845045c2e9a471..4d9d6560ed1bb1760f8e6a17f139d646f11ea809 100644 (file)
@@ -963,7 +963,7 @@ CREATE INDEX "SESSION_TOKENS_USER_UUID" ON "SESSION_TOKENS"("USER_UUID" NULLS FI
 
 CREATE TABLE "SNAPSHOTS"(
     "UUID" CHARACTER VARYING(50) NOT NULL,
-    "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+    "ROOT_COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
     "STATUS" CHARACTER VARYING(4) DEFAULT 'U' NOT NULL,
     "ISLAST" BOOLEAN DEFAULT FALSE NOT NULL,
     "VERSION" CHARACTER VARYING(500),
@@ -977,7 +977,7 @@ CREATE TABLE "SNAPSHOTS"(
     "CREATED_AT" BIGINT
 );
 ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID");
-CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "SNAPSHOTS_ROOT_COMPONENT_UUID" ON "SNAPSHOTS"("ROOT_COMPONENT_UUID" NULLS FIRST);
 
 CREATE TABLE "USER_DISMISSED_MESSAGES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
index cf8638c4da6d4d14f4bced5368a81b7df43c23fe..b9d2aaec441598fa76162d611a5c752902ca564d 100644 (file)
@@ -33,7 +33,7 @@ public class SnapshotDtoTest {
   public void test_getter_and_setter() {
     SnapshotDto snapshotDto = new SnapshotDto()
       .setBuildDate(parseDate("2014-07-02").getTime())
-      .setComponentUuid("uuid_21")
+      .setRootComponentUuid("uuid_21")
       .setLast(true)
       .setProjectVersion("1.0")
       .setBuildString("1.0.1.123")
@@ -42,7 +42,7 @@ public class SnapshotDtoTest {
       .setPeriodDate(parseDate("2014-06-01").getTime());
 
     assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime());
-    assertThat(snapshotDto.getComponentUuid()).isEqualTo("uuid_21");
+    assertThat(snapshotDto.getRootComponentUuid()).isEqualTo("uuid_21");
     assertThat(snapshotDto.getLast()).isTrue();
     assertThat(snapshotDto.getProjectVersion()).isEqualTo("1.0");
     assertThat(snapshotDto.getBuildString()).isEqualTo("1.0.1.123");
index 238a5c962a042439fbc600e2daf509c3ac77544e..949402ea5ab39b9ca928ff86afdf636a64c6f427 100644 (file)
@@ -31,7 +31,7 @@ public class SnapshotQueryTest {
   @Test
   public void test_setters_and_getters() {
     SnapshotQuery query = new SnapshotQuery()
-      .setComponentUuid("abcd")
+      .setRootComponentUuid("abcd")
       .setIsLast(true)
       .setStatus("P")
       .setProjectVersion("1.0")
@@ -39,7 +39,7 @@ public class SnapshotQueryTest {
       .setCreatedBefore(20L)
       .setSort(BY_DATE, ASC);
 
-    assertThat(query.getComponentUuid()).isEqualTo("abcd");
+    assertThat(query.getRootComponentUuid()).isEqualTo("abcd");
     assertThat(query.getIsLast()).isTrue();
     assertThat(query.getStatus()).isEqualTo(List.of("P"));
     assertThat(query.getProjectVersion()).isEqualTo("1.0");
index 0cf40972cf5954087081cfa5a89eb6ae8977102c..7deed40f20fb61f11a0ba1260db3892f1b0ab7fc 100644 (file)
@@ -44,7 +44,7 @@ public class SnapshotTesting {
   public static SnapshotDto newAnalysis(String uuid) {
     return new SnapshotDto()
       .setUuid(randomAlphanumeric(40))
-      .setComponentUuid(uuid)
+      .setRootComponentUuid(uuid)
       .setStatus(SnapshotDto.STATUS_PROCESSED)
       .setCreatedAt(System.currentTimeMillis())
       .setBuildDate(System.currentTimeMillis())
@@ -55,7 +55,7 @@ public class SnapshotTesting {
   public static SnapshotDto newSnapshot() {
     return new SnapshotDto()
       .setUuid(randomAlphanumeric(40))
-      .setComponentUuid(randomAlphanumeric(40))
+      .setRootComponentUuid(randomAlphanumeric(40))
       .setStatus(randomAscii(1))
       .setCreatedAt(System.currentTimeMillis())
       .setBuildDate(System.currentTimeMillis())
index 432c4973c697e67b156741949f6cfb3e96da80d6..db6cf355d7fcfaa8d0224d28c927456cdc9b5ae8 100644 (file)
@@ -67,7 +67,7 @@ public class EventDbTester {
       .setComponentKey(component.getKey())
       .setComponentName(component.name())
       .setComponentBranchKey(Optional.ofNullable(branch).map(BranchDto::getKey).orElse(null));
-    EventPurgeData eventPurgeData = new EventPurgeData(analysis.getComponentUuid(), analysis.getUuid());
+    EventPurgeData eventPurgeData = new EventPurgeData(analysis.getRootComponentUuid(), analysis.getUuid());
     
     dbClient.eventComponentChangeDao().insert(dbSession, eventComponentChange, eventPurgeData);
     db.commit();
index da46af1938bcee5607382df9ffd7f0104670b020..abff31ec0b7660212360a047096559f712cec952 100644 (file)
@@ -28,11 +28,11 @@ public class EventTesting {
 
   public static EventDto newEvent(SnapshotDto analysis) {
     requireNonNull(analysis.getUuid());
-    requireNonNull(analysis.getComponentUuid());
+    requireNonNull(analysis.getRootComponentUuid());
 
     return new EventDto()
       .setAnalysisUuid(analysis.getUuid())
-      .setComponentUuid(analysis.getComponentUuid())
+      .setComponentUuid(analysis.getRootComponentUuid())
       .setUuid(randomAlphanumeric(40))
       .setName(randomAlphanumeric(400))
       .setDescription(null)
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshots.java
new file mode 100644 (file)
index 0000000..38c67b9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
+
+public class CreateIndexRootComponentUuidInSnapshots extends CreateIndexOnColumn {
+
+  private static final String TABLE_NAME = "snapshots";
+  private static final String COLUMN_NAME = "root_component_uuid";
+
+  public CreateIndexRootComponentUuidInSnapshots(Database db) {
+    super(db, TABLE_NAME, COLUMN_NAME, false);
+  }
+}
index 95d4e5aab62effceb604dd6b73579856ebe7d8e3..39ccad83e792cdc18c403f791c8bdeeaa0dbcd4e 100644 (file)
@@ -67,7 +67,9 @@ public class DbVersion102 implements DbVersion {
       .add(10_2_016, "Rename 'component_uuid' in 'webhook_deliveries' table to 'project_uuid'", RenameComponentUuidInWebhookDeliveries.class)
       .add(10_2_017, "Create index 'webhook_deliveries_project_uuid' in 'webhook_deliveries' table", CreateIndexProjectUuidInWebhookDeliveries.class)
 
+      .add(10_2_018, "Drop index 'component_uuid' in 'snapshots' table", DropIndexComponentUuidInSnapshots.class)
+      .add(10_2_019, "Rename 'component_uuid' in 'snapshots' table to 'root_component_uuid'", RenameComponentUuidInSnapshots.class)
+      .add(10_2_020, "Create index 'snapshots_root_component_uuid' in 'snapshots' table", CreateIndexRootComponentUuidInSnapshots.class)
     ;
   }
-
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshots.java
new file mode 100644 (file)
index 0000000..5646f83
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+public class DropIndexComponentUuidInSnapshots extends DropIndexChange {
+
+  private static final String TABLE_NAME = "snapshots";
+  private static final String INDEX_NAME = "snapshot_component";
+
+  public DropIndexComponentUuidInSnapshots(Database db) {
+    super(db, INDEX_NAME, TABLE_NAME);
+  }
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshots.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshots.java
new file mode 100644 (file)
index 0000000..8d14ffc
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameComponentUuidInSnapshots extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "snapshots";
+  private static final String OLD_COLUMN_NAME = "component_uuid";
+  private static final String NEW_COLUMN_NAME = "root_component_uuid";
+
+  public RenameComponentUuidInSnapshots(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+
+}
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest.java
new file mode 100644 (file)
index 0000000..18df8a9
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateIndexRootComponentUuidInSnapshotsTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexRootComponentUuidInSnapshotsTest.class, "schema.sql");
+
+  private final CreateIndexRootComponentUuidInSnapshots createIndex = new CreateIndexRootComponentUuidInSnapshots(db.database());
+
+  @Test
+  public void migration_should_create_index() throws SQLException {
+    db.assertIndexDoesNotExist("snapshots", "snapshots_root_component_uuid");
+
+    createIndex.execute();
+
+    db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid");
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    createIndex.execute();
+    createIndex.execute();
+
+    db.assertIndex("snapshots", "snapshots_root_component_uuid", "root_component_uuid");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest.java
new file mode 100644 (file)
index 0000000..7329d5c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropIndexComponentUuidInSnapshotsTest {
+
+  private static final String TABLE_NAME = "snapshots";
+  private static final String COLUMN_NAME = "component_uuid";
+  private static final String INDEX_NAME = "snapshot_component";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInSnapshotsTest.class, "schema.sql");
+
+  private final DropIndexComponentUuidInSnapshots underTest = new DropIndexComponentUuidInSnapshots(db.database());
+
+  @Test
+  public void index_is_dropped() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+    underTest.execute();
+
+    db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+    underTest.execute();
+    underTest.execute();
+
+    db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest.java
new file mode 100644 (file)
index 0000000..cea6152
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameComponentUuidInSnapshotsTest {
+  public static final String TABLE_NAME = "snapshots";
+  public static final String NEW_COLUMN_NAME = "root_component_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(RenameComponentUuidInSnapshotsTest.class, "schema.sql");
+
+  private final RenameComponentUuidInSnapshots underTest = new RenameComponentUuidInSnapshots(db.database());
+
+  @Test
+  public void columnIsRenamed() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 50, false);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/CreateIndexRootComponentUuidInSnapshotsTest/schema.sql
new file mode 100644 (file)
index 0000000..b9ca753
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "SNAPSHOTS"(
+    "UUID" CHARACTER VARYING(50) NOT NULL,
+    "ROOT_COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+    "STATUS" CHARACTER VARYING(4) DEFAULT 'U' NOT NULL,
+    "ISLAST" BOOLEAN DEFAULT FALSE NOT NULL,
+    "VERSION" CHARACTER VARYING(500),
+    "PURGE_STATUS" INTEGER,
+    "BUILD_STRING" CHARACTER VARYING(100),
+    "REVISION" CHARACTER VARYING(100),
+    "BUILD_DATE" BIGINT,
+    "PERIOD1_MODE" CHARACTER VARYING(100),
+    "PERIOD1_PARAM" CHARACTER VARYING(100),
+    "PERIOD1_DATE" BIGINT,
+    "CREATED_AT" BIGINT
+);
+ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID");
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInSnapshotsTest/schema.sql
new file mode 100644 (file)
index 0000000..404ebcd
--- /dev/null
@@ -0,0 +1,17 @@
+CREATE TABLE "SNAPSHOTS"(
+    "UUID" CHARACTER VARYING(50) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+    "STATUS" CHARACTER VARYING(4) DEFAULT 'U' NOT NULL,
+    "ISLAST" BOOLEAN DEFAULT FALSE NOT NULL,
+    "VERSION" CHARACTER VARYING(500),
+    "PURGE_STATUS" INTEGER,
+    "BUILD_STRING" CHARACTER VARYING(100),
+    "REVISION" CHARACTER VARYING(100),
+    "BUILD_DATE" BIGINT,
+    "PERIOD1_MODE" CHARACTER VARYING(100),
+    "PERIOD1_PARAM" CHARACTER VARYING(100),
+    "PERIOD1_DATE" BIGINT,
+    "CREATED_AT" BIGINT
+);
+ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID");
+CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS"("COMPONENT_UUID" NULLS FIRST);
\ No newline at end of file
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInSnapshotsTest/schema.sql
new file mode 100644 (file)
index 0000000..20c3bcc
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "SNAPSHOTS"(
+    "UUID" CHARACTER VARYING(50) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+    "STATUS" CHARACTER VARYING(4) DEFAULT 'U' NOT NULL,
+    "ISLAST" BOOLEAN DEFAULT FALSE NOT NULL,
+    "VERSION" CHARACTER VARYING(500),
+    "PURGE_STATUS" INTEGER,
+    "BUILD_STRING" CHARACTER VARYING(100),
+    "REVISION" CHARACTER VARYING(100),
+    "BUILD_DATE" BIGINT,
+    "PERIOD1_MODE" CHARACTER VARYING(100),
+    "PERIOD1_PARAM" CHARACTER VARYING(100),
+    "PERIOD1_DATE" BIGINT,
+    "CREATED_AT" BIGINT
+);
+ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID");
\ No newline at end of file
index 1eb7f3d64016764ea78a911f3c850b60b490021f..e39fd1d0c78d6417fd8c1711a8cee2cd73a9f0b1 100644 (file)
@@ -314,7 +314,7 @@ public class ProjectMeasuresIndexerIT {
 
   private void assertThatIndexContainsOnly(SnapshotDto... expectedProjects) {
     assertThat(es.getIds(TYPE_PROJECT_MEASURES)).containsExactlyInAnyOrder(
-      Arrays.stream(expectedProjects).map(SnapshotDto::getComponentUuid).toArray(String[]::new));
+      Arrays.stream(expectedProjects).map(SnapshotDto::getRootComponentUuid).toArray(String[]::new));
   }
 
   private void assertThatIndexContainsOnly(ComponentDto... expectedProjects) {
@@ -328,7 +328,7 @@ public class ProjectMeasuresIndexerIT {
   }
 
   private void assertThatQualifierIs(String qualifier, SnapshotDto... expectedComponents) {
-    String[] expectedComponentUuids = Arrays.stream(expectedComponents).map(SnapshotDto::getComponentUuid).toArray(String[]::new);
+    String[] expectedComponentUuids = Arrays.stream(expectedComponents).map(SnapshotDto::getRootComponentUuid).toArray(String[]::new);
     assertThatQualifierIs(qualifier, expectedComponentUuids);
   }
 
index 6d68b9c1e9b9352f5c2a04e370e7df66c92362a6..4338423164aaf9666267d7a8fd2911f7dda0b037 100644 (file)
@@ -121,7 +121,7 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing {
   private void sortProjectUuids(DbSession dbSession, List<String> projectUuids) {
     Map<String, SnapshotDto> snapshotByProjectUuid = dbClient.snapshotDao()
       .selectLastAnalysesByRootComponentUuids(dbSession, projectUuids).stream()
-      .collect(Collectors.toMap(SnapshotDto::getComponentUuid, Function.identity()));
+      .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, Function.identity()));
 
     projectUuids.sort(compareBySnapshot(snapshotByProjectUuid));
   }
index b289feebd4e7b19ac61de953ef04c66bc3f0b394..134571c861b5e154854993f2290314096bb3b0e8 100644 (file)
@@ -63,7 +63,7 @@ public class ProjectQGChangeEventListener implements QGChangeEventListener {
 
   private void addQualityGateEventToProject(QGChangeEvent qualityGateEvent, Metric.Level currentStatus) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      String componentUuid = qualityGateEvent.getAnalysis().getComponentUuid();
+      String componentUuid = qualityGateEvent.getAnalysis().getRootComponentUuid();
 
       SnapshotDto liveMeasureSnapshotDto = createLiveMeasureSnapshotDto(qualityGateEvent.getAnalysis().getProjectVersion(), componentUuid);
       dbClient.snapshotDao().insert(dbSession, liveMeasureSnapshotDto);
@@ -96,7 +96,7 @@ public class ProjectQGChangeEventListener implements QGChangeEventListener {
     dto.setProjectVersion(projectVersion);
     dto.setLast(false);
     dto.setStatus(SnapshotDto.STATUS_LIVE_MEASURE_COMPUTED);
-    dto.setComponentUuid(componentUuid);
+    dto.setRootComponentUuid(componentUuid);
 
     return dto;
   }
index ab1235f6aa3b462454cc6915ad80a06fbee7c4fa..21c097c3c3cba19d1aafa72ec836b43ec76c4360 100644 (file)
@@ -318,7 +318,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
     List<String> branchUuids = branchesWithLargestNcloc.stream().map(ProjectLocDistributionDto::branchUuid).toList();
     Map<String, Long> latestSnapshotMap = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, branchUuids)
       .stream()
-      .collect(toMap(SnapshotDto::getComponentUuid, SnapshotDto::getBuildDate));
+      .collect(toMap(SnapshotDto::getRootComponentUuid, SnapshotDto::getBuildDate));
     data.setProjects(buildProjectsList(branchesWithLargestNcloc, latestSnapshotMap));
   }
 
index 73e11b8c33ef6ad38d16948f18e319a63882cd09..fca9cbc6ae21d3bc2975bac255d1d1a9a7e4bf97 100644 (file)
@@ -337,7 +337,7 @@ public class AsyncIssueIndexingImplTest {
   private SnapshotDto insertSnapshot(String analysisUuid, String projectUuid, long createdAt) {
     SnapshotDto snapshot = new SnapshotDto()
       .setUuid(analysisUuid)
-      .setComponentUuid(projectUuid)
+      .setRootComponentUuid(projectUuid)
       .setStatus(STATUS_PROCESSED)
       .setCreatedAt(createdAt)
       .setLast(true);
index 63d5679c91ca800f5dedf52dd8b50612094e3b48..1047ca022c61ffe7036a8aa24fea9d5da9b02bcc 100644 (file)
@@ -392,13 +392,13 @@ public class IssueQueryFactory {
     Set<String> newCodeReferenceByProjects = snapshots
       .stream()
       .filter(s -> isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, s))
-      .map(SnapshotDto::getComponentUuid)
+      .map(SnapshotDto::getRootComponentUuid)
       .collect(toSet());
 
     Map<String, PeriodStart> leakByProjects = snapshots
       .stream()
       .filter(s -> s.getPeriodDate() != null && !isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, s))
-      .collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> new PeriodStart(longToDate(s.getPeriodDate()), false)));
+      .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> new PeriodStart(longToDate(s.getPeriodDate()), false)));
 
     builder.createdAfterByProjectUuids(leakByProjects);
     builder.newCodeOnReferenceByProjectUuids(newCodeReferenceByProjects);
@@ -406,7 +406,7 @@ public class IssueQueryFactory {
 
   private boolean isLastAnalysisFromReAnalyzedReferenceBranch(DbSession dbSession, SnapshotDto snapshot) {
     return isLastAnalysisUsingReferenceBranch(snapshot) &&
-      isLastAnalysisFromSonarQube94Onwards(dbSession, snapshot.getComponentUuid());
+      isLastAnalysisFromSonarQube94Onwards(dbSession, snapshot.getRootComponentUuid());
   }
 
   private static void addDirectories(IssueQuery.Builder builder, List<ComponentDto> directories) {
index 2dafb7161cd52b90770e4e192fcda35b1874bcd9..f71fbdf96ce5364254053a105145775cb26a14b0 100644 (file)
@@ -106,14 +106,14 @@ public class CreateEventActionIT {
 
     CreateEventResponse result = call(VERSION.name(), "5.6.3", analysis.getUuid());
 
-    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getComponentUuid());
+    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getRootComponentUuid());
     assertThat(dbEvents).hasSize(1);
     EventDto dbEvent = dbEvents.get(0);
     assertThat(dbEvent.getName()).isEqualTo("5.6.3");
     assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel());
     assertThat(dbEvent.getDescription()).isNull();
     assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid());
-    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid());
+    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getRootComponentUuid());
     assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey());
     assertThat(dbEvent.getCreatedAt()).isEqualTo(123_456_789L);
     assertThat(dbEvent.getDate()).isEqualTo(analysis.getCreatedAt());
@@ -130,14 +130,14 @@ public class CreateEventActionIT {
 
     CreateEventResponse result = call(VERSION.name(), "5.6.3", analysis.getUuid());
 
-    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getComponentUuid());
+    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getRootComponentUuid());
     assertThat(dbEvents).hasSize(1);
     EventDto dbEvent = dbEvents.get(0);
     assertThat(dbEvent.getName()).isEqualTo("5.6.3");
     assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel());
     assertThat(dbEvent.getDescription()).isNull();
     assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid());
-    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid());
+    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getRootComponentUuid());
     assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey());
     assertThat(dbEvent.getCreatedAt()).isEqualTo(123_456_789L);
     assertThat(dbEvent.getDate()).isEqualTo(analysis.getCreatedAt());
index 1f6edb4d2f7bafb2793a359d066a8d58bcd535b8..e49658c97cff8c9dfe87891be0e64f23bee77044 100644 (file)
@@ -425,7 +425,7 @@ public class LinesActionIT {
     dto.setUuid("uuid");
     dto.setLast(true);
     dto.setPeriodDate(date);
-    dto.setComponentUuid(componentDto.uuid());
+    dto.setRootComponentUuid(componentDto.uuid());
     snapshotDao.insert(db.getSession(), dto);
   }
 }
index d6f5216f48bd75fced68c65b1c422b01abc2042c..df525437848a635311db184cc4c3b858fbe06134 100644 (file)
@@ -97,7 +97,7 @@ public class ListAction implements BranchWsAction {
         .collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
       Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao()
         .selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream()
-        .collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
+        .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> formatDateTime(s.getCreatedAt())));
 
       ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder();
       branches.forEach(b -> addBranch(protobufResponse, b, qualityGateMeasuresByComponentUuids.get(b.getUuid()),
index be7713895db84dea51c781c6e605a87f63d082d3..828c4d17cad67db0d68a8685f136ac9c594af37a 100644 (file)
@@ -255,7 +255,7 @@ public class SearchProjectsAction implements ComponentsWsAction {
 
     List<SnapshotDto> snapshots = getSnapshots(dbSession, request, mainBranchByUuid.keySet());
     Map<String, SnapshotDto> analysisByProjectUuid = snapshots.stream()
-      .collect(Collectors.toMap(s -> mainBranchByUuid.get(s.getComponentUuid()).getProjectUuid(), s -> s));
+      .collect(Collectors.toMap(s -> mainBranchByUuid.get(s.getRootComponentUuid()).getProjectUuid(), s -> s));
     Map<String, Long> applicationsBranchLeakPeriod = getApplicationsLeakPeriod(dbSession, request, qualifiersBasedOnEdition, mainBranchByUuid.keySet());
     Map<String, Long> applicationsLeakPeriod = applicationsBranchLeakPeriod.entrySet()
       .stream()
index 598c7616760067e73139833b7f885bb0ec5b069c..78c359618a220c55152c78c7c9b8e9c73ebf2587 100644 (file)
@@ -141,7 +141,7 @@ public class SearchEventsAction implements DevelopersWsAction {
         return Stream.empty();
       }
 
-      List<String> branchUuids = analyses.stream().map(SnapshotDto::getComponentUuid).collect(toList());
+      List<String> branchUuids = analyses.stream().map(SnapshotDto::getRootComponentUuid).collect(toList());
       Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, branchUuids).stream().collect(uniqueIndex(BranchDto::getUuid));
 
       return Stream.concat(
index d60e1e294a69f344496670509fe48d268a7530ab..bda19cfa40861a7ac09633283c392bca460a91f9 100644 (file)
@@ -503,13 +503,13 @@ public class SearchAction implements HotspotsWsAction {
     Set<String> newCodeReferenceByProjects = snapshots
       .stream()
       .filter(s -> !isNullOrEmpty(s.getPeriodMode()) && s.getPeriodMode().equals(REFERENCE_BRANCH.name()))
-      .map(SnapshotDto::getComponentUuid)
+      .map(SnapshotDto::getRootComponentUuid)
       .collect(toSet());
 
     Map<String, IssueQuery.PeriodStart> leakByProjects = snapshots
       .stream()
       .filter(s -> isNullOrEmpty(s.getPeriodMode()) || !s.getPeriodMode().equals(REFERENCE_BRANCH.name()))
-      .collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> new IssueQuery.PeriodStart(longToDate(s.getPeriodDate() == null ? now : s.getPeriodDate()), false)));
+      .collect(uniqueIndex(SnapshotDto::getRootComponentUuid, s -> new IssueQuery.PeriodStart(longToDate(s.getPeriodDate() == null ? now : s.getPeriodDate()), false)));
 
     builder.createdAfterByProjectUuids(leakByProjects);
     builder.newCodeOnReferenceByProjectUuids(newCodeReferenceByProjects);
index 09bedb212df7bfc6134fa88a8f705331068216bb..c911ffdd1c4b7298e5d1b68cef217c5f32a7d533 100644 (file)
@@ -193,7 +193,7 @@ public class SearchHistoryAction implements MeasuresWsAction {
 
   private List<SnapshotDto> searchAnalyses(DbSession dbSession, SearchHistoryRequest request, ComponentDto component) {
     SnapshotQuery dbQuery = new SnapshotQuery()
-      .setComponentUuid(component.branchUuid())
+      .setRootComponentUuid(component.branchUuid())
       .setStatus(STATUS_PROCESSED)
       .setSort(SORT_FIELD.BY_DATE, SORT_ORDER.ASC);
     ofNullable(request.getFrom()).ifPresent(from -> dbQuery.setCreatedAfter(parseStartingDateOrDateTime(from).getTime()));
index 9e286981fb229045fc0d5d502daed2af839f6fa1..eb2d7f2eb41d1251e1661155fe7cc8605fe31680 100644 (file)
@@ -272,7 +272,7 @@ public class SetAction implements NewCodePeriodsWsAction {
   }
 
   private void checkAnalysis(DbSession dbSession, ProjectDto project, BranchDto branch, SnapshotDto analysis) {
-    BranchDto analysisBranch = dbClient.branchDao().selectByUuid(dbSession, analysis.getComponentUuid()).orElse(null);
+    BranchDto analysisBranch = dbClient.branchDao().selectByUuid(dbSession, analysis.getRootComponentUuid()).orElse(null);
     boolean analysisMatchesProjectBranch = analysisBranch != null && analysisBranch.getUuid().equals(branch.getUuid());
 
     checkArgument(analysisMatchesProjectBranch,
index b919b3ae41d49bbc278dfbba2fa8ba99910262bc..06bd4e41cf493c3faf44bab6d87e482a4fcd5c33 100644 (file)
@@ -163,7 +163,7 @@ public class SearchAction implements ProjectsWsAction {
         .collect(Collectors.toMap(ProjectLastAnalysisDateDto::getProjectUuid, ProjectLastAnalysisDateDto::getDate));
       Map<String, SnapshotDto> snapshotsByComponentUuid = dbClient.snapshotDao()
         .selectLastAnalysesByRootComponentUuids(dbSession, componentUuids).stream()
-        .collect(MoreCollectors.uniqueIndex(SnapshotDto::getComponentUuid, identity()));
+        .collect(MoreCollectors.uniqueIndex(SnapshotDto::getRootComponentUuid, identity()));
 
       return buildResponse(components, snapshotsByComponentUuid, lastAnalysisDateByComponentUuid, paging);
     }
index cc24753be4f47fd9fa7fbd11fbb512db729133cb..3cc20fc91b8a9ca303c2a6dfbd549ebb67942212 100644 (file)
@@ -50,7 +50,7 @@ class SearchMyProjectsData {
     this.projects = copyOf(builder.projects);
     this.branchUuidByProjectUuids = buildBranchUuidByProjectUuidMap(builder.branches);
     this.projectLinksByProjectUuid = buildProjectLinks(builder.projectLinks);
-    this.snapshotsByComponentUuid =builder.snapshots.stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, identity()));
+    this.snapshotsByComponentUuid =builder.snapshots.stream().collect(uniqueIndex(SnapshotDto::getRootComponentUuid, identity()));
     this.qualityGateStatuses = buildQualityGateStatuses(builder.qualityGates);
     this.totalNbOfProject = builder.totalNbOfProjects;
   }
index c2c945095ac1bf73729f4abf885ef53bc3a4cff6..7edf9a2dcf398b20d0e8c91ea6862f881d92cf1c 100644 (file)
@@ -134,7 +134,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction {
   }
 
   private ProjectDto getProjectOrApplication(DbSession dbSession, SnapshotDto analysis) {
-    return dbClient.branchDao().selectByUuid(dbSession, analysis.getComponentUuid())
+    return dbClient.branchDao().selectByUuid(dbSession, analysis.getRootComponentUuid())
       .flatMap(branch -> dbClient.projectDao().selectByUuid(dbSession, branch.getProjectUuid()))
       .orElseThrow(() -> new IllegalStateException(String.format("Project of analysis '%s' not found", analysis.getUuid())));
   }
@@ -157,7 +157,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction {
     return new EventDto()
       .setUuid(uuidFactory.create())
       .setAnalysisUuid(analysis.getUuid())
-      .setComponentUuid(analysis.getComponentUuid())
+      .setComponentUuid(analysis.getRootComponentUuid())
       .setCategory(request.getCategory().getLabel())
       .setName(request.getName())
       .setCreatedAt(system.now())
index 7617d5acb8091273f509d53d033466519244d343..daab6f70187ba4758e7f43ce3d75b056cdc6a48c 100644 (file)
@@ -73,7 +73,7 @@ public class DeleteAction implements ProjectAnalysesWsAction {
       if (STATUS_UNPROCESSED.equals(analysis.getStatus())) {
         throw analysisNotFoundException(analysisUuid);
       }
-      userSession.checkComponentUuidPermission(UserRole.ADMIN, analysis.getComponentUuid());
+      userSession.checkComponentUuidPermission(UserRole.ADMIN, analysis.getRootComponentUuid());
 
       checkArgument(!analysis.getLast(), "The last analysis '%s' cannot be deleted", analysisUuid);
       checkNotUsedInNewCodePeriod(dbSession, analysis);
index 3caa2195cb678e50b9b4aafd23669508b0e7e90f..4ab1c4a4b4b2b8ff19a24a0d5d026ccea3dd4e12 100644 (file)
@@ -170,7 +170,7 @@ public class SearchAction implements ProjectAnalysesWsAction {
 
   private void addAnalyses(SearchData.Builder data) {
     SnapshotQuery dbQuery = new SnapshotQuery()
-      .setComponentUuid(data.getProject().uuid())
+      .setRootComponentUuid(data.getProject().uuid())
       .setStatuses(data.getRequest().getStatuses())
       .setSort(BY_DATE, DESC);
     ofNullable(data.getRequest().getFrom()).ifPresent(from -> dbQuery.setCreatedAfter(parseStartingDateOrDateTime(from).getTime()));
index c8ccf14fff000573c1c2f5f16f2775bf3dd3a4f2..33bd6fd9dce3af6f2e55a5b4cf015d15095db004 100644 (file)
@@ -119,7 +119,7 @@ public class StatusAction implements ProjectDumpAction {
         " count(*), islast" +
         " from snapshots" +
         " where" +
-        " component_uuid = ?" +
+        " root_component_uuid = ?" +
         " group by" +
         " islast";
       stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, sql);
index fe7f1b43c1e907b5bb4aeffca7fa1ff8c8f0fc49..ef2496d518713b46921d3aab5f4633b3e8ea9a47 100644 (file)
@@ -191,7 +191,7 @@ public class ProjectStatusAction implements QualityGatesWsAction {
 
   private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String analysisUuid) {
     SnapshotDto snapshotDto = getSnapshot(dbSession, analysisUuid);
-    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, snapshotDto.getComponentUuid())
+    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, snapshotDto.getRootComponentUuid())
       .orElseThrow(() -> new IllegalStateException(String.format("Branch '%s' not found", snapshotDto.getUuid())));
     ProjectDto projectDto = dbClient.projectDao().selectByUuid(dbSession, branchDto.getProjectUuid())
       .orElseThrow(() -> new IllegalStateException(String.format("Project '%s' not found", branchDto.getProjectUuid())));