From a9f33af2ab0e8a72609d7304af65758c3f39bfa7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 9 Jun 2016 17:09:20 +0200 Subject: [PATCH] SONAR-7693 support removal of ID columns in SNAPSHOTS --- .../src/test/java/it/dbCleaner/PurgeTest.java | 6 +- .../sonar/server/component/ws/ShowAction.java | 4 +- .../sonar/server/component/ws/ShowData.java | 18 +++--- .../sonar/server/component/ws/TreeAction.java | 2 +- .../component/ProjectViewAttributes.java | 11 +++- .../computation/dbcleaner/ProjectCleaner.java | 8 +-- .../computation/step/IndexComponentsStep.java | 7 +-- .../computation/step/LoadPeriodsStep.java | 2 +- .../computation/step/PeriodResolver.java | 22 +++---- .../step/PersistSnapshotsStep.java | 14 ++--- .../computation/step/SwitchSnapshotStep.java | 4 +- .../computation/step/ValidateProjectStep.java | 2 +- .../sonar/server/issue/IssueQueryService.java | 2 +- .../server/measure/MeasureFilterSql.java | 8 ++- .../measure/custom/ws/SearchAction.java | 2 +- .../server/measure/ws/ComponentAction.java | 2 +- .../measure/ws/ComponentTreeDataLoader.java | 2 +- .../qualitygate/ws/ProjectStatusAction.java | 4 +- .../ui/ws/ComponentNavigationAction.java | 4 +- .../dbcleaner/ProjectCleanerTest.java | 7 ++- .../measure/MeasureToMeasureDtoTest.java | 2 +- .../step/IndexComponentsStepTest.java | 16 ++--- .../step/ReportPersistSnapshotsStepTest.java | 61 +++++++++---------- .../step/ViewsPersistComponentsStepTest.java | 2 +- .../step/ViewsPersistSnapshotsStepTest.java | 42 +++++-------- .../ui/ws/ComponentNavigationActionTest.java | 2 +- .../MeasureRepositoryImplTest/shared.xml | 6 +- .../no_previous_version.xml | 10 +-- .../previous_version_deleted.xml | 6 +- .../previous_version_is_last_one.xml | 2 +- .../step/LoadPeriodsStepTest/shared.xml | 10 +-- .../unprocessed_snapshots.xml | 2 +- .../snapshots-result.xml | 30 ++++----- .../step/SwitchSnapshotStepTest/snapshots.xml | 30 ++++----- .../load_component_id_from_db.xml | 4 +- .../load_project_id_from_db.xml | 4 +- .../should_insert_new_issues.xml | 4 +- .../should_update_issues.xml | 4 +- ...e_when_filter_by_component_name_or_key.xml | 8 +-- .../ignore_person_measures.xml | 2 +- .../ignore_quality_model_measures.xml | 2 +- .../MeasureFilterExecutorTest/shared.xml | 10 +-- .../sort_by_alert.xml | 6 +- .../BackendCleanupMediumTest/shared.xml | 2 +- .../view/index/ViewIndexerTest/index.xml | 18 +++--- .../app/controllers/api/events_controller.rb | 6 +- .../controllers/api/projects_controller.rb | 26 ++++---- .../controllers/api/resources_controller.rb | 10 +-- .../controllers/api/timemachine_controller.rb | 4 +- .../app/controllers/project_controller.rb | 10 +-- .../main/webapp/WEB-INF/app/models/event.rb | 4 +- .../WEB-INF/app/models/measure_filter.rb | 12 ++-- .../main/webapp/WEB-INF/app/models/project.rb | 8 +-- .../webapp/WEB-INF/app/models/snapshot.rb | 20 +++--- .../webapp/WEB-INF/app/models/trends_chart.rb | 6 +- .../sonar/db/component/ResourceIndexDao.java | 14 ++--- .../db/component/ResourceIndexQuery.java | 10 +-- .../sonar/db/component/ResourceMapper.java | 10 --- .../org/sonar/db/component/SnapshotDao.java | 28 ++++----- .../org/sonar/db/component/SnapshotDto.java | 31 +++++----- .../db/component/SnapshotDtoFunctions.java | 14 +---- .../sonar/db/component/SnapshotMapper.java | 22 +++---- .../org/sonar/db/component/SnapshotQuery.java | 11 ---- .../org/sonar/db/purge/PurgeCommands.java | 4 +- .../java/org/sonar/db/purge/PurgeDao.java | 19 +++--- .../java/org/sonar/db/purge/PurgeMapper.java | 8 +-- .../sonar/db/purge/PurgeSnapshotQuery.java | 20 +++--- .../db/purge/period/DefaultPeriodCleaner.java | 12 ++-- .../sonar/db/component/ComponentMapper.xml | 8 +-- .../db/component/ResourceIndexMapper.xml | 8 +-- .../org/sonar/db/component/ResourceMapper.xml | 37 +++-------- .../org/sonar/db/component/SnapshotMapper.xml | 34 +++-------- .../db/duplication/DuplicationMapper.xml | 2 +- .../org/sonar/db/measure/MeasureMapper.xml | 11 ++-- .../org/sonar/db/purge/PurgeMapper.xml | 28 ++++----- .../sonar/db/component/ComponentDbTester.java | 2 +- .../db/component/ResourceIndexDaoTest.java | 10 +-- .../sonar/db/component/SnapshotDaoTest.java | 51 ++++------------ .../sonar/db/component/SnapshotDtoTest.java | 8 +-- .../sonar/db/component/SnapshotQueryTest.java | 2 - .../sonar/db/component/SnapshotTesting.java | 16 ++--- .../org/sonar/db/measure/MeasureDaoTest.java | 24 ++------ .../org/sonar/db/purge/PurgeCommandsTest.java | 2 +- .../java/org/sonar/db/purge/PurgeDaoTest.java | 4 +- .../period/DefaultPeriodCleanerTest.java | 4 +- .../ComponentDaoTest/multi-modules.xml | 12 ++-- .../select_ghost_projects.xml | 12 ++-- .../select_provisioned_projects.xml | 10 +-- .../db/component/ComponentDaoTest/shared.xml | 10 +-- ...g-ghost-projects-and-technical-project.xml | 16 ++--- .../db/component/ResourceDaoTest/fixture.xml | 10 +-- .../shouldIndexMultiModulesProject.xml | 8 +-- .../shouldNotIndexPackages.xml | 6 +- ...shouldReIndexNewTwoLettersLongResource.xml | 2 +- .../shouldReIndexTwoLettersLongResource.xml | 2 +- .../shouldReindexProjectAfterRenaming.xml | 2 +- .../has_last_snapshot_by_component_uuid.xml | 6 +- .../SnapshotDaoTest/insert-result.xml | 2 +- .../select_previous_version_snapshots.xml | 8 +-- .../select_snapshots_by_query.xml | 12 ++-- .../db/component/SnapshotDaoTest/shared.xml | 2 +- .../component/SnapshotDaoTest/snapshots.xml | 12 ++-- .../duplication/DuplicationDaoTest/insert.xml | 6 +- .../DuplicationDaoTest/select_candidates.xml | 34 +++++------ .../sonar/db/issue/IssueDaoTest/shared.xml | 8 +-- .../measure/MeasureDaoTest/past_measures.xml | 6 +- .../past_measures_with_person_id.xml | 2 +- .../select_by_snapshot_and_metric_keys.xml | 4 +- .../db/measure/MeasureDaoTest/shared.xml | 4 +- .../with_some_measures_for_developer.xml | 4 +- .../shouldDeleteResource.xml | 8 +-- .../shouldDeleteSnapshot-result.xml | 16 ++--- .../shouldDeleteSnapshot.xml | 7 ++- ...eleteWastedMeasuresWhenPurgingSnapshot.xml | 22 +------ .../shouldPurgeSnapshot-result.xml | 4 +- .../PurgeCommandsTest/shouldPurgeSnapshot.xml | 6 +- ...ete_file_sources_of_disabled_resources.xml | 8 +-- ...resources_without_last_snapshot-result.xml | 6 +- ...isable_resources_without_last_snapshot.xml | 6 +- .../shouldDeleteAbortedBuilds-result.xml | 15 +---- .../shouldDeleteAbortedBuilds.xml | 6 +- ...oricalDataOfDirectoriesAndFiles-result.xml | 29 ++------- ...eteHistoricalDataOfDirectoriesAndFiles.xml | 12 ++-- .../PurgeDaoTest/shouldDeleteProject.xml | 8 +-- .../shouldDeleteSnapshots-result.xml | 14 +---- .../PurgeDaoTest/shouldDeleteSnapshots.xml | 6 +- .../shouldPurgeProject-result.xml | 6 +- .../purge/PurgeDaoTest/shouldPurgeProject.xml | 6 +- .../shouldSelectPurgeableSnapshots.xml | 10 +-- .../should_delete_all_closed_issues.xml | 2 +- .../should_delete_old_closed_issues.xml | 2 +- 131 files changed, 593 insertions(+), 782 deletions(-) diff --git a/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java b/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java index be1a983e7dc..bd7683fb5a8 100644 --- a/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java +++ b/it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java @@ -146,7 +146,7 @@ public class PurgeTest { // analyse twice scan(PROJECT_SAMPLE_PATH); // and check we have 2 snapshots - assertThat(count("snapshots s where s.project_id=(select p.id from projects p where p.kee='com.sonarsource.it.samples:multi-modules-sample')")).isEqualTo(2); + assertThat(count("snapshots s where s.component_uuid=(select p.uuid from projects p where p.kee='com.sonarsource.it.samples:multi-modules-sample')")).isEqualTo(2); } /** @@ -290,12 +290,12 @@ public class PurgeTest { } private void assertDeleted(String key) { - assertThat(count("snapshots s where s.project_id=(select p.id from projects p where p.kee='" + key + "')")).isZero(); + assertThat(count("snapshots s where s.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isZero(); assertThat(count("resource_index ri where ri.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isZero(); } private void assertSingleSnapshot(String key) { - assertThat(count("snapshots s where s.project_id=(select p.id from projects p where p.kee='" + key + "')")).isEqualTo(1); + assertThat(count("snapshots s where s.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isEqualTo(1); assertThat(count("resource_index ri where ri.component_uuid=(select p.uuid from projects p where p.kee='" + key + "')")).isGreaterThan(1); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java index df6dbdd5010..6e8c9c09506 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java @@ -96,13 +96,13 @@ public class ShowAction implements ComponentsWsAction { DbSession dbSession = dbClient.openSession(false); try { ComponentDto component = getComponentByUuidOrKey(dbSession, request); - SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, component.getId()); + SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); List orderedAncestors = emptyList(); if (lastSnapshot != null) { ShowData.Builder showDataBuilder = ShowData.builder(lastSnapshot); List ancestorsSnapshots = dbClient.snapshotDao().selectByIds(dbSession, showDataBuilder.getOrderedSnapshotIds()); showDataBuilder.withAncestorsSnapshots(ancestorsSnapshots); - List ancestorComponents = dbClient.componentDao().selectByIds(dbSession, showDataBuilder.getOrderedComponentIds()); + List ancestorComponents = dbClient.componentDao().selectByUuids(dbSession, showDataBuilder.getOrderedComponentUuids()); ShowData showData = showDataBuilder.andAncestorComponents(ancestorComponents); orderedAncestors = showData.getComponents(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowData.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowData.java index e5f3d22f082..9b090941d4a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowData.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowData.java @@ -52,7 +52,7 @@ class ShowData { static class Builder { private Ordering snapshotOrdering; private List orderedSnapshotIds; - private List orderedComponentIds; + private List orderedComponentUuids; private Builder(SnapshotDto snapshot) { List orderedSnapshotIdsAsString = snapshot.getPath() == null ? Collections.emptyList() : Splitter.on(".").omitEmptyStrings().splitToList(snapshot.getPath()); @@ -67,20 +67,20 @@ class ShowData { checkNotNull(snapshotOrdering, "Snapshot must be set before the ancestors"); checkState(orderedSnapshotIds.size() == ancestorsSnapshots.size(), "Missing ancestor"); - orderedComponentIds = Lists.transform( + orderedComponentUuids = Lists.transform( snapshotOrdering.immutableSortedCopy(ancestorsSnapshots), - SnapshotDtoFunctions.toComponentId()); + SnapshotDtoFunctions.toComponentUuid()); return this; } ShowData andAncestorComponents(List ancestorComponents) { - checkNotNull(orderedComponentIds, "Snapshot ancestors must be set before the component ancestors"); - checkState(orderedComponentIds.size() == ancestorComponents.size(), "Missing ancestor"); + checkNotNull(orderedComponentUuids, "Snapshot ancestors must be set before the component ancestors"); + checkState(orderedComponentUuids.size() == ancestorComponents.size(), "Missing ancestor"); return new ShowData(Ordering - .explicit(orderedComponentIds) - .onResultOf(ComponentDtoFunctions.toId()) + .explicit(orderedComponentUuids) + .onResultOf(ComponentDtoFunctions.toUuid()) .immutableSortedCopy(ancestorComponents)); } @@ -88,8 +88,8 @@ class ShowData { return orderedSnapshotIds; } - List getOrderedComponentIds() { - return orderedComponentIds; + List getOrderedComponentUuids() { + return orderedComponentUuids; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java index 6c318f50ce1..3ba6e4d9c96 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java @@ -158,7 +158,7 @@ public class TreeAction implements ComponentsWsAction { try { ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, treeWsRequest.getBaseComponentId(), treeWsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY); checkPermissions(baseComponent); - SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, baseComponent.getId()); + SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, baseComponent.uuid()); if (baseSnapshot == null) { return emptyResponse(baseComponent, treeWsRequest); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectViewAttributes.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectViewAttributes.java index 0f704cf499c..2b1b0cb2c87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectViewAttributes.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectViewAttributes.java @@ -21,22 +21,31 @@ package org.sonar.server.computation.component; import javax.annotation.concurrent.Immutable; +import static java.util.Objects.requireNonNull; + @Immutable public class ProjectViewAttributes { private final long projectId; + private final String projectUuid; - public ProjectViewAttributes(long projectId) { + public ProjectViewAttributes(long projectId, String projectUuid) { this.projectId = projectId; + this.projectUuid = requireNonNull(projectUuid, "projectUuid can't be null"); } public long getProjectId() { return projectId; } + public String getProjectUuid() { + return projectUuid; + } + @Override public String toString() { return "ProjectViewAttributes{" + "projectId=" + projectId + + ", projectUuid='" + projectUuid + '\'' + '}'; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java index 140bb6ea872..2e9e064007f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/dbcleaner/ProjectCleaner.java @@ -59,7 +59,7 @@ public class ProjectCleaner { PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectSettings, idUuidPair); - cleanHistoricalData(session, configuration.rootProjectIdUuid().getId(), projectSettings); + cleanHistoricalData(session, configuration.rootProjectIdUuid().getUuid(), projectSettings); doPurge(session, configuration); session.commit(); @@ -76,12 +76,12 @@ public class ProjectCleaner { } } - private void cleanHistoricalData(DbSession session, long resourceId, Settings settings) { + private void cleanHistoricalData(DbSession session, String componentUuid, Settings settings) { try { - periodCleaner.clean(session, resourceId, settings); + periodCleaner.clean(session, componentUuid, settings); } catch (Exception e) { // purge errors must no fail the batch - LOG.error("Fail to clean historical data [id=" + resourceId + "]", e); + LOG.error("Fail to clean historical data [uuid=" + componentUuid + "]", e); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java index dd155cf1571..b2ce8801129 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java @@ -20,7 +20,6 @@ package org.sonar.server.computation.step; import org.sonar.db.component.ResourceIndexDao; -import org.sonar.server.computation.component.DbIdsRepository; import org.sonar.server.computation.component.TreeRootHolder; /** @@ -29,18 +28,16 @@ import org.sonar.server.computation.component.TreeRootHolder; public class IndexComponentsStep implements ComputationStep { private final ResourceIndexDao resourceIndexDao; - private final DbIdsRepository dbIdsRepository; private final TreeRootHolder treeRootHolder; - public IndexComponentsStep(ResourceIndexDao resourceIndexDao, DbIdsRepository dbIdsRepository, TreeRootHolder treeRootHolder) { + public IndexComponentsStep(ResourceIndexDao resourceIndexDao, TreeRootHolder treeRootHolder) { this.resourceIndexDao = resourceIndexDao; - this.dbIdsRepository = dbIdsRepository; this.treeRootHolder = treeRootHolder; } @Override public void execute() { - resourceIndexDao.indexProject(dbIdsRepository.getComponentId(treeRootHolder.getRoot())); + resourceIndexDao.indexProject(treeRootHolder.getRoot().getUuid()); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadPeriodsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadPeriodsStep.java index 9a0ef5c9aa5..138895e63d9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadPeriodsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadPeriodsStep.java @@ -102,7 +102,7 @@ public class LoadPeriodsStep implements ComputationStep { } boolean isReportType = projectOrView.getType().isReportType(); - PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().getId(), analysisMetadataHolder.getAnalysisDate(), + PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null, isReportType ? Qualifiers.PROJECT : Qualifiers.VIEW); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PeriodResolver.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PeriodResolver.java index 7f58aa9946a..2991cf3140f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PeriodResolver.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PeriodResolver.java @@ -52,16 +52,16 @@ public class PeriodResolver { private final DbClient dbClient; private final DbSession session; - private final long projectId; + private final String projectUuid; private final long analysisDate; @CheckForNull private final String currentVersion; private final String qualifier; - public PeriodResolver(DbClient dbClient, DbSession session, long projectId, long analysisDate, @Nullable String currentVersion, String qualifier) { + public PeriodResolver(DbClient dbClient, DbSession session, String projectUuid, long analysisDate, @Nullable String currentVersion, String qualifier) { this.dbClient = dbClient; this.session = session; - this.projectId = projectId; + this.projectUuid = projectUuid; this.analysisDate = analysisDate; this.currentVersion = currentVersion; this.qualifier = qualifier; @@ -100,7 +100,7 @@ public class PeriodResolver { } private Period findByDate(int index, Date date) { - SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedAfter(date.getTime()).setSort(BY_DATE, ASC)); + SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setCreatedAfter(date.getTime()).setSort(BY_DATE, ASC)); if (snapshot == null) { return null; } @@ -110,7 +110,7 @@ public class PeriodResolver { @CheckForNull private Period findByDays(int index, int days) { - List snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC)); + List snapshots = dbClient.snapshotDao().selectSnapshotsByQuery(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setSort(BY_DATE, ASC)); long targetDate = DateUtils.addDays(new Date(analysisDate), -days).getTime(); SnapshotDto snapshot = findNearestSnapshotToTargetDate(snapshots, targetDate); if (snapshot == null) { @@ -122,7 +122,7 @@ public class PeriodResolver { @CheckForNull private Period findByPreviousAnalysis(int index) { - SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC)); + SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC)); if (snapshot == null) { return null; } @@ -135,7 +135,7 @@ public class PeriodResolver { if (currentVersion == null) { return null; } - List snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectId, currentVersion); + List snapshotDtos = dbClient.snapshotDao().selectPreviousVersionSnapshots(session, projectUuid, currentVersion); if (snapshotDtos.isEmpty()) { // If no previous version is found, the first analysis is returned return findByFirstAnalysis(index); @@ -147,7 +147,7 @@ public class PeriodResolver { @CheckForNull private Period findByFirstAnalysis(int index) { - SnapshotDto snapshotDto = dbClient.snapshotDao().selectOldestSnapshot(session, projectId); + SnapshotDto snapshotDto = dbClient.snapshotDao().selectOldestSnapshot(session, projectUuid); if (snapshotDto == null) { return null; } @@ -157,7 +157,7 @@ public class PeriodResolver { @CheckForNull private Period findByVersion(int index, String version) { - SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectId).setVersion(version).setSort(BY_DATE, DESC)); + SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setVersion(version).setSort(BY_DATE, DESC)); if (snapshot == null) { return null; } @@ -198,8 +198,8 @@ public class PeriodResolver { return nearest; } - private static SnapshotQuery createCommonQuery(Long projectId) { - return new SnapshotQuery().setComponentId(projectId).setStatus(STATUS_PROCESSED); + private static SnapshotQuery createCommonQuery(String projectUuid) { + return new SnapshotQuery().setComponentUuid(projectUuid).setStatus(STATUS_PROCESSED); } private static String formatDate(long date) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java index 98ed3a10794..3e2deea6419 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java @@ -67,7 +67,7 @@ public class PersistSnapshotsStep implements ComputationStep { try { new PathAwareCrawler<>( new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate(), dbIdsRepository)) - .visit(treeRootHolder.getRoot()); + .visit(treeRootHolder.getRoot()); session.commit(); } finally { dbClient.closeSession(session); @@ -80,7 +80,7 @@ public class PersistSnapshotsStep implements ComputationStep { private final long analysisDate; private final MutableDbIdsRepository dbIdsRepository; - private long rootId; + private String rootUuid; public PersistSnapshotsPathAwareVisitor(DbSession dbSession, long analysisDate, MutableDbIdsRepository dbIdsRepository) { super(CrawlerDepthLimit.LEAVES, Order.PRE_ORDER, SnapshotDtoHolderFactory.INSTANCE); @@ -91,7 +91,7 @@ public class PersistSnapshotsStep implements ComputationStep { @Override public void visitProject(Component project, Path path) { - this.rootId = dbIdsRepository.getComponentId(project); + this.rootUuid = project.getUuid(); SnapshotDto snapshot = createSnapshot(project, path, Qualifiers.PROJECT, Scopes.PROJECT, true); updateSnapshotPeriods(snapshot); commonForAnyVisit(project, path, snapshot); @@ -118,7 +118,7 @@ public class PersistSnapshotsStep implements ComputationStep { @Override public void visitView(Component view, Path path) { - this.rootId = dbIdsRepository.getComponentId(view); + this.rootUuid = view.getUuid(); SnapshotDto snapshot = createSnapshot(view, path, Qualifiers.VIEW, Scopes.PROJECT, false); updateSnapshotPeriods(snapshot); commonForAnyVisit(view, path, snapshot); @@ -157,11 +157,11 @@ public class PersistSnapshotsStep implements ComputationStep { private SnapshotDto createSnapshot(Component component, Path path, String qualifier, String scope, boolean setVersion) { - long componentId = dbIdsRepository.getComponentId(component); + String componentUuid = component.getUuid(); SnapshotDto snapshotDto = new SnapshotDto() - .setRootProjectId(rootId) + .setRootComponentUuid(rootUuid) .setVersion(setVersion ? component.getReportAttributes().getVersion() : null) - .setComponentId(componentId) + .setComponentUuid(componentUuid) .setQualifier(qualifier) .setScope(scope) .setLast(false) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java index 55dd22033c9..5f2706d816d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java @@ -64,7 +64,7 @@ public class SwitchSnapshotStep implements ComputationStep { private void disablePreviousSnapshot(DbSession session, long reportSnapshotId) { List snapshots = dbClient.snapshotDao().selectSnapshotAndChildrenOfProjectScope(session, reportSnapshotId); for (SnapshotDto snapshot : snapshots) { - SnapshotDto previousLastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(session, snapshot.getComponentId()); + SnapshotDto previousLastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, snapshot.getComponentUuid()); if (previousLastSnapshot != null) { dbClient.snapshotDao().updateSnapshotAndChildrenLastFlag(session, previousLastSnapshot, false); session.commit(); @@ -75,7 +75,7 @@ public class SwitchSnapshotStep implements ComputationStep { private void enableCurrentSnapshot(DbSession session, long reportSnapshotId) { SnapshotDao dao = dbClient.snapshotDao(); SnapshotDto snapshot = dao.selectOrFailById(session, reportSnapshotId); - SnapshotDto previousLastSnapshot = dao.selectLastSnapshotByComponentId(session, snapshot.getComponentId()); + SnapshotDto previousLastSnapshot = dao.selectLastSnapshotByComponentUuid(session, snapshot.getComponentUuid()); boolean isLast = isLast(snapshot, previousLastSnapshot); dao.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, isLast, SnapshotDto.STATUS_PROCESSED); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java index 7c5e805808e..32d9329bba7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java @@ -147,7 +147,7 @@ public class ValidateProjectStep implements ComputationStep { private void validateAnalysisDate(Optional baseProject) { if (baseProject.isPresent()) { - SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentId(session, baseProject.get().getId()); + SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, baseProject.get().uuid()); long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate(); Long lastAnalysisDate = snapshotDto != null ? snapshotDto.getCreatedAt() : null; if (lastAnalysisDate != null && currentAnalysisDate <= snapshotDto.getCreatedAt()) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java index fa98d0fc3f2..5fa880c1cf7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java @@ -250,7 +250,7 @@ public class IssueQueryService { @CheckForNull private Date findCreatedAfterFromComponentUuid(DbSession dbSession, String uuid) { ComponentDto component = checkFoundWithOptional(componentService.getByUuid(uuid), "Component with id '%s' not found", uuid); - SnapshotDto snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, component.getId()); + SnapshotDto snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); Long projectSnapshotId = snapshot == null ? null : snapshot.getRootId(); SnapshotDto projectSnapshot = projectSnapshotId == null ? snapshot : dbClient.snapshotDao().selectById(dbSession, projectSnapshotId); return projectSnapshot == null ? null : longToDate(projectSnapshot.getPeriodDate(1)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java index e93c253bce5..125fe79428e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java @@ -96,9 +96,11 @@ class MeasureFilterSql { private String generateSql() { StringBuilder sb = new StringBuilder(1000); - sb.append("SELECT s.id, s.project_id, s.root_project_id, "); + sb.append("SELECT s.id, p.id, root.id, "); sb.append(filter.sort().column()); - sb.append(" FROM snapshots s INNER JOIN projects p ON s.project_id=p.id "); + sb.append(" FROM snapshots s"); + sb.append(" INNER JOIN projects p ON s.component_uuid=p.uuid "); + sb.append(" INNER JOIN projects root ON s.root_component_uuid=root.uuid "); for (int index = 0; index < filter.getMeasureConditions().size(); index++) { MeasureFilterCondition condition = filter.getMeasureConditions().get(index); @@ -108,7 +110,7 @@ class MeasureFilterSql { } if (filter.isOnFavourites()) { - sb.append(" INNER JOIN properties props ON props.resource_id=s.project_id "); + sb.append(" INNER JOIN properties props ON props.resource_id=p.id "); } if (filter.sort().isOnMeasure()) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java index 16ed05c32e8..6efe11a28d9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java @@ -115,7 +115,7 @@ public class SearchAction implements CustomMeasuresWsAction { @CheckForNull private Long searchLastSnapshot(DbSession dbSession, ComponentDto project) { - SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, project.getId()); + SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, project.uuid()); return lastSnapshot == null ? null : lastSnapshot.getBuildDate(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 72bb2c58e7c..5a8f2b7e18e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -135,7 +135,7 @@ public class ComponentAction implements MeasuresWsAction { Long developerId = searchDeveloperId(dbSession, request); Optional refComponent = getReferenceComponent(dbSession, component); checkPermissions(component); - SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, component.getId()); + SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); List metrics = searchMetrics(dbSession, request); List periods = snapshotToWsPeriods(lastSnapshot); List measures = searchMeasures(dbSession, component, lastSnapshot, metrics, periods, developerId); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java index d386def59a3..3b29e1c58a4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java @@ -101,7 +101,7 @@ public class ComponentTreeDataLoader { try { ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY); checkPermissions(baseComponent); - SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, baseComponent.getId()); + SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, baseComponent.uuid()); if (baseSnapshot == null) { return ComponentTreeData.builder() .setBaseComponent(baseComponent) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index 0201259bef8..252a6b3d19c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -144,13 +144,13 @@ public class ProjectStatusAction implements QGateWsAction { private ProjectAndSnapshot getProjectThenSnapshot(DbSession dbSession, ProjectStatusWsRequest request) { ComponentDto projectDto = componentFinder.getByUuidOrKey(dbSession, request.getProjectId(), request.getProjectKey(), ParamNames.PROJECT_ID_AND_KEY); - SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentId(dbSession, projectDto.getId()); + SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, projectDto.uuid()); return new ProjectAndSnapshot(projectDto, snapshotDto); } private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String snapshotId) { SnapshotDto snapshotDto = getSnapshot(dbSession, snapshotId); - ComponentDto projectDto = dbClient.componentDao().selectOrFailById(dbSession, snapshotDto.getComponentId()); + ComponentDto projectDto = dbClient.componentDao().selectOrFailByUuid(dbSession, snapshotDto.getComponentUuid()); return new ProjectAndSnapshot(projectDto, snapshotDto); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java index 3d64e852f3e..f8f1995df0f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java @@ -115,7 +115,7 @@ public class ComponentNavigationAction implements NavigationWsAction { userSession.checkComponentUuidPermission(UserRole.USER, component.projectUuid()); - SnapshotDto snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentId(session, component.getId()); + SnapshotDto snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, component.uuid()); JsonWriter json = response.newJsonWriter(); json.beginObject(); @@ -267,7 +267,7 @@ public class ComponentNavigationAction implements NavigationWsAction { SnapshotDto currentSnapshot = snapshot; while (currentSnapshot.getParentId() != null) { currentSnapshot = dbClient.snapshotDao().selectOrFailById(session, currentSnapshot.getParentId()); - componentPath.add(0, dbClient.componentDao().selectOrFailById(session, currentSnapshot.getComponentId())); + componentPath.add(0, dbClient.componentDao().selectOrFailByUuid(session, currentSnapshot.getComponentUuid())); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java index 28e08a37eb1..7886adb6c0c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/dbcleaner/ProjectCleanerTest.java @@ -33,6 +33,7 @@ import org.sonar.db.purge.PurgeListener; import org.sonar.db.purge.PurgeProfiler; import org.sonar.db.purge.period.DefaultPeriodCleaner; +import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.doThrow; @@ -78,7 +79,7 @@ public class ProjectCleanerTest { underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings); - verify(periodCleaner).clean(any(DbSession.class), any(Long.class), any(Settings.class)); + verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class)); verify(dao).purge(any(DbSession.class), any(PurgeConfiguration.class), any(PurgeListener.class), any(PurgeProfiler.class)); } @@ -93,10 +94,10 @@ public class ProjectCleanerTest { @Test public void if_profiler_cleaning_fails_it_should_not_interrupt_program_execution() { - doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class)); + doThrow(RuntimeException.class).when(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class)); underTest.purge(mock(DbSession.class), mock(IdUuidPair.class), settings); - verify(periodCleaner).clean(any(DbSession.class), anyLong(), any(Settings.class)); + verify(periodCleaner).clean(any(DbSession.class), anyString(), any(Settings.class)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java index e139a3c1137..6269fa2e659 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java @@ -52,7 +52,7 @@ public class MeasureToMeasureDtoTest { private static final MetricImpl SOME_STRING_METRIC = new MetricImpl(5, "5", "5", Metric.MetricType.STRING); private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl(6, "6", "6", Metric.MetricType.LEVEL); - static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).build(); + static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid_1").build(); @Rule public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(SOME_COMPONENT); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java index e07aa3fb054..e39e8a2e71b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java @@ -25,7 +25,6 @@ import org.sonar.db.component.ResourceIndexDao; import org.sonar.server.computation.batch.BatchReportReaderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; -import org.sonar.server.computation.component.MutableDbIdsRepositoryRule; import org.sonar.server.computation.component.ReportComponent; import org.sonar.server.computation.component.ViewsComponent; @@ -37,37 +36,34 @@ import static org.sonar.server.computation.component.Component.Type.VIEW; public class IndexComponentsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; + private static final String PROJECT_UUID = "PROJECT_UUID"; @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); @Rule public BatchReportReaderRule reportReader = new BatchReportReaderRule(); - @Rule - public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder); ResourceIndexDao resourceIndexDao = mock(ResourceIndexDao.class); - IndexComponentsStep underTest = new IndexComponentsStep(resourceIndexDao, dbIdsRepository, treeRootHolder); + IndexComponentsStep underTest = new IndexComponentsStep(resourceIndexDao, treeRootHolder); @Test public void call_indexProject_of_dao_for_project() { - Component project = ReportComponent.builder(PROJECT, 1).setUuid("PROJECT_UUID").setKey(PROJECT_KEY).build(); - dbIdsRepository.setComponentId(project, 123L); + Component project = ReportComponent.builder(PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build(); treeRootHolder.setRoot(project); underTest.execute(); - verify(resourceIndexDao).indexProject(123L); + verify(resourceIndexDao).indexProject(PROJECT_UUID); } @Test public void call_indexProject_of_dao_for_view() { - Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid("PROJECT_UUID").build(); - dbIdsRepository.setComponentId(view, 123L); + Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid(PROJECT_UUID).build(); treeRootHolder.setRoot(view); underTest.execute(); - verify(resourceIndexDao).indexProject(123L); + verify(resourceIndexDao).indexProject(PROJECT_UUID); } @Override diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java index 930595e9cf3..9517ebb1390 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java @@ -54,13 +54,10 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - @Rule public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); - @Rule public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); - @Rule public PeriodsHolderRule periodsHolder = new PeriodsHolderRule(); @@ -124,9 +121,9 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(4); - SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.getId()); - assertThat(projectSnapshot.getComponentId()).isEqualTo(projectDto.getId()); - assertThat(projectSnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); + assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid()); + assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(projectSnapshot.getRootId()).isNull(); assertThat(projectSnapshot.getParentId()).isNull(); assertThat(projectSnapshot.getDepth()).isEqualTo(0); @@ -139,9 +136,9 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(projectSnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto moduleSnapshot = getUnprocessedSnapshot(moduleDto.getId()); - assertThat(moduleSnapshot.getComponentId()).isEqualTo(moduleDto.getId()); - assertThat(moduleSnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto moduleSnapshot = getUnprocessedSnapshot(moduleDto.uuid()); + assertThat(moduleSnapshot.getComponentUuid()).isEqualTo(module.getUuid()); + assertThat(moduleSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(moduleSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleSnapshot.getDepth()).isEqualTo(1); @@ -154,9 +151,9 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { assertThat(moduleSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(moduleSnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto directorySnapshot = getUnprocessedSnapshot(directoryDto.getId()); - assertThat(directorySnapshot.getComponentId()).isEqualTo(directoryDto.getId()); - assertThat(directorySnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto directorySnapshot = getUnprocessedSnapshot(directoryDto.uuid()); + assertThat(directorySnapshot.getComponentUuid()).isEqualTo(directory.getUuid()); + assertThat(directorySnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(directorySnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(directorySnapshot.getParentId()).isEqualTo(moduleSnapshot.getId()); assertThat(directorySnapshot.getDepth()).isEqualTo(2); @@ -169,9 +166,9 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { assertThat(directorySnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(directorySnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.getId()); - assertThat(fileSnapshot.getComponentId()).isEqualTo(fileDto.getId()); - assertThat(fileSnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); + assertThat(fileSnapshot.getComponentUuid()).isEqualTo(file.getUuid()); + assertThat(fileSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(fileSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(fileSnapshot.getParentId()).isEqualTo(directorySnapshot.getId()); assertThat(fileSnapshot.getDepth()).isEqualTo(3); @@ -214,7 +211,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.getId()); + SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); assertThat(fileSnapshot.getQualifier()).isEqualTo("UTS"); assertThat(fileSnapshot.getScope()).isEqualTo("FIL"); } @@ -246,29 +243,29 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(4); - SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.getId()); - assertThat(projectSnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); + assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(projectSnapshot.getRootId()).isNull(); assertThat(projectSnapshot.getParentId()).isNull(); assertThat(projectSnapshot.getDepth()).isEqualTo(0); assertThat(projectSnapshot.getPath()).isNullOrEmpty(); - SnapshotDto moduleASnapshot = getUnprocessedSnapshot(moduleADto.getId()); - assertThat(moduleASnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto moduleASnapshot = getUnprocessedSnapshot(moduleADto.uuid()); + assertThat(moduleASnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(moduleASnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleASnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleASnapshot.getDepth()).isEqualTo(1); assertThat(moduleASnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "."); - SnapshotDto subModuleASnapshot = getUnprocessedSnapshot(subModuleADto.getId()); - assertThat(subModuleASnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto subModuleASnapshot = getUnprocessedSnapshot(subModuleADto.uuid()); + assertThat(subModuleASnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(subModuleASnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(subModuleASnapshot.getParentId()).isEqualTo(moduleASnapshot.getId()); assertThat(subModuleASnapshot.getDepth()).isEqualTo(2); assertThat(subModuleASnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "." + moduleASnapshot.getId() + "."); - SnapshotDto moduleBSnapshot = getUnprocessedSnapshot(moduleBDto.getId()); - assertThat(moduleBSnapshot.getRootProjectId()).isEqualTo(projectDto.getId()); + SnapshotDto moduleBSnapshot = getUnprocessedSnapshot(moduleBDto.uuid()); + assertThat(moduleBSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); assertThat(moduleBSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleBSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); assertThat(moduleBSnapshot.getDepth()).isEqualTo(1); @@ -290,7 +287,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.getId()); + SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); assertThat(projectSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); assertThat(projectSnapshot.getPeriodModeParameter(1)).isNotNull(); @@ -335,16 +332,16 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.getId()); + SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(newProjectSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - SnapshotDto newModuleSnapshot = getUnprocessedSnapshot(moduleDto.getId()); + SnapshotDto newModuleSnapshot = getUnprocessedSnapshot(moduleDto.uuid()); assertThat(newModuleSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - SnapshotDto newDirectorySnapshot = getUnprocessedSnapshot(directoryDto.getId()); + SnapshotDto newDirectorySnapshot = getUnprocessedSnapshot(directoryDto.uuid()); assertThat(newDirectorySnapshot.getPeriodMode(1)).isNull(); - SnapshotDto newFileSnapshot = getUnprocessedSnapshot(fileDto.getId()); + SnapshotDto newFileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); assertThat(newFileSnapshot.getPeriodMode(1)).isNull(); } @@ -362,15 +359,15 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.getId()); + SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getPeriodMode(1)).isNull(); assertThat(projectSnapshot.getPeriodDate(1)).isNull(); assertThat(projectSnapshot.getPeriodModeParameter(1)).isNull(); } - private SnapshotDto getUnprocessedSnapshot(long componentId) { + private SnapshotDto getUnprocessedSnapshot(String componentUuid) { List projectSnapshots = dbClient.snapshotDao().selectSnapshotsByQuery(dbTester.getSession(), - new SnapshotQuery().setComponentId(componentId).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); + new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); assertThat(projectSnapshots).hasSize(1); return projectSnapshots.get(0); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java index ea4c4e5dfaa..41266b7ed31 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java @@ -300,7 +300,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .setUuid(PROJECT_VIEW_1_UUID) .setName(PROJECT_VIEW_1_NAME) .setDescription("project view description is not persisted") - .setProjectViewAttributes(new ProjectViewAttributes(project.getId())); + .setProjectViewAttributes(new ProjectViewAttributes(project.getId(), project.uuid())); } private void persistComponents(ComponentDto... componentDtos) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java index b0b2bc73aae..26f66cad5b6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java @@ -47,7 +47,6 @@ import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.ComponentTesting.newProjectDto; import static org.sonar.db.component.ComponentTesting.newSubView; import static org.sonar.db.component.ComponentTesting.newView; -import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; import static org.sonar.server.computation.component.Component.Type.PROJECT_VIEW; import static org.sonar.server.computation.component.Component.Type.SUBVIEW; import static org.sonar.server.computation.component.Component.Type.VIEW; @@ -114,17 +113,13 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { Component view = ViewsComponent.builder(VIEW, 1).setUuid("ABCD").addChildren(subView).build(); treeRootHolder.setRoot(view); - dbIdsRepository.setComponentId(view, viewDto.getId()); - dbIdsRepository.setComponentId(subView, subViewDto.getId()); - dbIdsRepository.setComponentId(projectView, projectViewDto.getId()); - underTest.execute(); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(3); - SnapshotDto projectSnapshot = getUnprocessedSnapshot(viewDto.getId()); - assertThat(projectSnapshot.getComponentId()).isEqualTo(viewDto.getId()); - assertThat(projectSnapshot.getRootProjectId()).isEqualTo(viewDto.getId()); + SnapshotDto projectSnapshot = getUnprocessedSnapshot(viewDto.uuid()); + assertThat(projectSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); + assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); assertThat(projectSnapshot.getRootId()).isNull(); assertThat(projectSnapshot.getParentId()).isNull(); assertThat(projectSnapshot.getDepth()).isEqualTo(0); @@ -137,9 +132,9 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(projectSnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.getId()); - assertThat(subViewSnapshot.getComponentId()).isEqualTo(subViewDto.getId()); - assertThat(subViewSnapshot.getRootProjectId()).isEqualTo(viewDto.getId()); + SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.uuid()); + assertThat(subViewSnapshot.getComponentUuid()).isEqualTo(subView.getUuid()); + assertThat(subViewSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); assertThat(subViewSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(subViewSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); assertThat(subViewSnapshot.getDepth()).isEqualTo(1); @@ -152,9 +147,9 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { assertThat(subViewSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(subViewSnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto projectViewSnapshot = getUnprocessedSnapshot(projectViewDto.getId()); - assertThat(projectViewSnapshot.getComponentId()).isEqualTo(projectViewDto.getId()); - assertThat(projectViewSnapshot.getRootProjectId()).isEqualTo(viewDto.getId()); + SnapshotDto projectViewSnapshot = getUnprocessedSnapshot(projectViewDto.uuid()); + assertThat(projectViewSnapshot.getComponentUuid()).isEqualTo(projectView.getUuid()); + assertThat(projectViewSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); assertThat(projectViewSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); assertThat(projectViewSnapshot.getParentId()).isEqualTo(subViewSnapshot.getId()); assertThat(projectViewSnapshot.getDepth()).isEqualTo(2); @@ -168,20 +163,16 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { assertThat(projectViewSnapshot.getBuildDate()).isEqualTo(now); assertThat(dbIdsRepository.getSnapshotId(view)).isEqualTo(projectSnapshot.getId()); - assertThat(dbIdsRepository.getComponentId(subView)).isEqualTo(subViewDto.getId()); - assertThat(dbIdsRepository.getComponentId(projectView)).isEqualTo(projectViewDto.getId()); } @Test public void persist_snapshots_with_periods() { ComponentDto viewDto = save(newView("ABCD").setKey(valueOf(PROJECT_KEY)).setName("Project")); ComponentDto subViewDto = save(newSubView(viewDto, "CDEF", "key").setKey("2")); - SnapshotDto viewSnapshotDto = save(newSnapshotForProject(viewDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime())); - SnapshotDto subViewSnapshotDto = save(newSnapshotForProject(subViewDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime())); dbTester.getSession().commit(); Component subView = ViewsComponent.builder(SUBVIEW, 2).setUuid("ABCD").build(); - Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid("ABCD").addChildren(subView).build(); + Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid("CDEF").addChildren(subView).build(); treeRootHolder.setRoot(view); dbIdsRepository.setComponentId(view, viewDto.getId()); dbIdsRepository.setComponentId(subView, subViewDto.getId()); @@ -190,12 +181,12 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.getId()); + SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); assertThat(viewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); assertThat(viewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); assertThat(viewSnapshot.getPeriodModeParameter(1)).isNotNull(); - SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.getId()); + SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.uuid()); assertThat(subViewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); assertThat(subViewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); assertThat(subViewSnapshot.getPeriodModeParameter(1)).isNotNull(); @@ -206,14 +197,9 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { return componentDto; } - private SnapshotDto save(SnapshotDto snapshotDto) { - dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); - return snapshotDto; - } - - private SnapshotDto getUnprocessedSnapshot(long componentId) { + private SnapshotDto getUnprocessedSnapshot(String componentUuid) { List projectSnapshots = dbClient.snapshotDao().selectSnapshotsByQuery(dbTester.getSession(), - new SnapshotQuery().setComponentId(componentId).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); + new SnapshotQuery().setComponentUuid(componentUuid).setIsLast(false).setStatus(SnapshotDto.STATUS_UNPROCESSED)); assertThat(projectSnapshots).hasSize(1); return projectSnapshots.get(0); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java index bd457413dca..e9e9f3fe160 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java @@ -148,7 +148,7 @@ public class ComponentNavigationActionTest { .setKey("polop").setName("Polop"); dbClient.componentDao().insert(dbTester.getSession(), project); dbClient.snapshotDao().insert(dbTester.getSession(), new SnapshotDto().setCreatedAt(snapshotDate.getTime()).setVersion("3.14") - .setLast(true).setQualifier(project.qualifier()).setComponentId(project.getId()).setRootProjectId(project.getId()).setScope(project.scope())); + .setLast(true).setQualifier(project.qualifier()).setComponentUuid(project.uuid()).setRootComponentUuid(project.uuid()).setScope(project.scope())); dbTester.getSession().commit(); userSessionRule.login("obiwan").setUserId(userId).addProjectUuidPermissions(UserRole.USER, "abcd"); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml index 19ce3154111..0234c9b213f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml @@ -1,7 +1,7 @@ - - - + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml index a99245eec5d..be57cfc6d21 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml @@ -7,7 +7,7 @@ @@ -15,7 +15,7 @@ @@ -24,7 +24,7 @@ @@ -32,7 +32,7 @@ @@ -40,7 +40,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml index cc92a138743..f8b76a17917 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml @@ -7,7 +7,7 @@ @@ -15,7 +15,7 @@ @@ -24,7 +24,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_is_last_one.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_is_last_one.xml index f61194367cf..6a97946ef19 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_is_last_one.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_is_last_one.xml @@ -9,7 +9,7 @@ period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" - project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + component_uuid="ABCD" parent_snapshot_id="[null]" root_component_uuid="ABCD" root_snapshot_id="[null]" scope="PRJ" qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" path="" status="P" islast="[true]" depth="0"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml index 8a81488a57a..2c8ae5c913f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml @@ -7,7 +7,7 @@ @@ -15,7 +15,7 @@ @@ -24,7 +24,7 @@ @@ -32,7 +32,7 @@ @@ -40,7 +40,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/unprocessed_snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/unprocessed_snapshots.xml index e0a95fb14f2..70de478ba1e 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/unprocessed_snapshots.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/unprocessed_snapshots.xml @@ -8,7 +8,7 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml index f92f776ff1a..e8d30bcb7dd 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml @@ -1,7 +1,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml index a5097aa6f66..f17681470e3 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml @@ -2,6 +2,6 @@ - - + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml index 76aa5b6864f..1a1f7e8466a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml @@ -1,7 +1,7 @@ - + - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml index bdaace4d67c..832058c2eef 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml @@ -1,10 +1,10 @@ - + - + - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml b/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml index be3bfa4e5ea..4f0c07b3f5b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml @@ -3,14 +3,14 @@ - - @@ -18,13 +18,13 @@ - - @@ -32,14 +32,14 @@ - - @@ -47,7 +47,7 @@ - @@ -57,7 +57,7 @@ - @@ -65,7 +65,7 @@ - diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb index 44277d0885b..7900407f219 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb @@ -130,10 +130,10 @@ class Api::EventsController < Api::ApiController if (params[:dateTime]) # try to find a snapshot on that day date = parse_datetime(params[:dateTime], true) - root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ? AND created_at >= ? AND created_at <= ?", @resource.id, date.to_i*1000, (date + 1.day).to_i*1000], :order => :created_at) + root_snapshot = Snapshot.find(:last, :conditions => ["component_uuid = ? AND created_at >= ? AND created_at <= ?", @resource.uuid, date.to_i*1000, (date + 1.day).to_i*1000], :order => :created_at) raise "No snapshot exists for given date" unless root_snapshot else - root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ?", @resource.id], :order => :created_at) + root_snapshot = Snapshot.find(:last, :conditions => ["component_uuid = ?", @resource.uuid], :order => :created_at) end raise "A version already exists on this resource." if params[:category]==EventCategory::KEY_VERSION && root_snapshot.event(EventCategory::KEY_VERSION) @@ -161,7 +161,7 @@ class Api::EventsController < Api::ApiController :event_date => snapshot.created_at ) event.save! - event_to_return = event if snapshot.project_id = @resource.id + event_to_return = event if snapshot.component_uuid = @resource.uuid end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb index cac85bb1e1d..de02d22c9cd 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb @@ -38,7 +38,7 @@ class Api::ProjectsController < Api::ApiController begin @show_description=(params[:desc]=='true') @projects=load_projects - @snapshots_by_pid=load_snapshots_by_project + @snapshots_by_puuid=load_snapshots_by_project respond_to do |format| format.json{ render :json => jsonp(to_json) } format.xml { render :xml => to_xml } @@ -115,7 +115,7 @@ class Api::ProjectsController < Api::ApiController end # this is really an advanced optimization ! - select_columns='id,kee,name,language,long_name,scope,qualifier,root_id' + select_columns='id,uuid,kee,name,language,long_name,scope,qualifier,root_id' select_columns += ',description' if @show_description projects=Project.find(:all, :select => select_columns, :conditions => [conditions.join(' AND '), values], :order => 'name') @@ -123,21 +123,21 @@ class Api::ProjectsController < Api::ApiController end def load_snapshots_by_project - select_columns='id,project_id,version,islast,created_at' + select_columns='id,component_uuid,version,islast,created_at' if params[:versions]=='true' - snapshots=Snapshot.find_by_sql(["SELECT #{select_columns} FROM snapshots s1 WHERE s1.status=? AND s1.project_id IN (?) AND NOT EXISTS(SELECT * FROM snapshots s2 WHERE s2.project_id=s1.project_id AND s2.created_at>s1.created_at AND s2.version=s1.version)", 'P', @projects.map{|p| p.id}]) + snapshots=Snapshot.find_by_sql(["SELECT #{select_columns} FROM snapshots s1 WHERE s1.status=? AND s1.component_uuid IN (?) AND NOT EXISTS(SELECT * FROM snapshots s2 WHERE s2.component_uuid=s1.component_uuid AND s2.created_at>s1.created_at AND s2.version=s1.version)", 'P', @projects.map{|p| p.uuid}]) elsif params[:versions]=='last' - snapshots=Snapshot.find_by_sql(["SELECT #{select_columns} FROM snapshots s1 WHERE s1.status=? AND islast=? AND s1.project_id IN (?) AND NOT EXISTS(SELECT * FROM snapshots s2 WHERE s2.project_id=s1.project_id AND s2.created_at>s1.created_at AND s2.version=s1.version)", 'P', true, @projects.map{|p| p.id}]) + snapshots=Snapshot.find_by_sql(["SELECT #{select_columns} FROM snapshots s1 WHERE s1.status=? AND islast=? AND s1.component_uuid IN (?) AND NOT EXISTS(SELECT * FROM snapshots s2 WHERE s2.component_uuid=s1.component_uuid AND s2.created_at>s1.created_at AND s2.version=s1.version)", 'P', true, @projects.map{|p| p.uuid}]) else snapshots=[] end - snapshots_by_project_id={} + snapshots_by_project_uuid={} snapshots.each do |s| - snapshots_by_project_id[s.project_id]||=[] - snapshots_by_project_id[s.project_id]< s1.version}.each do |snapshot| + @snapshots_by_puuid[project.uuid].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot| version={:sid => snapshot.id.to_s} version[:d]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at if snapshot.last? @@ -189,8 +189,8 @@ class Api::ProjectsController < Api::ApiController xml.qualifier(project.qualifier) xml.desc(project.description) if @show_description && project.description - if @snapshots_by_pid && @snapshots_by_pid[project.id] - @snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot| + if @snapshots_by_puuid && @snapshots_by_puuid[project.uuid] + @snapshots_by_puuid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot| attributes={:sid => snapshot.id.to_s, :last => snapshot.last?} attributes[:date]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at xml.version(snapshot.version, attributes) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb index 35f9baa870b..9be60b5114a 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb @@ -227,10 +227,10 @@ class Api::ResourcesController < Api::ApiController # ---------- PREPARE RESPONSE resource_by_sid={} - snapshots_by_rid={} + snapshots_by_uuid={} snapshots_including_resource.each do |snapshot| resource_by_sid[snapshot.id]=snapshot.project - snapshots_by_rid[snapshot.project_id]=snapshot + snapshots_by_uuid[snapshot.component_uuid]=snapshot end @@ -248,7 +248,7 @@ class Api::ResourcesController < Api::ApiController sorted_resources=sorted_resources.uniq.compact # ---------- FORMAT RESPONSE - objects={:sorted_resources => sorted_resources, :snapshots_by_rid => snapshots_by_rid, :measures_by_sid => measures_by_sid, :params => params} + objects={:sorted_resources => sorted_resources, :snapshots_by_uuid => snapshots_by_uuid, :measures_by_sid => measures_by_sid, :params => params} respond_to do |format| format.json { render :json => jsonp(to_json(objects)) } format.xml { render :xml => to_xml(objects) } @@ -277,13 +277,13 @@ class Api::ResourcesController < Api::ApiController def to_json(objects) resources = objects[:sorted_resources] - snapshots_by_rid = objects[:snapshots_by_rid] + snapshots_by_uuid = objects[:snapshots_by_uuid] measures_by_sid = objects[:measures_by_sid] params = objects[:params] result=[] resources.each do |resource| - snapshot=snapshots_by_rid[resource.id] + snapshot=snapshots_by_uuid[resource.uuid] result< @resource.id, :status => Snapshot::STATUS_PROCESSED} + sql_conditions = ['snapshots.component_uuid=:rid AND snapshots.status=:status AND project_measures.person_id IS NULL'] + sql_values = {:rid => @resource.uuid, :status => Snapshot::STATUS_PROCESSED} if params[:fromDateTime] from = parse_datetime(params[:fromDateTime]) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index 169e153b56a..16fbb908651 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -221,7 +221,7 @@ class ProjectController < ApplicationController end @snapshot=@project.last_snapshot - @snapshots = Snapshot.all(:conditions => ["status='P' AND project_id=?", @project.id], + @snapshots = Snapshot.all(:conditions => ["status='P' AND component_uuid=?", @project.uuid], :include => 'events', :order => 'snapshots.created_at DESC') end @@ -320,7 +320,7 @@ class ProjectController < ApplicationController end end - redirect_to :action => 'history', :id => snapshot.root_project_id + redirect_to :action => 'history', :id => snapshot.root_project.id end def delete_version @@ -329,7 +329,7 @@ class ProjectController < ApplicationController access_denied unless is_admin?(parent_snapshot) # We update all the related snapshots to have the same version as the next snapshot - next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', parent_snapshot.created_at.to_i*1000, parent_snapshot.project_id], :order => 'created_at asc') + next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and component_uuid=?', parent_snapshot.created_at.to_i*1000, parent_snapshot.component_uuid], :order => 'created_at asc') snapshots = find_project_snapshots(parent_snapshot.id) snapshots.each do |snapshot| snapshot.version = next_snapshot.version @@ -348,7 +348,7 @@ class ProjectController < ApplicationController end flash[:notice] = message('project_history.version_removed', :params => h(old_version_name)) - redirect_to :action => 'history', :id => parent_snapshot.root_project_id + redirect_to :action => 'history', :id => parent_snapshot.root_project.id end def create_event @@ -371,7 +371,7 @@ class ProjectController < ApplicationController flash[:notice] = message('project_history.event_created', :params => h(params[:event_name])) end - redirect_to :action => 'history', :id => snapshot.project_id + redirect_to :action => 'history', :id => snapshot.project.id end def update_event diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb index b9d1b345cf7..6133eaead1e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb @@ -70,7 +70,7 @@ class Event < ActiveRecord::Base # def self.already_exists(snapshot_id, event_name, event_category) snapshot = Snapshot.find(snapshot_id.to_i) - snapshots = Snapshot.find(:all, :conditions => ["status='P' AND project_id=?", snapshot.project_id], :include => 'events') + snapshots = Snapshot.find(:all, :conditions => ["status='P' AND component_uuid=?", snapshot.component_uuid], :include => 'events') snapshots.each do |snapshot| snapshot.events.each do |event| return true if event.name==event_name && event.category==event_category @@ -82,6 +82,6 @@ class Event < ActiveRecord::Base def populate_snapshot self.created_at=DateTime.now unless self.created_at - self.snapshot=Snapshot.snapshot_by_date(resource_id, event_date) unless self.snapshot + self.snapshot=Snapshot.snapshot_by_date(snapshot.uuid, event_date) unless self.snapshot end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb index ad9713b3dbe..2a24b78060e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -287,15 +287,11 @@ class MeasureFilter < ActiveRecord::Base end if require_links? - project_ids = [] project_uuids = [] - project_id_by_uuid = {} - rows_by_project_id = {} + rows_by_project_uuid = {} snapshots.each do |snapshot| - project_ids << snapshot.project_id - project_uuids << snapshot.project.uuid - project_id_by_uuid[snapshot.project.uuid] = snapshot.project_id - rows_by_project_id[snapshot.project_id] = rows_by_snapshot_id[snapshot.id] + project_uuids << snapshot.component_uuid + rows_by_project_uuid[snapshot.component_uuid] = rows_by_snapshot_id[snapshot.id] end links = [] @@ -303,7 +299,7 @@ class MeasureFilter < ActiveRecord::Base links.concat(ProjectLink.all(:conditions => {:component_uuid => safe_for_oracle_uuids}, :order => 'link_type')) end links.each do |link| - rows_by_project_id[project_id_by_uuid[link.component_uuid]].add_link(link) + rows_by_project_uuid[link.component_uuid].add_link(link) end end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb index 668c75ebd46..b3c0ec0dbc3 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb @@ -21,8 +21,8 @@ class Project < ActiveRecord::Base include Comparable include Resourceable - has_many :snapshots - has_many :processed_snapshots, :class_name => 'Snapshot', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc' + has_many :snapshots, :class_name => 'Snapshot', :foreign_key => 'component_uuid', :primary_key => 'uuid' + has_many :processed_snapshots, :class_name => 'Snapshot', :foreign_key => 'component_uuid', :primary_key => 'uuid', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc' has_many :events, :foreign_key => 'component_uuid', :primary_key => 'uuid', :order => 'event_date DESC' has_many :project_links, :foreign_key => 'component_uuid', :primary_key => 'uuid', :dependent => :delete_all, :order => 'link_type' has_many :user_roles, :foreign_key => 'resource_id' @@ -108,7 +108,7 @@ class Project < ActiveRecord::Base def last_snapshot @last_snapshot ||= begin - snapshot=Snapshot.first(:conditions => {:islast => true, :project_id => id}) + snapshot=Snapshot.first(:conditions => {:islast => true, :component_uuid => uuid}) if snapshot snapshot.project=self end @@ -146,7 +146,7 @@ class Project < ActiveRecord::Base ' from project_measures m, snapshots s ' + ' where s.id=m.snapshot_id and ' + " s.status='%s' and " + - ' s.project_id=%s and m.metric_id=%s ', 'P', self.id, metric_id]) + + ' s.component_uuid=%s and m.metric_id=%s ', 'P', self.uuid, metric_id]) + ' and m.person_id IS NULL' + ' order by s.created_at' create_chart_measures(Project.connection.select_all(sql), 'created_at', 'value') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb index f929f119e6f..9d17cfe325e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb @@ -21,8 +21,8 @@ class Snapshot < ActiveRecord::Base include Resourceable acts_as_tree :foreign_key => 'parent_snapshot_id' - belongs_to :project - belongs_to :root_project, :class_name => 'Project', :foreign_key => 'root_project_id' + belongs_to :project, :class_name => 'Project', :foreign_key => 'component_uuid',:primary_key => 'uuid' + belongs_to :root_project, :class_name => 'Project', :foreign_key => 'root_component_uuid',:primary_key => 'uuid' belongs_to :parent_snapshot, :class_name => 'Snapshot', :foreign_key => 'parent_snapshot_id' belongs_to :root_snapshot, :class_name => 'Snapshot', :foreign_key => 'root_snapshot_id' @@ -75,7 +75,7 @@ class Snapshot < ActiveRecord::Base # 2. project B, which depends on A 1.0, is analyzed -> new snapshot A 1.0 with qualifier LIB. # 3. project A has 2 snapshots : the first one with qualifier=TRK has measures, the second one with qualifier LIB has no measures. Its version must not be used in time machine # That's why the 2 following SQL requests check the qualifiers (and optionally scopes, just to be sure) - snapshots=Snapshot.find(:all, :conditions => ["snapshots.project_id=? AND events.snapshot_id=snapshots.id AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier], + snapshots=Snapshot.find(:all, :conditions => ["snapshots.component_uuid=? AND events.snapshot_id=snapshots.id AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.uuid, STATUS_PROCESSED, resource.scope, resource.qualifier], :include => 'events', :order => 'snapshots.created_at ASC') @@ -84,7 +84,7 @@ class Snapshot < ActiveRecord::Base snapshots=snapshots[-5, 5] if snapshots.size>=5 snapshots.insert(0, Snapshot.find(:first, - :conditions => ["project_id=? AND status=? AND scope=? AND qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier], + :conditions => ["component_uuid=? AND status=? AND scope=? AND qualifier=?", resource.uuid, STATUS_PROCESSED, resource.scope, resource.qualifier], :include => 'project', :order => 'snapshots.created_at ASC', :limit => 1)) snapshots.compact.uniq @@ -97,7 +97,7 @@ class Snapshot < ActiveRecord::Base end # Get 1rst & latests snapshots of the period - snapshot_conditions = ["snapshots.project_id=? AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.id, STATUS_PROCESSED, resource.scope, resource.qualifier] + snapshot_conditions = ["snapshots.component_uuid=? AND snapshots.status=? AND snapshots.scope=? AND snapshots.qualifier=?", resource.uuid, STATUS_PROCESSED, resource.scope, resource.qualifier] if options[:from] snapshot_conditions[0] += " AND snapshots.created_at>=?" snapshot_conditions << options[:from].to_i * 1000 @@ -196,9 +196,9 @@ class Snapshot < ActiveRecord::Base nil end - def self.snapshot_by_date(resource_id, date) - if resource_id && date - Snapshot.find(:first, :conditions => ['created_at>=? and created_at 'created_at desc') + def self.snapshot_by_date(resource_uuid, date) + if resource_uuid && date + Snapshot.find(:first, :conditions => ['created_at>=? and created_at 'created_at desc') else nil end @@ -209,7 +209,7 @@ class Snapshot < ActiveRecord::Base end def resource_id - project_id + project.id end def periods? @@ -217,7 +217,7 @@ class Snapshot < ActiveRecord::Base end def resource_id_for_authorization - root_project_id || project_id + root_project.id end def path_name diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/trends_chart.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/trends_chart.rb index 0780981546e..f681c28b3d7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/trends_chart.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/trends_chart.rb @@ -24,9 +24,9 @@ class TrendsChart sql= "select s.created_at as created_at, m.value as value, m.metric_id as metric_id, s.id as sid " + " from project_measures m LEFT OUTER JOIN snapshots s ON s.id=m.snapshot_id " + " where s.status=? " + - " and s.project_id=? " + + " and s.component_uuid=? " + " and m.metric_id in (?) " + - " and m.person_id is null" + " and m.person_id is null" if (options[:from]) sql += ' and s.created_at>=?' end @@ -34,7 +34,7 @@ class TrendsChart sql += ' and s.created_at<=?' end sql += ' order by s.created_at ASC' - conditions=[sql, Snapshot::STATUS_PROCESSED, resource.id, metric_ids] + conditions=[sql, Snapshot::STATUS_PROCESSED, resource.uuid, metric_ids] if (options[:from]) conditions< { ResourceDto resource = (ResourceDto) context.getResultObject(); @@ -96,7 +96,7 @@ public class ResourceIndexDao extends AbstractDao { .setNonIndexedOnly(false) .setQualifiers(RENAMABLE_QUALIFIERS) .setScopes(RENAMABLE_SCOPES) - .setRootProjectId(rootProjectId); + .setRootComponentUuid(rootProjectUuid); session.select(SELECT_RESOURCES, query, context -> { ResourceDto resource = (ResourceDto) context.getResultObject(); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java index 19b513375b3..589b9d3f58f 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java @@ -20,7 +20,7 @@ package org.sonar.db.component; final class ResourceIndexQuery { - private long rootProjectId; + private String rootComponentUuid; private String[] scopes = null; private String[] qualifiers = null; private boolean nonIndexedOnly = false; @@ -50,12 +50,12 @@ final class ResourceIndexQuery { return this; } - public long getRootProjectId() { - return rootProjectId; + public String getRootComponentUuid() { + return rootComponentUuid; } - public ResourceIndexQuery setRootProjectId(long i) { - this.rootProjectId = i; + public ResourceIndexQuery setRootComponentUuid(String rootComponentUuid) { + this.rootComponentUuid = rootComponentUuid; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java index 32ed246eada..a77f240dad3 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceMapper.java @@ -52,16 +52,6 @@ public interface ResourceMapper { */ void selectResources(ResourceQuery query, ResultHandler resultHandler); - /** - * @since 3.6 - */ - ResourceDto selectRootProjectByComponentKey(@Param("componentKey") String componentKey); - - /** - * @since 3.6 - */ - ResourceDto selectRootProjectByComponentId(@Param("componentId") long componentId); - List selectProjectsIncludingNotCompletedOnesByQualifiers(@Param("qualifiers") Collection qualifier); List selectProjectsByQualifiers(@Param("qualifiers") Collection qualifier); diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java index 2fd248d7c52..bacf8898f32 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java @@ -59,18 +59,14 @@ public class SnapshotDao implements Dao { } @CheckForNull - public SnapshotDto selectLastSnapshotByComponentId(DbSession session, long componentId) { - return mapper(session).selectLastSnapshot(componentId); + public SnapshotDto selectLastSnapshotByComponentUuid(DbSession session, String componentUuid) { + return mapper(session).selectLastSnapshot(componentUuid); } public boolean hasLastSnapshotByComponentUuid(DbSession session, String componentUUid) { return mapper(session).countLastSnapshotByComponentUuid(componentUUid) > 0; } - public List selectSnapshotsByComponentId(DbSession session, long componentId) { - return mapper(session).selectSnapshotsByQuery(new SnapshotQuery().setComponentId(componentId)); - } - public List selectSnapshotsByQuery(DbSession session, SnapshotQuery query) { return mapper(session).selectSnapshotsByQuery(query); } @@ -85,13 +81,13 @@ public class SnapshotDao implements Dao { return snapshotDtos.get(0); } - public List selectPreviousVersionSnapshots(DbSession session, long componentId, String lastVersion) { - return mapper(session).selectPreviousVersionSnapshots(componentId, lastVersion); + public List selectPreviousVersionSnapshots(DbSession session, String componentUuid, String lastVersion) { + return mapper(session).selectPreviousVersionSnapshots(componentUuid, lastVersion); } @CheckForNull - public SnapshotDto selectOldestSnapshot(DbSession session, long componentId) { - List snapshotDtos = mapper(session).selectOldestSnapshots(componentId, new RowBounds(0, 1)); + public SnapshotDto selectOldestSnapshot(DbSession session, String componentUuid) { + List snapshotDtos = mapper(session).selectOldestSnapshots(componentUuid, new RowBounds(0, 1)); return snapshotDtos.isEmpty() ? null : snapshotDtos.get(0); } @@ -130,18 +126,16 @@ public class SnapshotDao implements Dao { insert(session, Lists.asList(item, others)); } + /** + * Used by Governance + */ @CheckForNull - public ViewsSnapshotDto selectSnapshotBefore(long componentId, long date, DbSession dbSession) { - return from(mapper(dbSession).selectSnapshotBefore(componentId, date)) + public ViewsSnapshotDto selectSnapshotBefore(String componentUuid, long date, DbSession dbSession) { + return from(mapper(dbSession).selectSnapshotBefore(componentUuid, date)) .first() .orNull(); } - @CheckForNull - public ViewsSnapshotDto selectLatestSnapshot(long componentId, DbSession dbSession) { - return mapper(dbSession).selectLatestSnapshot(componentId); - } - private static SnapshotMapper mapper(DbSession session) { return session.getMapper(SnapshotMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java index 74c66297dbd..a70f75b0e77 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java @@ -35,11 +35,12 @@ public final class SnapshotDto { private Long id; private Long parentId; private Long rootId; - private Long rootProjectId; + + private String rootComponentUuid; + private String componentUuid; private Long createdAt; private Long buildDate; - private Long componentId; private String status = STATUS_UNPROCESSED; private Integer purgeStatus; private Boolean last; @@ -108,12 +109,21 @@ public final class SnapshotDto { return this; } - public Long getComponentId() { - return componentId; + public String getRootComponentUuid() { + return rootComponentUuid; + } + + public SnapshotDto setRootComponentUuid(String rootComponentUuid) { + this.rootComponentUuid = rootComponentUuid; + return this; + } + + public String getComponentUuid() { + return componentUuid; } - public SnapshotDto setComponentId(Long componentId) { - this.componentId = componentId; + public SnapshotDto setComponentUuid(String componentUuid) { + this.componentUuid = componentUuid; return this; } @@ -198,15 +208,6 @@ public final class SnapshotDto { return this; } - public Long getRootProjectId() { - return rootProjectId; - } - - public SnapshotDto setRootProjectId(Long rootProjectId) { - this.rootProjectId = rootProjectId; - return this; - } - public SnapshotDto setPeriodMode(int index, @Nullable String p) { switch (index) { case 1: diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDtoFunctions.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDtoFunctions.java index 67d3e10897a..3e79e7b7f05 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDtoFunctions.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDtoFunctions.java @@ -27,8 +27,8 @@ public class SnapshotDtoFunctions { return ToId.INSTANCE; } - public static Function toComponentId() { - return ToComponentId.INSTANCE; + public static Function toComponentUuid() { + return SnapshotDto::getComponentUuid; } private enum ToId implements Function { @@ -40,14 +40,4 @@ public class SnapshotDtoFunctions { } } - private enum ToComponentId implements Function { - INSTANCE; - - @Override - public Long apply(@Nonnull SnapshotDto input) { - return input.getComponentId(); - } - } - - } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java index b8a0ff6bab9..2082e241f7c 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java @@ -34,28 +34,24 @@ public interface SnapshotMapper { void insert(SnapshotDto snapshot); @CheckForNull - SnapshotDto selectLastSnapshot(Long resourceId); + SnapshotDto selectLastSnapshot(@Param("componentUuid") String componentUuid); int countLastSnapshotByComponentUuid(String componentUuid); - @CheckForNull - SnapshotDto selectLastSnapshotByComponentUuid(String componentUuid); - List selectSnapshotsByQuery(@Param("query") SnapshotQuery query); - List selectPreviousVersionSnapshots(@Param(value = "componentId") Long componentId, @Param(value = "lastVersion") String lastVersion); + List selectPreviousVersionSnapshots(@Param("componentUuid") String componentUuid, @Param("lastVersion") String lastVersion); - List selectOldestSnapshots(@Param(value = "componentId") Long componentId, RowBounds rowBounds); + List selectOldestSnapshots(@Param("componentUuid") String componentUuid, RowBounds rowBounds); - List selectSnapshotAndChildrenOfScope(@Param(value = "snapshot") Long resourceId, @Param(value = "scope") String scope); + List selectSnapshotAndChildrenOfScope(@Param("snapshot") Long resourceId, @Param("scope") String scope); - int updateSnapshotAndChildrenLastFlagAndStatus(@Param(value = "root") Long rootId, @Param(value = "pathRootId") Long pathRootId, - @Param(value = "path") String path, @Param(value = "isLast") boolean isLast, @Param(value = "status") String status); + int updateSnapshotAndChildrenLastFlagAndStatus(@Param("root") Long rootId, @Param("pathRootId") Long pathRootId, + @Param("path") String path, @Param("isLast") boolean isLast, @Param("status") String status); - int updateSnapshotAndChildrenLastFlag(@Param(value = "root") Long rootId, @Param(value = "pathRootId") Long pathRootId, - @Param(value = "path") String path, @Param(value = "isLast") boolean isLast); + int updateSnapshotAndChildrenLastFlag(@Param("root") Long rootId, @Param("pathRootId") Long pathRootId, + @Param("path") String path, @Param("isLast") boolean isLast); - List selectSnapshotBefore(@Param("componentId") long componentId, @Param("date") long date); + List selectSnapshotBefore(@Param("componentUuid") String componentUuid, @Param("date") long date); - ViewsSnapshotDto selectLatestSnapshot(@Param("componentId") long componentId); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java index d06492d6afe..fca78966f8c 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java @@ -42,7 +42,6 @@ public final class SnapshotQuery { } } - private Long componentId; private String componentUuid; private Long createdAfter; private Long createdBefore; @@ -90,16 +89,6 @@ public final class SnapshotQuery { return this; } - @CheckForNull - public Long getComponentId() { - return componentId; - } - - public SnapshotQuery setComponentId(@Nullable Long componentId) { - this.componentId = componentId; - return this; - } - @CheckForNull public String getComponentUuid() { return componentUuid; diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java index 214e07aef30..8dd3c515c92 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -61,8 +61,8 @@ class PurgeCommands { // voluntarily grouped by tables in order to benefit from JDBC batch mode. // Batch requests can only relate to the same PreparedStatement. - for (List partResourceIds : componentIdPartitions) { - deleteSnapshots(purgeMapper.selectSnapshotIdsByResource(partResourceIds)); + for (List componentUuidPartition : componentUuidsPartitions) { + deleteSnapshots(purgeMapper.selectSnapshotIdsByResource(componentUuidPartition)); } // possible missing optimization: filter requests according to resource scope diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java index 9d265f0ebda..403b991e530 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -103,14 +103,14 @@ public class PurgeDao implements Dao { PurgeSnapshotQuery query = PurgeSnapshotQuery.create() .setIslast(false) .setStatus(UNPROCESSED_STATUS) - .setRootProjectId(project.getId()); + .setRootComponentUuid(project.getUuid()); commands.deleteSnapshots(query); } private static void purge(ResourceDto project, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { List projectSnapshotIds = purgeCommands.selectSnapshotIds( PurgeSnapshotQuery.create() - .setResourceId(project.getId()) + .setComponentUuid(project.getUuid()) .setIslast(false) .setNotPurged(true)); for (Long projectSnapshotId : projectSnapshotIds) { @@ -148,19 +148,19 @@ public class PurgeDao implements Dao { session.commit(); } - public List selectPurgeableSnapshots(long resourceId) { + public List selectPurgeableSnapshots(String componentUuid) { DbSession session = mybatis.openSession(true); try { - return selectPurgeableSnapshots(resourceId, session); + return selectPurgeableSnapshots(componentUuid, session); } finally { MyBatis.closeQuietly(session); } } - public List selectPurgeableSnapshots(long resourceId, DbSession session) { + public List selectPurgeableSnapshots(String componentUuid, DbSession session) { List result = Lists.newArrayList(); - result.addAll(mapper(session).selectPurgeableSnapshotsWithEvents(resourceId)); - result.addAll(mapper(session).selectPurgeableSnapshotsWithoutEvents(resourceId)); + result.addAll(mapper(session).selectPurgeableSnapshotsWithEvents(componentUuid)); + result.addAll(mapper(session).selectPurgeableSnapshotsWithoutEvents(componentUuid)); // sort by date Collections.sort(result); return result; @@ -181,11 +181,10 @@ public class PurgeDao implements Dao { } private void disableResource(IdUuidPair componentIdUuid, PurgeMapper mapper) { - long componentId = componentIdUuid.getId(); mapper.deleteResourceIndex(Arrays.asList(componentIdUuid.getUuid())); - mapper.setSnapshotIsLastToFalse(componentId); + mapper.setSnapshotIsLastToFalse(componentIdUuid.getUuid()); mapper.deleteFileSourcesByUuid(componentIdUuid.getUuid()); - mapper.disableResource(componentId); + mapper.disableResource(componentIdUuid.getId()); mapper.resolveResourceIssuesNotAlreadyResolved(componentIdUuid.getUuid(), system2.now()); } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java index bf3c97cc6dc..d0f63fe332b 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -27,7 +27,7 @@ public interface PurgeMapper { List selectSnapshotIds(PurgeSnapshotQuery query); - List selectSnapshotIdsByResource(@Param("resourceIds") List resourceIds); + List selectSnapshotIdsByResource(@Param("componentUuids") List componentUuids); /** * Returns the list of components of a project from a project_uuid. The project itself is also returned. @@ -56,7 +56,7 @@ public interface PurgeMapper { void deleteEvent(long eventId); - void setSnapshotIsLastToFalse(long resourceId); + void setSnapshotIsLastToFalse(@Param("componentUuid") String componentUuid); void deleteResourceLinks(@Param("componentUuids") List componentUuids); @@ -74,9 +74,9 @@ public interface PurgeMapper { void deleteAuthors(@Param("resourceIds") List resourceIds); - List selectPurgeableSnapshotsWithEvents(long resourceId); + List selectPurgeableSnapshotsWithEvents(@Param("componentUuid") String componentUuid); - List selectPurgeableSnapshotsWithoutEvents(long resourceId); + List selectPurgeableSnapshotsWithoutEvents(@Param("componentUuid") String componentUuid); void deleteComponentIssueChanges(@Param("componentUuids") List componentUuids); diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java index 2827ddd0296..52dc9dc42e7 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java @@ -21,9 +21,9 @@ package org.sonar.db.purge; public final class PurgeSnapshotQuery { private Long id; - private Long rootProjectId; + private String rootComponentUuid; private Long rootSnapshotId; - private Long resourceId; + private String componentUuid; private String[] scopes; private String[] qualifiers; private String[] status; @@ -47,12 +47,12 @@ public final class PurgeSnapshotQuery { return this; } - public Long getRootProjectId() { - return rootProjectId; + public String getRootComponentUuid() { + return rootComponentUuid; } - public PurgeSnapshotQuery setRootProjectId(Long rootProjectId) { - this.rootProjectId = rootProjectId; + public PurgeSnapshotQuery setRootComponentUuid(String rootComponentUuid) { + this.rootComponentUuid = rootComponentUuid; return this; } @@ -110,12 +110,12 @@ public final class PurgeSnapshotQuery { return this; } - public Long getResourceId() { - return resourceId; + public String getComponentUuid() { + return componentUuid; } - public PurgeSnapshotQuery setResourceId(Long l) { - this.resourceId = l; + public PurgeSnapshotQuery setComponentUuid(String componentUuid) { + this.componentUuid = componentUuid; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java b/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java index ac65ae2247a..26de4acd902 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/period/DefaultPeriodCleaner.java @@ -42,13 +42,13 @@ public class DefaultPeriodCleaner { this.profiler = profiler; } - public void clean(DbSession session, long projectId, Settings settings) { - doClean(projectId, new Filters(settings).all(), session); + public void clean(DbSession session, String componentUuid, Settings settings) { + doClean(componentUuid, new Filters(settings).all(), session); } @VisibleForTesting - void doClean(long projectId, List filters, DbSession session) { - List history = selectProjectSnapshots(projectId, session); + void doClean(String componentUuid, List filters, DbSession session) { + List history = selectProjectSnapshots(componentUuid, session); for (Filter filter : filters) { filter.log(); delete(filter.filter(history), session); @@ -65,7 +65,7 @@ public class DefaultPeriodCleaner { } } - private List selectProjectSnapshots(long resourceId, DbSession session) { - return purgeDao.selectPurgeableSnapshots(resourceId, session); + private List selectProjectSnapshots(String componentUuid, DbSession session) { + return purgeDao.selectPurgeableSnapshots(componentUuid, session); } } diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index afe8e015818..297f5a037e1 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -348,7 +348,7 @@ from projects p - inner join snapshots s on p.id = s.project_id + inner join snapshots s on p.uuid = s.component_uuid where p.enabled=${_true} @@ -443,7 +443,7 @@ - left join snapshots s on s.project_id=p.id + left join snapshots s on s.component_uuid=p.uuid where s.id is null and p.enabled=${_true} @@ -471,8 +471,8 @@ - inner join snapshots s1 on s1.project_id = p.id and s1.status='U' - left join snapshots s2 on s2.project_id = p.id and s2.status='P' + inner join snapshots s1 on s1.component_uuid = p.uuid and s1.status='U' + left join snapshots s2 on s2.component_uuid = p.uuid and s2.status='P' where s2.id is null and p.qualifier=#{qualifier} diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml index 15c1c98568c..de993ded498 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml @@ -24,7 +24,7 @@ p.enabled=${_true} and p.copy_resource_id is null - and p.id=s.project_id + and p.uuid=s.component_uuid and s.islast=${_true} and p.scope in @@ -35,13 +35,13 @@ #{qualifier} - - and s.root_project_id=#{rootProjectId} + + and s.root_component_uuid=#{rootComponentUuid} and not exists(select * from resource_index ri where ri.component_uuid=p.uuid) - and root.id = s.root_project_id + and root.uuid = s.root_component_uuid order by p.id diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml index 0816902334c..ef0fce32d24 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceMapper.xml @@ -9,7 +9,7 @@ - + @@ -18,7 +18,7 @@ - + @@ -111,7 +111,7 @@ SELECT s.* from snapshots s - INNER JOIN projects p on p.id=s.project_id AND p.enabled=${_true} AND p.copy_resource_id IS NULL + INNER JOIN projects p on p.uuid=s.component_uuid AND p.enabled=${_true} AND p.copy_resource_id IS NULL AND p.uuid=#{uuid} AND s.islast=${_true} @@ -137,25 +137,6 @@ - - - - select distinct p.* from projects p - inner join snapshots s1 on s1.project_id = p.id and s1.status='U' - left join snapshots s2 on s2.project_id = p.id and s2.status='P' + inner join snapshots s1 on s1.component_uuid = p.uuid and s1.status='U' + left join snapshots s2 on s2.component_uuid = p.uuid and s2.status='P' and s2.id is null @@ -208,7 +189,7 @@ select p.* from projects p - left join snapshots s on s.project_id=p.id + left join snapshots s on s.component_uuid=p.uuid where s.id is null and p.kee = #{key} and p.copy_resource_id is null diff --git a/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml index 1cc4b2aff96..1b9704deddc 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml @@ -6,8 +6,8 @@ s.id, s.parent_snapshot_id as parentId, s.root_snapshot_id as rootId, - s.root_project_id as rootProjectId, - s.project_id as componentId, + s.root_component_uuid as rootComponentUuid, + s.component_uuid as componentUuId, s.created_at as createdAt, s.build_date as buildDate, s.status as status, @@ -64,14 +64,14 @@ select from snapshots s - where s.islast=${_true} and s.project_id = #{resource} + where s.islast=${_true} and s.component_uuid = #{componentUuid} @@ -81,12 +81,9 @@ FROM snapshots s - INNER JOIN projects p ON p.id=s.project_id AND p.uuid=#{query.componentUuid} AND p.enabled=${_true} + INNER JOIN projects p ON p.uuid=s.component_uuid AND p.enabled=${_true} AND s.component_uuid=#{query.componentUuid} - - AND s.project_id=#{query.componentId} - AND s.scope=#{query.scope} @@ -129,7 +126,7 @@ FROM snapshots s INNER JOIN events e ON s.id = e.snapshot_id AND e.name <> #{lastVersion} AND e.category='Version' - s.project_id=#{componentId} + s.component_uuid=#{componentUuid} ORDER BY e.event_date DESC @@ -139,7 +136,7 @@ FROM snapshots s - s.project_id=#{componentId} + s.component_uuid=#{componentUuid} ORDER BY s.created_at ASC @@ -157,26 +154,15 @@ FROM snapshots s - and s.project_id = #{componentId} + and s.component_uuid = #{componentUuid} and s.status = 'P' and s.created_at < #{date} order by created_at desc - - - (parent_snapshot_id, root_snapshot_id, root_project_id, project_id, created_at, build_date, status, purge_status, + (parent_snapshot_id, root_snapshot_id, root_component_uuid, component_uuid, created_at, build_date, status, purge_status, islast, scope, qualifier, version, path, depth, period1_mode, period2_mode, period3_mode, period4_mode, period5_mode, period1_param, period2_param, period3_param, period4_param, period5_param, @@ -198,7 +184,7 @@ insert into snapshots - values (#{parentId}, #{rootId}, #{rootProjectId}, #{componentId}, #{createdAt}, #{buildDate}, #{status}, + values (#{parentId}, #{rootId}, #{rootComponentUuid}, #{componentUuid}, #{createdAt}, #{buildDate}, #{status}, #{purgeStatus}, #{last}, #{scope}, #{qualifier}, #{version}, #{path}, #{depth}, #{period1Mode}, #{period2Mode}, #{period3Mode}, #{period4Mode}, #{period5Mode}, #{period1Param}, #{period2Param}, #{period3Param}, #{period4Param}, #{period5Param}, diff --git a/sonar-db/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml index af67fef0584..b1ce10e4069 100644 --- a/sonar-db/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml @@ -15,7 +15,7 @@ file_component.kee as componentKey FROM duplications_index duplication_block INNER JOIN snapshots snapshot ON duplication_block.snapshot_id=snapshot.id AND snapshot.islast=${_true} - INNER JOIN projects file_component ON file_component.id=snapshot.project_id AND file_component.language=#{language} + INNER JOIN projects file_component ON file_component.uuid=snapshot.component_uuid AND file_component.language=#{language} AND file_component.enabled=${_true} AND duplication_block.hash in diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index eb938f119ba..90c5a3dde46 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -29,7 +29,7 @@ FROM project_measures pm INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true} - INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true} + INNER JOIN projects p ON p.uuid=s.component_uuid AND p.enabled=${_true} INNER JOIN metrics metric ON metric.id=pm.metric_id AND p.kee = #{componentKey} @@ -43,7 +43,7 @@ FROM project_measures pm INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true} - INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true} + INNER JOIN projects p ON p.uuid=s.component_uuid AND p.enabled=${_true} INNER JOIN metrics metric ON metric.id=pm.metric_id AND p.kee = #{componentKey} @@ -115,9 +115,10 @@ select s.id from snapshots s - s.project_id in - - #{resourceId} + s.component_uuid in + + #{componentUuid} - select s.id as "snapshotId", s.created_at as "date", ${_true} as "hasEvents", islast as "isLast" from snapshots s where - s.project_id=#{id} and s.status='P' and s.qualifier <> 'LIB' and + s.component_uuid=#{componentUuid} and s.status='P' and s.qualifier <> 'LIB' and exists(select e.id from events e where e.snapshot_id=s.id) - select s.id as "snapshotId", s.created_at as "date", ${_false} as "hasEvents", islast as "isLast" from snapshots s where - s.project_id=#{id} and s.status='P' and s.qualifier <> 'LIB' and + s.component_uuid=#{componentUuid} and s.status='P' and s.qualifier <> 'LIB' and not exists(select e.id from events e where e.snapshot_id=s.id)