From: Simon Brandhof Date: Thu, 16 Jun 2016 16:20:36 +0000 (+0200) Subject: SONAR-7779 Add column UUID to table SNAPSHOTS X-Git-Tag: 6.0-RC1~283 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9865eac69141d22968f060bfb3bbadba8c9bacbf;p=sonarqube.git SONAR-7779 Add column UUID to table SNAPSHOTS --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolder.java index 93565cabbd3..020c1dd7fd0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolder.java @@ -25,6 +25,13 @@ import org.sonar.server.computation.qualityprofile.QualityProfile; import org.sonar.server.computation.snapshot.Snapshot; public interface AnalysisMetadataHolder { + + /** + * Returns the UUID generated for this analysis. + * @throws IllegalStateException if uuid has not been set + */ + String getUuid(); + /** * @throws IllegalStateException if no analysis date has been set */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImpl.java index 003d0c7509f..e13cc9ec850 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImpl.java @@ -31,17 +31,26 @@ import static com.google.common.base.Preconditions.checkState; public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder { - private InitializedProperty analysisDate = new InitializedProperty<>(); + private final InitializedProperty uuid = new InitializedProperty<>(); - private InitializedProperty baseProjectSnapshot = new InitializedProperty<>(); + private final InitializedProperty analysisDate = new InitializedProperty<>(); - private InitializedProperty crossProjectDuplicationEnabled = new InitializedProperty<>(); + private final InitializedProperty baseProjectSnapshot = new InitializedProperty<>(); - private InitializedProperty branch = new InitializedProperty<>(); + private final InitializedProperty crossProjectDuplicationEnabled = new InitializedProperty<>(); - private InitializedProperty rootComponentRef = new InitializedProperty<>(); + private final InitializedProperty branch = new InitializedProperty<>(); - private InitializedProperty> qProfilesPerLanguage = new InitializedProperty<>(); + private final InitializedProperty rootComponentRef = new InitializedProperty<>(); + + private final InitializedProperty> qProfilesPerLanguage = new InitializedProperty<>(); + + @Override + public MutableAnalysisMetadataHolder setUuid(String s) { + checkState(!uuid.isInitialized(), "Analysis uuid has already been set"); + this.uuid.setProperty(s); + return this; + } @Override public MutableAnalysisMetadataHolder setAnalysisDate(long date) { @@ -50,6 +59,12 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder return this; } + @Override + public String getUuid() { + checkState(uuid.isInitialized(), "Analysis uuid has not been set"); + return this.uuid.getProperty(); + } + @Override public long getAnalysisDate() { checkState(analysisDate.isInitialized(), "Analysis date has not been set"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolder.java index 20326ee5ec1..c9eb49425ec 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolder.java @@ -26,6 +26,11 @@ import org.sonar.server.computation.snapshot.Snapshot; public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder { + /** + * @throws IllegalStateException if the analysis uuid has already been set + */ + MutableAnalysisMetadataHolder setUuid(String uuid); + /** * @throws IllegalStateException if the analysis date has already been set */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/GenerateAnalysisUuid.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/GenerateAnalysisUuid.java new file mode 100644 index 00000000000..2140b9e4748 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/GenerateAnalysisUuid.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.computation.step; + +import org.sonar.core.util.UuidFactory; +import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder; + +public class GenerateAnalysisUuid implements ComputationStep { + + private final UuidFactory uuidFactory; + private final MutableAnalysisMetadataHolder analysisMetadataHolder; + + public GenerateAnalysisUuid(UuidFactory uuidFactory, MutableAnalysisMetadataHolder analysisMetadataHolder) { + this.uuidFactory = uuidFactory; + this.analysisMetadataHolder = analysisMetadataHolder; + } + + @Override + public void execute() { + analysisMetadataHolder.setUuid(uuidFactory.create()); + } + + @Override + public String getDescription() { + return "Generate analysis UUID"; + } +} 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 3e2deea6419..5bd0b00489d 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 @@ -24,6 +24,7 @@ import javax.annotation.Nullable; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; +import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.SnapshotDto; @@ -92,48 +93,48 @@ public class PersistSnapshotsStep implements ComputationStep { @Override public void visitProject(Component project, Path path) { this.rootUuid = project.getUuid(); - SnapshotDto snapshot = createSnapshot(project, path, Qualifiers.PROJECT, Scopes.PROJECT, true); + SnapshotDto snapshot = createSnapshot(analysisMetadataHolder.getUuid(), project, path, Qualifiers.PROJECT, Scopes.PROJECT, true); updateSnapshotPeriods(snapshot); commonForAnyVisit(project, path, snapshot); } @Override public void visitModule(Component module, Path path) { - SnapshotDto snapshot = createSnapshot(module, path, Qualifiers.MODULE, Scopes.PROJECT, true); + SnapshotDto snapshot = createSnapshot(Uuids.create(), module, path, Qualifiers.MODULE, Scopes.PROJECT, true); updateSnapshotPeriods(snapshot); commonForAnyVisit(module, path, snapshot); } @Override public void visitDirectory(Component directory, Path path) { - SnapshotDto snapshot = createSnapshot(directory, path, Qualifiers.DIRECTORY, Scopes.DIRECTORY, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), directory, path, Qualifiers.DIRECTORY, Scopes.DIRECTORY, false); commonForAnyVisit(directory, path, snapshot); } @Override public void visitFile(Component file, Path path) { - SnapshotDto snapshot = createSnapshot(file, path, getFileQualifier(file), Scopes.FILE, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), file, path, getFileQualifier(file), Scopes.FILE, false); commonForAnyVisit(file, path, snapshot); } @Override public void visitView(Component view, Path path) { this.rootUuid = view.getUuid(); - SnapshotDto snapshot = createSnapshot(view, path, Qualifiers.VIEW, Scopes.PROJECT, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), view, path, Qualifiers.VIEW, Scopes.PROJECT, false); updateSnapshotPeriods(snapshot); commonForAnyVisit(view, path, snapshot); } @Override public void visitSubView(Component subView, Path path) { - SnapshotDto snapshot = createSnapshot(subView, path, Qualifiers.SUBVIEW, Scopes.PROJECT, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), subView, path, Qualifiers.SUBVIEW, Scopes.PROJECT, false); updateSnapshotPeriods(snapshot); commonForAnyVisit(subView, path, snapshot); } @Override public void visitProjectView(Component projectView, Path path) { - SnapshotDto snapshot = createSnapshot(projectView, path, Qualifiers.PROJECT, Scopes.FILE, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), projectView, path, Qualifiers.PROJECT, Scopes.FILE, false); updateSnapshotPeriods(snapshot); commonForAnyVisit(projectView, path, snapshot); } @@ -155,10 +156,11 @@ public class PersistSnapshotsStep implements ComputationStep { } } - private SnapshotDto createSnapshot(Component component, Path path, + private SnapshotDto createSnapshot(String snapshotUuid, Component component, Path path, String qualifier, String scope, boolean setVersion) { String componentUuid = component.getUuid(); SnapshotDto snapshotDto = new SnapshotDto() + .setUuid(snapshotUuid) .setRootComponentUuid(rootUuid) .setVersion(setVersion ? component.getReportAttributes().getVersion() : null) .setComponentUuid(componentUuid) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java index fc066ff22f3..fa6c1a570bc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java @@ -38,6 +38,7 @@ public class ReportComputationSteps extends AbstractComputationSteps { private static final List> STEPS = Arrays.asList( ExtractReportStep.class, LogScannerContextStep.class, + GenerateAnalysisUuid.class, // Builds Component tree LoadReportAnalysisMetadataHolderStep.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderRule.java index ae79537f57e..c87cf4bcc4a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderRule.java @@ -31,19 +31,34 @@ import org.sonar.server.computation.util.InitializedProperty; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -public class AnalysisMetadataHolderRule extends ExternalResource implements AnalysisMetadataHolder { +public class AnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder { - private InitializedProperty analysisDate = new InitializedProperty<>(); + private final InitializedProperty uuid = new InitializedProperty<>(); - private InitializedProperty baseProjectSnapshot = new InitializedProperty<>(); + private final InitializedProperty analysisDate = new InitializedProperty<>(); - private InitializedProperty crossProjectDuplicationEnabled = new InitializedProperty<>(); + private final InitializedProperty baseProjectSnapshot = new InitializedProperty<>(); - private InitializedProperty branch = new InitializedProperty<>(); + private final InitializedProperty crossProjectDuplicationEnabled = new InitializedProperty<>(); - private InitializedProperty rootComponentRef = new InitializedProperty<>(); + private final InitializedProperty branch = new InitializedProperty<>(); - private InitializedProperty> qProfilesPerLanguage = new InitializedProperty<>(); + private final InitializedProperty rootComponentRef = new InitializedProperty<>(); + + private final InitializedProperty> qProfilesPerLanguage = new InitializedProperty<>(); + + @Override + public String getUuid() { + checkState(uuid.isInitialized(), "Analysis UUID has not been set"); + return this.uuid.getProperty(); + } + + @Override + public AnalysisMetadataHolderRule setUuid(String s) { + checkNotNull(s, "UUID must not be null"); + this.uuid.setProperty(s); + return this; + } public AnalysisMetadataHolderRule setAnalysisDate(Date date) { checkNotNull(date, "Date must not be null"); @@ -51,6 +66,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return this; } + @Override public AnalysisMetadataHolderRule setAnalysisDate(long date) { checkNotNull(date, "Date must not be null"); this.analysisDate.setProperty(date); @@ -68,6 +84,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return getBaseProjectSnapshot() == null; } + @Override public AnalysisMetadataHolderRule setBaseProjectSnapshot(@Nullable Snapshot baseProjectSnapshot) { this.baseProjectSnapshot.setProperty(baseProjectSnapshot); return this; @@ -80,6 +97,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return baseProjectSnapshot.getProperty(); } + @Override public AnalysisMetadataHolderRule setCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) { this.crossProjectDuplicationEnabled.setProperty(isCrossProjectDuplicationEnabled); return this; @@ -91,6 +109,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return crossProjectDuplicationEnabled.getProperty(); } + @Override public AnalysisMetadataHolderRule setBranch(@Nullable String branch) { this.branch.setProperty(branch); return this; @@ -102,6 +121,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return branch.getProperty(); } + @Override public AnalysisMetadataHolderRule setRootComponentRef(int rootComponentRef) { this.rootComponentRef.setProperty(rootComponentRef); return this; @@ -113,6 +133,7 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Anal return rootComponentRef.getProperty(); } + @Override public AnalysisMetadataHolderRule setQProfilesByLanguage(Map qProfilesPerLanguage) { this.qProfilesPerLanguage.setProperty(qProfilesPerLanguage); return this; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolderRule.java index bc187d8469c..065eed1bd81 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolderRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolderRule.java @@ -35,6 +35,16 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen delegate = new AnalysisMetadataHolderImpl(); } + @Override + public String getUuid() { + return delegate.getUuid(); + } + + public MutableAnalysisMetadataHolderRule setUuid(String s) { + delegate.setUuid(s); + return this; + } + @Override public long getAnalysisDate() { return delegate.getAnalysisDate(); 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 9517ebb1390..fe52addb475 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 @@ -51,6 +51,7 @@ import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PRE public class ReportPersistSnapshotsStepTest extends BaseStepTest { private static final String PROJECT_KEY = "PROJECT_KEY"; + private static final String ANALYSIS_UUID = "U1"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -76,6 +77,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { @Before public void setup() { analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime(); + analysisMetadataHolder.setUuid(ANALYSIS_UUID); analysisMetadataHolder.setAnalysisDate(analysisDate); dbIdsRepository = new DbIdsRepositoryImpl(); 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 26f66cad5b6..9d1cc1bd61c 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 @@ -55,6 +55,7 @@ import static org.sonar.server.computation.component.ComponentFunctions.toKey; public class ViewsPersistSnapshotsStepTest extends BaseStepTest { private static final int PROJECT_KEY = 1; + private static final String ANALYSIS_UUID = "U1"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -83,6 +84,7 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { @Before public void setup() { analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime(); + analysisMetadataHolder.setUuid(ANALYSIS_UUID); analysisMetadataHolder.setAnalysisDate(analysisDate); now = DateUtils.parseDateQuietly("2015-06-02").getTime(); 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 e9e9f3fe160..4a8d382e41b 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 @@ -147,8 +147,15 @@ public class ComponentNavigationActionTest { ComponentDto project = ComponentTesting.newProjectDto("abcd") .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()).setComponentUuid(project.uuid()).setRootComponentUuid(project.uuid()).setScope(project.scope())); + dbClient.snapshotDao().insert(dbTester.getSession(), new SnapshotDto() + .setUuid("u1") + .setCreatedAt(snapshotDate.getTime()) + .setVersion("3.14") + .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/activity/ActivityManagerTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml index 2ac38c2fb0b..3e4fda90137 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml @@ -1,7 +1,9 @@ - - - - - + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml index b89e3fcd691..cbe40829665 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml @@ -22,10 +22,14 @@ enabled="true"/> - - 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 b984a948a37..ee0040b86c3 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 @@ -4,7 +4,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml index ab190db883e..60d27b9ae4b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml @@ -1,7 +1,11 @@ - + - + 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 a1508445b14..a8b95ef4769 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,10 @@ - - + + 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 ab190db883e..60d27b9ae4b 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,11 @@ - + - + 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 918d755636a..fb18192c216 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,14 @@ - + - + - - - - - - - - - - - - - - - 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 d96e1157ea0..0683f90d6b6 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,18 @@ - - @@ -18,13 +22,17 @@ - - @@ -32,14 +40,18 @@ - - @@ -47,7 +59,9 @@ - @@ -57,7 +71,9 @@ - @@ -65,7 +81,9 @@ - diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_component_uuid_columns_to_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_component_uuid_columns_to_snapshots.rb new file mode 100644 index 00000000000..d79d4828646 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_component_uuid_columns_to_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class AddComponentUuidColumnsToSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_uuid_columns_to_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_uuid_columns_to_snapshots.rb deleted file mode 100644 index 5d635c18624..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1208_add_uuid_columns_to_snapshots.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -# -# SonarQube 6.0 -# -class AddUuidColumnsToSnapshots < ActiveRecord::Migration - - def self.up - execute_java_migration('org.sonar.db.version.v60.AddUuidColumnsToSnapshots') - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_component_uuid_columns_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_component_uuid_columns_of_snapshots.rb new file mode 100644 index 00000000000..6bd9447b4dd --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_component_uuid_columns_of_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class PopulateComponentUuidColumnsOfSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.PopulateComponentUuidColumnsOfSnapshots') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_uuid_columns_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_uuid_columns_of_snapshots.rb deleted file mode 100644 index 6ca6a0d56fa..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1209_populate_uuid_columns_of_snapshots.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -# -# SonarQube 6.0 -# -class PopulateUuidColumnsOfSnapshots < ActiveRecord::Migration - - def self.up - execute_java_migration('org.sonar.db.version.v60.PopulateUuidColumnsOfSnapshots') - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_component_uuid_columns_not_null_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_component_uuid_columns_not_null_on_snapshots.rb new file mode 100644 index 00000000000..29c328e6aeb --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_component_uuid_columns_not_null_on_snapshots.rb @@ -0,0 +1,32 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class MakeComponentUuidColumnsNotNullOnSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.MakeComponentUuidColumnsNotNullOnSnapshots') + + add_index :snapshots, :component_uuid, :name => 'snapshot_component' + add_index :snapshots, :root_component_uuid, :name => 'snapshot_root_component' + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_uuid_columns_not_null_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_uuid_columns_not_null_on_snapshots.rb deleted file mode 100644 index a214efc765c..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1211_make_uuid_columns_not_null_on_snapshots.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -# -# SonarQube 6.0 -# -class MakeUuidColumnsNotNullOnSnapshots < ActiveRecord::Migration - - def self.up - execute_java_migration('org.sonar.db.version.v60.MakeUuidColumnsNotNullOnSnapshots') - - add_index :snapshots, :component_uuid, :name => 'snapshot_component' - add_index :snapshots, :root_component_uuid, :name => 'snapshot_root_component' - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_add_uuid_column_to_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_add_uuid_column_to_snapshots.rb new file mode 100644 index 00000000000..10d61c8e83e --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_add_uuid_column_to_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class AddUuidColumnToSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.AddUuidColumnToSnapshots') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_populate_uuid_column_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_populate_uuid_column_on_snapshots.rb new file mode 100644 index 00000000000..fe409fe9b39 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_populate_uuid_column_on_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class PopulateUuidColumnOnSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.PopulateUuidColumnOnSnapshots') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_make_uuid_column_not_null_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_make_uuid_column_not_null_on_snapshots.rb new file mode 100644 index 00000000000..d7baeef61cd --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_make_uuid_column_not_null_on_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class MakeUuidColumnNotNullOnSnapshots < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.MakeUuidColumnNotNullOnSnapshots') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_add_unique_index_on_uuid_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_add_unique_index_on_uuid_of_snapshots.rb new file mode 100644 index 00000000000..5a66c1d7759 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_add_unique_index_on_uuid_of_snapshots.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 6.0 +# +class AddUniqueIndexOnUuidOfSnapshots < ActiveRecord::Migration + + def self.up + add_index :snapshots, :uuid, :name => 'analyses_uuid', :unique => true + end +end 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 a70f75b0e77..21d281278c3 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,6 +35,7 @@ public final class SnapshotDto { private Long id; private Long parentId; private Long rootId; + private String uuid; private String rootComponentUuid; private String componentUuid; @@ -77,6 +78,15 @@ public final class SnapshotDto { return this; } + public SnapshotDto setUuid(String s) { + this.uuid = s; + return this; + } + + public String getUuid() { + return this.uuid; + } + @CheckForNull public Long getParentId() { return parentId; diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 887c87f8cfc..9285480a569 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1_227; + public static final int LAST_VERSION = 1_231; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 07a5e5d79f7..521436d1597 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -84,9 +84,10 @@ import org.sonar.db.version.v55.FeedRulesTypes; import org.sonar.db.version.v56.FixLengthOfIssuesMessageOnOracle; import org.sonar.db.version.v56.FixTypeOfRuleTypeOnMysql; import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures; +import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots; +import org.sonar.db.version.v60.AddUuidColumnToSnapshots; import org.sonar.db.version.v60.AddUuidColumnsToProjects; import org.sonar.db.version.v60.AddUuidColumnsToResourceIndex; -import org.sonar.db.version.v60.AddUuidColumnsToSnapshots; import org.sonar.db.version.v60.CleanOrphanRowsInProjects; import org.sonar.db.version.v60.CleanOrphanRowsInResourceIndex; import org.sonar.db.version.v60.CleanOrphanRowsInSnapshots; @@ -97,14 +98,16 @@ import org.sonar.db.version.v60.DropIdColumnsFromSnapshots; import org.sonar.db.version.v60.DropProjectIdColumnFromMeasures; import org.sonar.db.version.v60.DropRememberMeColumnsFromUsers; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; +import org.sonar.db.version.v60.MakeComponentUuidColumnsNotNullOnSnapshots; import org.sonar.db.version.v60.MakeComponentUuidNotNullOnMeasures; +import org.sonar.db.version.v60.MakeUuidColumnNotNullOnSnapshots; import org.sonar.db.version.v60.MakeUuidColumnsNotNullOnProjects; import org.sonar.db.version.v60.MakeUuidColumnsNotNullOnResourceIndex; -import org.sonar.db.version.v60.MakeUuidColumnsNotNullOnSnapshots; import org.sonar.db.version.v60.PopulateComponentUuidOfMeasures; +import org.sonar.db.version.v60.PopulateUuidColumnOnSnapshots; import org.sonar.db.version.v60.PopulateUuidColumnsOfProjects; import org.sonar.db.version.v60.PopulateUuidColumnsOfResourceIndex; -import org.sonar.db.version.v60.PopulateUuidColumnsOfSnapshots; +import org.sonar.db.version.v60.PopulateComponentUuidColumnsOfSnapshots; public class MigrationStepModule extends Module { @Override @@ -196,10 +199,10 @@ public class MigrationStepModule extends Module { MakeUuidColumnsNotNullOnResourceIndex.class, DropIdColumnsFromResourceIndex.class, DropUnusedMeasuresColumns.class, - AddUuidColumnsToSnapshots.class, - PopulateUuidColumnsOfSnapshots.class, + AddComponentUuidColumnsToSnapshots.class, + PopulateComponentUuidColumnsOfSnapshots.class, CleanOrphanRowsInSnapshots.class, - MakeUuidColumnsNotNullOnSnapshots.class, + MakeComponentUuidColumnsNotNullOnSnapshots.class, DropIdColumnsFromSnapshots.class, AddComponentUuidColumnToMeasures.class, PopulateComponentUuidOfMeasures.class, @@ -211,6 +214,12 @@ public class MigrationStepModule extends Module { PopulateUuidColumnsOfProjects.class, CleanOrphanRowsInProjects.class, MakeUuidColumnsNotNullOnProjects.class, - DropIdColumnsFromProjects.class); + DropIdColumnsFromProjects.class, + + // SNAPSHOTS.UUID + AddUuidColumnToSnapshots.class, + PopulateUuidColumnOnSnapshots.class, + MakeUuidColumnNotNullOnSnapshots.class + ); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshots.java new file mode 100644 index 00000000000..9fdfd3857ab --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshots.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AddColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddComponentUuidColumnsToSnapshots extends DdlChange { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + public AddComponentUuidColumnsToSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) + .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnToSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnToSnapshots.java new file mode 100644 index 00000000000..349459b9484 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnToSnapshots.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AddColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddUuidColumnToSnapshots extends DdlChange { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + public AddUuidColumnToSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), TABLE_SNAPSHOTS) + .addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshots.java deleted file mode 100644 index a9abdc76a9b..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshots.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import org.sonar.db.Database; -import org.sonar.db.version.AddColumnsBuilder; -import org.sonar.db.version.DdlChange; - -import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; -import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; - -public class AddUuidColumnsToSnapshots extends DdlChange { - - private static final String TABLE_SNAPSHOTS = "snapshots"; - - public AddUuidColumnsToSnapshots(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) - .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) - .addColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) - .build()); - } - -} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java new file mode 100644 index 00000000000..40c2c55bf55 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshots.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeComponentUuidColumnsNotNullOnSnapshots extends DdlChange { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + public MakeComponentUuidColumnsNotNullOnSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) + .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshots.java new file mode 100644 index 00000000000..527201a1a76 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshots.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.AlterColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeUuidColumnNotNullOnSnapshots extends DdlChange { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + public MakeUuidColumnNotNullOnSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) + .updateColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshots.java deleted file mode 100644 index c821e589aa2..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshots.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import org.sonar.db.Database; -import org.sonar.db.version.AlterColumnsBuilder; -import org.sonar.db.version.DdlChange; - -import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; -import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; - -public class MakeUuidColumnsNotNullOnSnapshots extends DdlChange { - - private static final String TABLE_SNAPSHOTS = "snapshots"; - - public MakeUuidColumnsNotNullOnSnapshots(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_SNAPSHOTS) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) - .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) - .build()); - } - -} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshots.java new file mode 100644 index 00000000000..36db0807e50 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshots.java @@ -0,0 +1,85 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.sonar.db.Database; +import org.sonar.db.version.BaseDataChange; +import org.sonar.db.version.MassUpdate; +import org.sonar.db.version.Select; +import org.sonar.db.version.SqlStatement; + +public class PopulateComponentUuidColumnsOfSnapshots extends BaseDataChange { + + public PopulateComponentUuidColumnsOfSnapshots(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + Map componentUuidById = buildComponentUuidMap(context); + if (componentUuidById.isEmpty()) { + return; + } + + populateUuidColumns(context, componentUuidById); + } + + private static Map buildComponentUuidMap(Context context) throws SQLException { + Map componentUuidById = new HashMap<>(); + context.prepareSelect("select distinct p.id, p.uuid from projects p" + + " join snapshots sn1 on sn1.project_id = p.id and sn1.component_uuid is null") + .scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2))); + context.prepareSelect("select distinct p.id, p.uuid from projects p" + + " join snapshots sn2 on sn2.root_project_id = p.id and sn2.root_component_uuid is null") + .scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2))); + return componentUuidById; + } + + private void populateUuidColumns(Context context, Map componentUuidById) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null"); + massUpdate.update("UPDATE snapshots SET component_uuid=?, root_component_uuid=? WHERE id=?"); + massUpdate.rowPluralName("snapshots"); + massUpdate.execute((row, update) -> this.handle(componentUuidById, row, update)); + } + + private boolean handle(Map componentUuidById, Select.Row row, SqlStatement update) throws SQLException { + long id = row.getLong(1); + long componentId = row.getLong(2); + long rootProjectId = row.getLong(3); + + String componentUuid = componentUuidById.get(componentId); + String rootComponentUuid = componentUuidById.get(rootProjectId); + + if (componentUuid == null && rootComponentUuid == null) { + return false; + } + + update.setString(1, componentUuid); + update.setString(2, rootComponentUuid); + update.setLong(3, id); + + return true; + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshots.java new file mode 100644 index 00000000000..214e62ad42b --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshots.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.Database; +import org.sonar.db.version.BaseDataChange; +import org.sonar.db.version.MassUpdate; +import org.sonar.db.version.Select; +import org.sonar.db.version.SqlStatement; + +public class PopulateUuidColumnOnSnapshots extends BaseDataChange { + + private final UuidFactory uuidFactory; + + public PopulateUuidColumnOnSnapshots(Database db, UuidFactory uuidFactory) { + super(db); + this.uuidFactory = uuidFactory; + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT s.id from snapshots s where s.uuid is null"); + massUpdate.update("UPDATE snapshots SET uuid=? WHERE id=?"); + massUpdate.rowPluralName("snapshots"); + massUpdate.execute(this::handle); + } + + private boolean handle(Select.Row row, SqlStatement update) throws SQLException { + long id = row.getLong(1); + update.setString(1, uuidFactory.create()); + update.setLong(2, id); + return true; + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshots.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshots.java deleted file mode 100644 index 4fb0fd2eda5..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshots.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import org.sonar.db.Database; -import org.sonar.db.version.BaseDataChange; -import org.sonar.db.version.MassUpdate; -import org.sonar.db.version.Select; -import org.sonar.db.version.SqlStatement; - -public class PopulateUuidColumnsOfSnapshots extends BaseDataChange { - - public PopulateUuidColumnsOfSnapshots(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - Map componentUuidById = buildComponentUuidMap(context); - if (componentUuidById.isEmpty()) { - return; - } - - populateUuidColumns(context, componentUuidById); - } - - private static Map buildComponentUuidMap(Context context) throws SQLException { - Map componentUuidById = new HashMap<>(); - context.prepareSelect("select distinct p.id, p.uuid from projects p" + - " join snapshots sn1 on sn1.project_id = p.id and sn1.component_uuid is null") - .scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2))); - context.prepareSelect("select distinct p.id, p.uuid from projects p" + - " join snapshots sn2 on sn2.root_project_id = p.id and sn2.root_component_uuid is null") - .scroll(row -> componentUuidById.put(row.getLong(1), row.getString(2))); - return componentUuidById; - } - - private void populateUuidColumns(Context context, Map componentUuidById) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null"); - massUpdate.update("UPDATE snapshots SET component_uuid=?, root_component_uuid=? WHERE id=?"); - massUpdate.rowPluralName("snapshots"); - massUpdate.execute((row, update) -> this.handle(componentUuidById, row, update)); - } - - private boolean handle(Map componentUuidById, Select.Row row, SqlStatement update) throws SQLException { - long id = row.getLong(1); - long componentId = row.getLong(2); - long rootProjectId = row.getLong(3); - - String componentUuid = componentUuidById.get(componentId); - String rootComponentUuid = componentUuidById.get(rootProjectId); - - if (componentUuid == null && rootComponentUuid == null) { - return false; - } - - update.setString(1, componentUuid); - update.setString(2, rootComponentUuid); - update.setLong(3, id); - - return true; - } - -} 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 6d64f244d3b..4c81f73de09 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 @@ -4,6 +4,7 @@ s.id, + s.uuid as uuid, s.parent_snapshot_id as parentId, s.root_snapshot_id as rootId, s.root_component_uuid as rootComponentUuid, @@ -174,13 +175,6 @@ order by created_at desc - - (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, - period1_date, period2_date, period3_date, period4_date, period5_date) - update snapshots @@ -195,13 +189,68 @@ - insert into snapshots - - 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}, - #{period1Date}, #{period2Date}, #{period3Date}, #{period4Date}, #{period5Date}) + insert into snapshots ( + uuid, + 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, + period1_date, + period2_date, + period3_date, + period4_date, + period5_date) + values ( + #{uuid, jdbcType=VARCHAR}, + #{parentId, jdbcType=BIGINT}, + #{rootId, jdbcType=BIGINT}, + #{rootComponentUuid, jdbcType=VARCHAR}, + #{componentUuid, jdbcType=VARCHAR}, + #{createdAt, jdbcType=BIGINT}, + #{buildDate, jdbcType=BIGINT}, + #{status, jdbcType=VARCHAR}, + #{purgeStatus, jdbcType=INTEGER}, + #{last, jdbcType=BOOLEAN}, + #{scope, jdbcType=VARCHAR}, + #{qualifier, jdbcType=VARCHAR}, + #{version, jdbcType=VARCHAR}, + #{path, jdbcType=VARCHAR}, + #{depth, jdbcType=BOOLEAN}, + #{period1Mode, jdbcType=VARCHAR}, + #{period2Mode, jdbcType=VARCHAR}, + #{period3Mode, jdbcType=VARCHAR}, + #{period4Mode, jdbcType=VARCHAR}, + #{period5Mode, jdbcType=VARCHAR}, + #{period1Param, jdbcType=VARCHAR}, + #{period2Param, jdbcType=VARCHAR}, + #{period3Param, jdbcType=VARCHAR}, + #{period4Param, jdbcType=VARCHAR}, + #{period5Param, jdbcType=VARCHAR}, + #{period1Date, jdbcType=BIGINT}, + #{period2Date, jdbcType=BIGINT}, + #{period3Date, jdbcType=BIGINT}, + #{period4Date, jdbcType=BIGINT}, + #{period5Date, jdbcType=BIGINT}) diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index ef60eb5d94e..f35f96c2cdb 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -434,6 +434,10 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1224'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1225'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1226'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1227'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1228'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1229'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1230'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1231'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482'); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index 4861e6c87aa..f0433733cc2 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -54,6 +54,7 @@ CREATE TABLE "GROUPS" ( CREATE TABLE "SNAPSHOTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "UUID" VARCHAR(50) NOT NULL, "CREATED_AT" BIGINT, "BUILD_DATE" BIGINT, "COMPONENT_UUID" VARCHAR(50) NOT NULL, @@ -577,6 +578,8 @@ CREATE INDEX "SNAPSHOTS_PARENT" ON "SNAPSHOTS" ("PARENT_SNAPSHOT_ID"); CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID"); +CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID"); + CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS" ("RULE_ID"); CREATE INDEX "ACTIVE_DASHBOARDS_DASHBOARDID" ON "ACTIVE_DASHBOARDS" ("DASHBOARD_ID"); diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java index ecf6a506df5..61b0c00cf17 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java @@ -150,7 +150,11 @@ public class ResourceIndexDaoTest { ComponentDto project = new ComponentDto().setUuid(ROOT_UUID).setRootUuid(ROOT_UUID).setKey("the_key").setName(longName).setScope(Scopes.PROJECT).setQualifier(Qualifiers.PROJECT); DbSession session = dbTester.getSession(); dbTester.getDbClient().componentDao().insert(session, project); - dbTester.getDbClient().snapshotDao().insert(session, new SnapshotDto().setComponentUuid(project.uuid()).setRootComponentUuid(project.uuid()).setLast(true)); + dbTester.getDbClient().snapshotDao().insert(session, new SnapshotDto() + .setUuid("u1") + .setComponentUuid(project.uuid()) + .setRootComponentUuid(project.uuid()) + .setLast(true)); underTest.indexProject(session, project.uuid()); session.commit(); diff --git a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index b10abdb2d3c..fa8bfbee32f 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -62,6 +62,7 @@ public class SnapshotDaoTest { SnapshotDto result = underTest.selectById(db.getSession(), 3L); assertThat(result).isNotNull(); assertThat(result.getId()).isEqualTo(3L); + assertThat(result.getUuid()).isEqualTo("u3"); assertThat(result.getComponentUuid()).isEqualTo("uuid_3"); assertThat(result.getRootComponentUuid()).isEqualTo("uuid_1"); assertThat(result.getParentId()).isEqualTo(2L); @@ -254,8 +255,8 @@ public class SnapshotDaoTest { db.prepareDbUnit(getClass(), "empty.xml"); underTest.insert(db.getSession(), - new SnapshotDto().setComponentUuid("uuid_1").setRootComponentUuid("uuid_1").setLast(false), - new SnapshotDto().setComponentUuid("uuid_2").setRootComponentUuid("uuid_1").setLast(false)); + new SnapshotDto().setComponentUuid("uuid_1").setRootComponentUuid("uuid_1").setLast(false).setUuid("u5"), + new SnapshotDto().setComponentUuid("uuid_2").setRootComponentUuid("uuid_1").setLast(false).setUuid("u6")); db.getSession().commit(); assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2); @@ -336,6 +337,7 @@ public class SnapshotDaoTest { private static SnapshotDto defaultSnapshot() { return new SnapshotDto() + .setUuid("u1") .setComponentUuid("uuid_3") .setRootComponentUuid("uuid_1") .setParentId(2L) diff --git a/sonar-db/src/test/java/org/sonar/db/component/SnapshotTesting.java b/sonar-db/src/test/java/org/sonar/db/component/SnapshotTesting.java index 7d0bc76e77a..c2ef9e2f84e 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/SnapshotTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/component/SnapshotTesting.java @@ -19,6 +19,7 @@ */ package org.sonar.db.component; +import org.apache.commons.lang.RandomStringUtils; import org.assertj.core.util.Strings; import static com.google.common.base.Preconditions.checkNotNull; @@ -61,6 +62,7 @@ public class SnapshotTesting { checkNotNull(component.getId(), "The project need to be persisted before creating this snapshot"); checkNotNull(rootComponentUuid, "Root component uuid is null"); return new SnapshotDto() + .setUuid(RandomStringUtils.randomAlphanumeric(40)) .setComponentUuid(component.uuid()) .setRootComponentUuid(rootComponentUuid) .setStatus(SnapshotDto.STATUS_PROCESSED) diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index 3913321d571..fdc2ab7ccec 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -405,7 +405,7 @@ public class MeasureDaoTest { long otherDeveloperId = 666l; ComponentDto projectDto = insertProject("aa"); - SnapshotDto snapshotDto = insertSnapshot(projectDto, true); + SnapshotDto snapshotDto = insertSnapshot("u1", projectDto, true); insertMeasure(projectDto, snapshotDto, DEVELOPER_ID, NCLOC_METRIC_ID, 12d); List measureDtos = underTest.selectProjectMeasuresByDeveloperForMetrics(dbSession, DEVELOPER_ID, ImmutableList.of(NCLOC_METRIC_ID)); @@ -426,9 +426,9 @@ public class MeasureDaoTest { long otherDeveloperId = 666l; ComponentDto projectDto = insertProject("aa"); - SnapshotDto nonLastSnapshotDto = insertSnapshot(projectDto, false); + SnapshotDto nonLastSnapshotDto = insertSnapshot("u1", projectDto, false); insertMeasure(projectDto, nonLastSnapshotDto, DEVELOPER_ID, NCLOC_METRIC_ID, 12d); - SnapshotDto lastSnapshotDto = insertSnapshot(projectDto, true); + SnapshotDto lastSnapshotDto = insertSnapshot("u2", projectDto, true); insertMeasure(projectDto, lastSnapshotDto, otherDeveloperId, NCLOC_METRIC_ID, 15d); assertThat(underTest.selectProjectMeasuresByDeveloperForMetrics(dbSession, DEVELOPER_ID, ImmutableList.of(NCLOC_METRIC_ID))).hasSize(0); @@ -446,13 +446,13 @@ public class MeasureDaoTest { @Test public void selectProjectMeasuresByDeveloperForMetrics_returns_ignores_snapshots_of_any_component_but_project() { ComponentDto projectDto = insertProject("aa"); - insertSnapshot(projectDto, true); + insertSnapshot("u1", projectDto, true); ComponentDto moduleDto = insertComponent(ComponentTesting.newModuleDto(projectDto)); - insertMeasure(moduleDto, insertSnapshot(moduleDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 15d); + insertMeasure(moduleDto, insertSnapshot("u2", moduleDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 15d); ComponentDto dirDto = insertComponent(ComponentTesting.newDirectory(moduleDto, "toto")); - insertMeasure(dirDto, insertSnapshot(dirDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 25d); + insertMeasure(dirDto, insertSnapshot("u3", dirDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 25d); ComponentDto fileDto = insertComponent(ComponentTesting.newFileDto(moduleDto, "tutu")); - insertMeasure(fileDto, insertSnapshot(fileDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 35d); + insertMeasure(fileDto, insertSnapshot("u4", fileDto, true), DEVELOPER_ID, NCLOC_METRIC_ID, 35d); assertThat(underTest.selectProjectMeasuresByDeveloperForMetrics(dbSession, DEVELOPER_ID, ImmutableList.of(NCLOC_METRIC_ID))).isEmpty(); } @@ -468,9 +468,13 @@ public class MeasureDaoTest { return insertComponent(projectDto); } - private SnapshotDto insertSnapshot(ComponentDto componentDto, boolean last) { - SnapshotDto snapshotDto = new SnapshotDto().setComponentUuid(componentDto.uuid()).setRootComponentUuid(componentDto.projectUuid()) - .setLast(last).setQualifier(componentDto.qualifier()).setScope(componentDto.scope()); + private SnapshotDto insertSnapshot(String uuid, ComponentDto componentDto, boolean last) { + SnapshotDto snapshotDto = new SnapshotDto() + .setUuid(uuid) + .setComponentUuid(componentDto.uuid()) + .setRootComponentUuid(componentDto.projectUuid()) + .setLast(last) + .setQualifier(componentDto.qualifier()).setScope(componentDto.scope()); dbClient.snapshotDao().insert(dbSession, snapshotDto); dbSession.commit(); return snapshotDto; diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index 01cfda06075..27ad48aceb8 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(87); + assertThat(container.size()).isEqualTo(90); } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshotsTest.java new file mode 100644 index 00000000000..0c40da06747 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/AddComponentUuidColumnsToSnapshotsTest.java @@ -0,0 +1,78 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + +public class AddComponentUuidColumnsToSnapshotsTest { + + private static final String SNAPSHOTS_TABLE = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddComponentUuidColumnsToSnapshotsTest.class, "old_snapshots.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddComponentUuidColumnsToSnapshots underTest = new AddComponentUuidColumnsToSnapshots(db.database()); + + @Test + public void migration_adds_columns_to_empty_table() throws SQLException { + underTest.execute(); + + verifyAddedColumns(); + } + + @Test + public void migration_adds_columns_to_populated_table() throws SQLException { + for (int i = 0; i < 9; i++) { + db.executeInsert( + SNAPSHOTS_TABLE, + "PROJECT_ID", valueOf(i), + "ISLAST", "TRUE"); + } + db.commit(); + + underTest.execute(); + + verifyAddedColumns(); + } + + private void verifyAddedColumns() { + db.assertColumnDefinition(SNAPSHOTS_TABLE, "component_uuid", Types.VARCHAR, 50, true); + db.assertColumnDefinition(SNAPSHOTS_TABLE, "root_component_uuid", Types.VARCHAR, 50, true); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute "); + underTest.execute(); + } +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnToSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnToSnapshotsTest.java new file mode 100644 index 00000000000..eb1cde5c59b --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnToSnapshotsTest.java @@ -0,0 +1,77 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + + +public class AddUuidColumnToSnapshotsTest { + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddUuidColumnToSnapshotsTest.class, "old_snapshots.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private AddUuidColumnToSnapshots underTest = new AddUuidColumnToSnapshots(db.database()); + + @Test + public void migration_adds_columns_to_empty_table() throws SQLException { + underTest.execute(); + + verifyAddedColumns(); + } + + @Test + public void migration_adds_column_to_populated_table() throws SQLException { + for (int i = 0; i < 9; i++) { + db.executeInsert( + "snapshots", + "component_uuid", valueOf(i), + "root_component_uuid", valueOf(i + 10), + "QUALIFIER", (i % 2 == 0 ? "FIL" : "TRK")); + } + db.commit(); + + underTest.execute(); + + verifyAddedColumns(); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute "); + underTest.execute(); + } + + private void verifyAddedColumns() { + db.assertColumnDefinition("snapshots", "uuid", Types.VARCHAR, 50, true); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshotsTest.java deleted file mode 100644 index ec76166493b..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/AddUuidColumnsToSnapshotsTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.lang.String.valueOf; - -public class AddUuidColumnsToSnapshotsTest { - - private static final String SNAPSHOTS_TABLE = "snapshots"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddUuidColumnsToSnapshotsTest.class, "old_snapshots.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private AddUuidColumnsToSnapshots underTest = new AddUuidColumnsToSnapshots(db.database()); - - @Test - public void migration_adds_columns_to_empty_table() throws SQLException { - underTest.execute(); - - verifyAddedColumns(); - } - - @Test - public void migration_adds_columns_to_populated_table() throws SQLException { - for (int i = 0; i < 9; i++) { - db.executeInsert( - SNAPSHOTS_TABLE, - "PROJECT_ID", valueOf(i), - "ISLAST", "TRUE"); - } - db.commit(); - - underTest.execute(); - - verifyAddedColumns(); - } - - private void verifyAddedColumns() { - db.assertColumnDefinition(SNAPSHOTS_TABLE, "component_uuid", Types.VARCHAR, 50, true); - db.assertColumnDefinition(SNAPSHOTS_TABLE, "root_component_uuid", Types.VARCHAR, 50, true); - } - - @Test - public void migration_is_not_reentrant() throws SQLException { - underTest.execute(); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to execute "); - underTest.execute(); - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java new file mode 100644 index 00000000000..2263e9e3866 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeComponentUuidColumnsNotNullOnSnapshotsTest.java @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + +public class MakeComponentUuidColumnsNotNullOnSnapshotsTest { + + private static final String SNAPSHOTS_TABLE = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, MakeComponentUuidColumnsNotNullOnSnapshotsTest.class, + "in_progress_snapshots.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private MakeComponentUuidColumnsNotNullOnSnapshots underTest = new MakeComponentUuidColumnsNotNullOnSnapshots(db.database()); + + @Test + public void migration_sets_uuid_columns_not_nullable_on_empty_table() throws SQLException { + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_sets_uuid_columns_not_nullable_on_populated_table() throws SQLException { + insertSnapshots(1, true, true); + insertSnapshots(2, true, true); + + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_fails_if_some_uuid_columns_are_null() throws SQLException { + insertSnapshots(1, false, true); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute"); + + underTest.execute(); + } + + private void verifyColumnDefinitions() { + db.assertColumnDefinition(SNAPSHOTS_TABLE, "component_uuid", Types.VARCHAR, 50, false); + db.assertColumnDefinition(SNAPSHOTS_TABLE, "root_component_uuid", Types.VARCHAR, 50, false); + } + + private void insertSnapshots(long id, boolean hasComponentUiid, boolean hasRootComponentUuid) { + db.executeInsert( + SNAPSHOTS_TABLE, + "ID", valueOf(id), + "ISLAST", "TRUE", + "PROJECT_ID", valueOf(id + 300), + "COMPONENT_UUID", hasComponentUiid ? "uuid_" + id : null, + "ROOT_COMPONENT_UUID", hasRootComponentUuid ? "root_uuid_" + id : null); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshotsTest.java new file mode 100644 index 00000000000..b079bf6a867 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnNotNullOnSnapshotsTest.java @@ -0,0 +1,88 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; + + +public class MakeUuidColumnNotNullOnSnapshotsTest { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, MakeUuidColumnNotNullOnSnapshotsTest.class, + "in_progress_snapshots.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private MakeUuidColumnNotNullOnSnapshots underTest = new MakeUuidColumnNotNullOnSnapshots(db.database()); + + @Test + public void migration_sets_uuid_column_not_nullable_on_empty_table() throws SQLException { + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_sets_uuid_column_not_nullable_on_populated_table() throws SQLException { + insertSnapshot(1, true); + insertSnapshot(2, true); + + underTest.execute(); + + verifyColumnDefinitions(); + } + + @Test + public void migration_fails_if_some_row_has_a_null_uuid() throws SQLException { + insertSnapshot(1, false); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Fail to execute"); + + underTest.execute(); + } + + + private void verifyColumnDefinitions() { + db.assertColumnDefinition(TABLE_SNAPSHOTS, "uuid", Types.VARCHAR, 50, false); + } + + private String insertSnapshot(long id, boolean hasUuid) { + String uuid = "uuid_" + id; + db.executeInsert( + TABLE_SNAPSHOTS, + "ID", valueOf(id), + "COMPONENT_UUID", valueOf(id + 10), + "ROOT_COMPONENT_UUID", valueOf(id + 100), + "UUID", hasUuid ? "uuid_" + id : null); + return uuid; + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshotsTest.java deleted file mode 100644 index da9b16c2f9a..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnSnapshotsTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import java.sql.Types; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.lang.String.valueOf; - -public class MakeUuidColumnsNotNullOnSnapshotsTest { - - private static final String SNAPSHOTS_TABLE = "snapshots"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, MakeUuidColumnsNotNullOnSnapshotsTest.class, - "in_progress_snapshots.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private MakeUuidColumnsNotNullOnSnapshots underTest = new MakeUuidColumnsNotNullOnSnapshots(db.database()); - - @Test - public void migration_sets_uuid_columns_not_nullable_on_empty_table() throws SQLException { - underTest.execute(); - - verifyColumnDefinitions(); - } - - @Test - public void migration_sets_uuid_columns_not_nullable_on_populated_table() throws SQLException { - insertSnapshots(1, true, true); - insertSnapshots(2, true, true); - - underTest.execute(); - - verifyColumnDefinitions(); - } - - @Test - public void migration_fails_if_some_uuid_columns_are_null() throws SQLException { - insertSnapshots(1, false, true); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to execute"); - - underTest.execute(); - } - - private void verifyColumnDefinitions() { - db.assertColumnDefinition(SNAPSHOTS_TABLE, "component_uuid", Types.VARCHAR, 50, false); - db.assertColumnDefinition(SNAPSHOTS_TABLE, "root_component_uuid", Types.VARCHAR, 50, false); - } - - private void insertSnapshots(long id, boolean hasComponentUiid, boolean hasRootComponentUuid) { - db.executeInsert( - SNAPSHOTS_TABLE, - "ID", valueOf(id), - "ISLAST", "TRUE", - "PROJECT_ID", valueOf(id + 300), - "COMPONENT_UUID", hasComponentUiid ? "uuid_" + id : null, - "ROOT_COMPONENT_UUID", hasRootComponentUuid ? "root_uuid_" + id : null); - } - -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshotsTest.java new file mode 100644 index 00000000000..ce483323e8b --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateComponentUuidColumnsOfSnapshotsTest.java @@ -0,0 +1,121 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateComponentUuidColumnsOfSnapshotsTest { + + private static final String SNAPSHOTS_TABLE = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateComponentUuidColumnsOfSnapshotsTest.class, + "in_progress_snapshots_with_projects.sql"); + + private PopulateComponentUuidColumnsOfSnapshots underTest = new PopulateComponentUuidColumnsOfSnapshots(db.database()); + + @Test + public void migration_has_no_effect_on_empty_tables() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(SNAPSHOTS_TABLE)).isEqualTo(0); + assertThat(db.countRowsOfTable("projects")).isEqualTo(0); + } + + @Test + public void migration_updates_uuid_columns_with_values_from_table_projects_when_they_exist() throws SQLException { + String uuid1 = insertComponent(40); + String uuid2 = insertComponent(50); + String uuid3 = insertComponent(60); + String uuid4 = insertComponent(70); + String uuid5 = insertComponent(80); + + insertSnapshots(1, 40, 50L); + insertSnapshots(2, 60, 70L); + insertSnapshots(3, 90, 70L); // 90 does not exist + insertSnapshots(4, 40, 100L); // 100 does not exist + insertSnapshots(5, 110, 100L); // 110 and 100 do not exist + insertSnapshots(6, 80, null); // no root + insertSnapshots(7, 120, null); // no root and 120 does not exist + db.commit(); + + underTest.execute(); + + verifySnapshots(1, 40, uuid1, 50L, uuid2); + verifySnapshots(2, 60, uuid3, 70L, uuid4); + verifySnapshots(3, 90, null, 70L, uuid4); + verifySnapshots(4, 40, uuid1, 100L, null); + verifySnapshots(5, 110, null, 100L, null); + verifySnapshots(6, 80, uuid5, null, null); + verifySnapshots(7, 120, null, null, null); + } + + @Test + public void migration_is_reentrant() throws SQLException { + String uuid1 = insertComponent(40); + String uuid2 = insertComponent(50); + insertSnapshots(1, 40, 50L); + + underTest.execute(); + verifySnapshots(1, 40, uuid1, 50L, uuid2); + + underTest.execute(); + verifySnapshots(1, 40, uuid1, 50L, uuid2); + } + + private void insertSnapshots(long id, long projectId, @Nullable Long rootId) { + db.executeInsert( + SNAPSHOTS_TABLE, + "ID", valueOf(id), + "ISLAST", "TRUE", + "PROJECT_ID", valueOf(projectId), + "ROOT_PROJECT_ID", rootId == null ? null : valueOf(rootId)); + } + + private String insertComponent(long id) { + String uuid = "uuid_" + id; + db.executeInsert( + "projects", + "ID", valueOf(id), + "UUID", uuid); + return uuid; + } + + private void verifySnapshots(long id, long resourceId, @Nullable String componentUuid, @Nullable Long rootProjectId, @Nullable String rootComponentUuid) { + List> rows = db.select("select PROJECT_ID, COMPONENT_UUID, ROOT_PROJECT_ID, ROOT_COMPONENT_UUID from snapshots where ID=" + id); + assertThat(rows).hasSize(1); + Map row = rows.get(0); + assertThat(row.get("PROJECT_ID")).isEqualTo(resourceId); + assertThat(row.get("COMPONENT_UUID")).isEqualTo(componentUuid); + assertThat(row.get("ROOT_PROJECT_ID")).isEqualTo(rootProjectId); + assertThat(row.get("ROOT_COMPONENT_UUID")).isEqualTo(rootComponentUuid); + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshotsTest.java new file mode 100644 index 00000000000..8b55518db55 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnOnSnapshotsTest.java @@ -0,0 +1,95 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.core.util.UuidFactoryImpl; +import org.sonar.db.DbTester; + +import static java.lang.String.valueOf; +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateUuidColumnOnSnapshotsTest { + + private static final String TABLE_SNAPSHOTS = "snapshots"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateUuidColumnOnSnapshotsTest.class, + "in_progress_snapshots.sql"); + + private PopulateUuidColumnOnSnapshots underTest = new PopulateUuidColumnOnSnapshots(db.database(), UuidFactoryImpl.INSTANCE); + + @Test + public void migration_has_no_effect_on_empty_tables() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_SNAPSHOTS)).isEqualTo(0); + } + + @Test + public void migration_generates_uuids() throws SQLException { + insertSnapshot(1); + insertSnapshot(2); + insertSnapshot(3); + db.commit(); + + underTest.execute(); + + verifyUuids(3); + } + + private void verifyUuids(int expectedCount) { + List> rows = db.select("select uuid from snapshots where uuid is not null"); + Set uuids = rows.stream().map(cols -> cols.get("UUID")).filter(uuid -> StringUtils.isNotBlank((String) uuid)).collect(Collectors.toSet()); + assertThat(uuids).hasSize(expectedCount); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertSnapshot(1); + + underTest.execute(); + verifyUuids(1); + + underTest.execute(); + verifyUuids(1); + } + + private String insertSnapshot(long id) { + String uuid = "uuid_" + id; + db.executeInsert( + TABLE_SNAPSHOTS, + "ID", valueOf(id), + "COMPONENT_UUID", valueOf(id + 10), + "ROOT_COMPONENT_UUID", valueOf(id + 100), + "SCOPE", "PRJ", + "QUALIFIER", "FIL"); + return uuid; + } + +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshotsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshotsTest.java deleted file mode 100644 index 11dabd59e45..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUuidColumnsOfSnapshotsTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.version.v60; - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; - -import static java.lang.String.valueOf; -import static org.assertj.core.api.Assertions.assertThat; - -public class PopulateUuidColumnsOfSnapshotsTest { - - private static final String SNAPSHOTS_TABLE = "snapshots"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateUuidColumnsOfSnapshotsTest.class, - "in_progress_snapshots_with_projects.sql"); - - private PopulateUuidColumnsOfSnapshots underTest = new PopulateUuidColumnsOfSnapshots(db.database()); - - @Test - public void migration_has_no_effect_on_empty_tables() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable(SNAPSHOTS_TABLE)).isEqualTo(0); - assertThat(db.countRowsOfTable("projects")).isEqualTo(0); - } - - @Test - public void migration_updates_uuid_columns_with_values_from_table_projects_when_they_exist() throws SQLException { - String uuid1 = insertComponent(40); - String uuid2 = insertComponent(50); - String uuid3 = insertComponent(60); - String uuid4 = insertComponent(70); - String uuid5 = insertComponent(80); - - insertSnapshots(1, 40, 50L); - insertSnapshots(2, 60, 70L); - insertSnapshots(3, 90, 70L); // 90 does not exist - insertSnapshots(4, 40, 100L); // 100 does not exist - insertSnapshots(5, 110, 100L); // 110 and 100 do not exist - insertSnapshots(6, 80, null); // no root - insertSnapshots(7, 120, null); // no root and 120 does not exist - db.commit(); - - underTest.execute(); - - verifySnapshots(1, 40, uuid1, 50L, uuid2); - verifySnapshots(2, 60, uuid3, 70L, uuid4); - verifySnapshots(3, 90, null, 70L, uuid4); - verifySnapshots(4, 40, uuid1, 100L, null); - verifySnapshots(5, 110, null, 100L, null); - verifySnapshots(6, 80, uuid5, null, null); - verifySnapshots(7, 120, null, null, null); - } - - @Test - public void migration_is_reentrant() throws SQLException { - String uuid1 = insertComponent(40); - String uuid2 = insertComponent(50); - insertSnapshots(1, 40, 50L); - - underTest.execute(); - verifySnapshots(1, 40, uuid1, 50L, uuid2); - - underTest.execute(); - verifySnapshots(1, 40, uuid1, 50L, uuid2); - } - - private void insertSnapshots(long id, long projectId, @Nullable Long rootId) { - db.executeInsert( - SNAPSHOTS_TABLE, - "ID", valueOf(id), - "ISLAST", "TRUE", - "PROJECT_ID", valueOf(projectId), - "ROOT_PROJECT_ID", rootId == null ? null : valueOf(rootId)); - } - - private String insertComponent(long id) { - String uuid = "uuid_" + id; - db.executeInsert( - "projects", - "ID", valueOf(id), - "UUID", uuid); - return uuid; - } - - private void verifySnapshots(long id, long resourceId, @Nullable String componentUuid, @Nullable Long rootProjectId, @Nullable String rootComponentUuid) { - List> rows = db.select("select PROJECT_ID, COMPONENT_UUID, ROOT_PROJECT_ID, ROOT_COMPONENT_UUID from snapshots where ID=" + id); - assertThat(rows).hasSize(1); - Map row = rows.get(0); - assertThat(row.get("PROJECT_ID")).isEqualTo(resourceId); - assertThat(row.get("COMPONENT_UUID")).isEqualTo(componentUuid); - assertThat(row.get("ROOT_PROJECT_ID")).isEqualTo(rootProjectId); - assertThat(row.get("ROOT_COMPONENT_UUID")).isEqualTo(rootComponentUuid); - } - -} diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/multi-modules.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/multi-modules.xml index a60d785a90a..82c7bbbecfd 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/multi-modules.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/multi-modules.xml @@ -5,36 +5,84 @@ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD." scope="PRJ" qualifier="TRK" long_name="Apache Struts" description="the description" enabled="[true]" language="[null]" copy_component_uuid="[null]" developer_uuid="[null]" path="[null]" authorization_updated_at="[null]"/> - - + + - + - + - + - + - - - @@ -47,15 +106,36 @@ uuid="EFGH" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=".ABCD.EFGH." scope="PRJ" qualifier="BRC" long_name="Struts Core" description="[null]" enabled="[true]" language="[null]" copy_component_uuid="[null]" developer_uuid="[null]" authorization_updated_at="[null]"/> - + - + - + - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml index ff0f36d95e6..ff43af42c18 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml @@ -27,8 +27,20 @@ description="[null]" enabled="[true]" language="java" /> - - - - + + + + diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml index ee9ab480a7c..9b08be4a746 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml @@ -22,11 +22,20 @@ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/> - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml index 7e76208a0ee..60d7f6aa5ae 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml @@ -22,10 +22,20 @@ description="[null]" enabled="[true]" language="java" /> - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml index 1c7036cd095..6cd09bb7cf9 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml @@ -6,7 +6,10 @@ description="[null]" enabled="[true]" language="java"/> - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml index c7faa7de4ce..320106fb845 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml @@ -6,7 +6,10 @@ description="[null]" enabled="[true]" language="java" /> - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml index 1d5c5d31259..a4981c2ff93 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml @@ -6,7 +6,9 @@ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/> - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml index 6b1066004b3..31c50efeb96 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml @@ -6,7 +6,10 @@ description="[null]" enabled="[true]" language="java" /> - diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/has_last_snapshot_by_component_uuid.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/has_last_snapshot_by_component_uuid.xml index 84aeaa27387..fbdd4fc6bc9 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/has_last_snapshot_by_component_uuid.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/has_last_snapshot_by_component_uuid.xml @@ -1,11 +1,30 @@ - - + - + - + diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml index 66e1a4ec3d1..41b7453231a 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/insert-result.xml @@ -1,13 +1,35 @@ - + diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml index 9ba70bee6f4..960bc8be614 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/modules.xml @@ -5,7 +5,10 @@ uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="." description="the description" long_name="Apache Struts" enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" /> - - - - - - - - - - - - - - - - - + diff --git a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml index b950190b926..c67aeba2af9 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/snapshots.xml @@ -1,7 +1,9 @@ - - - - - - - - + + - - + + diff --git a/sonar-db/src/test/resources/org/sonar/db/duplication/DuplicationDaoTest/select_candidates.xml b/sonar-db/src/test/resources/org/sonar/db/duplication/DuplicationDaoTest/select_candidates.xml index d2eca360488..32b73f94ea4 100644 --- a/sonar-db/src/test/resources/org/sonar/db/duplication/DuplicationDaoTest/select_candidates.xml +++ b/sonar-db/src/test/resources/org/sonar/db/duplication/DuplicationDaoTest/select_candidates.xml @@ -1,26 +1,48 @@ - - + + - - + + - - + + - - + + - - + + - + diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml index ab4473adb1b..68405f0b926 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures.xml @@ -30,13 +30,20 @@ - - - diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml index 55744741a7f..6645b79f2bf 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/past_measures_with_person_id.xml @@ -8,7 +8,9 @@ enabled="[true]"/> - diff --git a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml index 67e00418372..1de5d1f021b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml +++ b/sonar-db/src/test/resources/org/sonar/db/measure/MeasureDaoTest/select_by_snapshot_and_metric_keys.xml @@ -6,7 +6,9 @@ - + - + - + - - - -