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();
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);
}
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");
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);
}
return new SnapshotDto()
.setUuid(uuid)
.setCreatedAt(date)
- .setComponentUuid(componentUuid)
+ .setRootComponentUuid(componentUuid)
.setProjectVersion(version)
.setBuildString(buildString)
.setLast(isLast)
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")
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));
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);
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);
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);
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();
}
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) {
.setUuid(snapshotUuid)
.setProjectVersion(projectVersion)
.setBuildString(buildString)
- .setComponentUuid(componentUuid)
+ .setRootComponentUuid(componentUuid)
.setLast(false)
.setStatus(SnapshotDto.STATUS_UNPROCESSED)
.setCreatedAt(analysisDate)
" 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";
" 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=?";
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")
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();
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");
@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
.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();
}
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())
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();
}
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());
}
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)
@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());
.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");
SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false);
db.commit();
analysis
- .setComponentUuid("P42")
+ .setRootComponentUuid("P42")
.setProjectVersion("5.6.3")
.setStatus(STATUS_UNPROCESSED);
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) {
private static SnapshotDto defaultSnapshot() {
return new SnapshotDto()
.setUuid("u1")
- .setComponentUuid("uuid_3")
+ .setRootComponentUuid("uuid_3")
.setStatus("P")
.setLast(true)
.setProjectVersion("2.1-SNAPSHOT")
.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_")
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));
}
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;
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;
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 {
}
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"));
}
}
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() {
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")
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,
.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);
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,
.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,
}
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"));
}
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);
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 {
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")
*/
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;
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();
}
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);
}
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));
}
* 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) {
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;
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;
}
}
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) &&
@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 + '\'' +
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);
}
}
- private String componentUuid;
+ private String rootComponentUuid;
private Long createdAfter;
private Long createdBefore;
private List<String> statuses;
}
@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;
}
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=?";
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
<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 < #{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 >= #{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 < #{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}
<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,
<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}
<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}
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}
<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">
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 < #{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},
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
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>
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>
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}
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 < #{timestamp,jdbcType=BIGINT} and s.islast=${_true}
or s.islast is null
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),
"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,
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")
.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");
@Test
public void test_setters_and_getters() {
SnapshotQuery query = new SnapshotQuery()
- .setComponentUuid("abcd")
+ .setRootComponentUuid("abcd")
.setIsLast(true)
.setStatus("P")
.setProjectVersion("1.0")
.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");
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())
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())
.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();
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)
--- /dev/null
+/*
+ * 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);
+ }
+}
.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)
;
}
-
}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
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) {
}
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);
}
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));
}
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);
dto.setProjectVersion(projectVersion);
dto.setLast(false);
dto.setStatus(SnapshotDto.STATUS_LIVE_MEASURE_COMPUTED);
- dto.setComponentUuid(componentUuid);
+ dto.setRootComponentUuid(componentUuid);
return dto;
}
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));
}
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);
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);
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) {
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());
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());
dto.setUuid("uuid");
dto.setLast(true);
dto.setPeriodDate(date);
- dto.setComponentUuid(componentDto.uuid());
+ dto.setRootComponentUuid(componentDto.uuid());
snapshotDao.insert(db.getSession(), dto);
}
}
.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()),
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()
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(
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);
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()));
}
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,
.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);
}
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;
}
}
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())));
}
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())
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);
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()));
" count(*), islast" +
" from snapshots" +
" where" +
- " component_uuid = ?" +
+ " root_component_uuid = ?" +
" group by" +
" islast";
stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, sql);
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())));