From 5112fc0bc1bc9c1725235ffcf3031060a44e3567 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 1 Jul 2016 16:31:22 +0200 Subject: SONAR-7780 Apply feedback --- .../java/org/sonar/db/measure/MeasureQuery.java | 7 +- .../java/org/sonar/db/measure/PastMeasureDto.java | 6 +- .../org/sonar/db/version/MigrationStepModule.java | 4 +- .../v60/FixProjectUuidOfDeveloperProjects.java | 50 ++++++++++ .../db/version/v60/FixProjectUuidOfDevelopers.java | 50 ---------- .../v60/FixProjectUuidOfDeveloperProjectsTest.java | 108 +++++++++++++++++++++ .../v60/FixProjectUuidOfDevelopersTest.java | 108 --------------------- .../in_progress_projects.sql | 22 +++++ .../in_progress_projects.sql | 22 ----- 9 files changed, 189 insertions(+), 188 deletions(-) create mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java delete mode 100644 sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java create mode 100644 sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java delete mode 100644 sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest.java create mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql delete mode 100644 sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest/in_progress_projects.sql (limited to 'sonar-db/src') diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java index 7dd1b1daa8c..dcb534a1ef4 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java @@ -45,9 +45,9 @@ public class MeasureQuery { } private MeasureQuery(List componentUuids, - @Nullable Collection metricIds, - @Nullable Collection metricKeys, - @Nullable Long personId) { + @Nullable Collection metricIds, + @Nullable Collection metricKeys, + @Nullable Long personId) { checkState(componentUuids != null, "Component UUIDs must be set"); checkState(metricIds == null || metricKeys == null, "Metric IDs and keys must not be set both"); this.componentUuids = componentUuids; @@ -96,6 +96,7 @@ public class MeasureQuery { private Long personId; private Builder() { + // see MeasureQuery#builder() } public Builder setComponentUuids(List componentUuids) { diff --git a/sonar-db/src/main/java/org/sonar/db/measure/PastMeasureDto.java b/sonar-db/src/main/java/org/sonar/db/measure/PastMeasureDto.java index f4a48cfa4a5..cdc90361b19 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/PastMeasureDto.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/PastMeasureDto.java @@ -39,7 +39,7 @@ public class PastMeasureDto { return value; } - public PastMeasureDto setValue(@Nullable Double value) { + PastMeasureDto setValue(@Nullable Double value) { this.value = value; return this; } @@ -52,7 +52,7 @@ public class PastMeasureDto { return metricId; } - public PastMeasureDto setMetricId(int i) { + PastMeasureDto setMetricId(int i) { this.metricId = i; return this; } @@ -62,7 +62,7 @@ public class PastMeasureDto { return personId; } - public PastMeasureDto setPersonId(@Nullable Long l) { + PastMeasureDto setPersonId(@Nullable Long l) { this.personId = l; return this; } 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 7047aed0917..2490c9f0298 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 @@ -115,7 +115,7 @@ import org.sonar.db.version.v60.DropSnapshotIdColumnFromCeActivity; import org.sonar.db.version.v60.DropSnapshotIdColumnFromEvents; import org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; -import org.sonar.db.version.v60.FixProjectUuidOfDevelopers; +import org.sonar.db.version.v60.FixProjectUuidOfDeveloperProjects; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnEvents; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnMeasures; @@ -288,7 +288,7 @@ public class MigrationStepModule extends Module { MakeAnalysisUuidNotNullOnEvents.class, DropSnapshotIdColumnFromEvents.class, - FixProjectUuidOfDevelopers.class, + FixProjectUuidOfDeveloperProjects.class, // PROJECTS.UUID_PATH AddUuidPathColumnToProjects.class, PopulateUuidPathColumnOnProjects.class, diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java new file mode 100644 index 00000000000..2952a9fa5ff --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java @@ -0,0 +1,50 @@ +/* + * 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.BaseDataChange; +import org.sonar.db.version.MassUpdate; +import org.sonar.db.version.Select; +import org.sonar.db.version.SqlStatement; + +public class FixProjectUuidOfDeveloperProjects extends BaseDataChange { + + public FixProjectUuidOfDeveloperProjects(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select distinct developer_uuid from projects where qualifier = 'DEV_PRJ' and project_uuid != developer_uuid"); + massUpdate.update("update projects set project_uuid = developer_uuid where developer_uuid = ? and qualifier = 'DEV_PRJ' and project_uuid != developer_uuid"); + massUpdate.rowPluralName("developers in project"); + massUpdate.execute(FixProjectUuidOfDeveloperProjects::handleComponent); + } + + private static boolean handleComponent(Select.Row row, SqlStatement update) throws SQLException { + String developerUuid = row.getString(1); + update.setString(1, developerUuid); + + return true; + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java deleted file mode 100644 index 3e042c03f3a..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java +++ /dev/null @@ -1,50 +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.BaseDataChange; -import org.sonar.db.version.MassUpdate; -import org.sonar.db.version.Select; -import org.sonar.db.version.SqlStatement; - -public class FixProjectUuidOfDevelopers extends BaseDataChange { - - public FixProjectUuidOfDevelopers(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select distinct developer_uuid from projects where qualifier = 'DEV_PRJ'"); - massUpdate.update("update projects set project_uuid = developer_uuid where developer_uuid = ? and qualifier = 'DEV_PRJ'"); - massUpdate.rowPluralName("developers in project"); - massUpdate.execute((row, update) -> handleComponent(row, update)); - } - - private boolean handleComponent(Select.Row row, SqlStatement update) throws SQLException { - String developerUuid = row.getString(1); - update.setString(1, developerUuid); - - return true; - } -} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java new file mode 100644 index 00000000000..ea09dcc0838 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java @@ -0,0 +1,108 @@ +/* + * 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.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 org.assertj.core.api.Assertions.assertThat; + +public class FixProjectUuidOfDeveloperProjectsTest { + + private static final String TABLE_PROJECTS = "projects"; + private static final String PROJECT_UUID = "U1"; + private static final String FILE_UUID = "U2"; + private static final String DEVELOPER_UUID = "U3"; + private static final String DEV1_IN_PROJECT_UUID = "U4"; + private static final String DEV2_IN_PROJECT_UUID = "U5"; + + @Rule + public DbTester db = DbTester.createForSchema(System2.INSTANCE, FixProjectUuidOfDeveloperProjectsTest.class, + "in_progress_projects.sql"); + + private FixProjectUuidOfDeveloperProjects underTest = new FixProjectUuidOfDeveloperProjects(db.database()); + + @Test + public void migration_has_no_effect_on_empty_tables() throws SQLException { + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_PROJECTS)).isEqualTo(0); + } + + @Test + public void migration_fixes_project_uuid_of_rows_with_qualifier_DEV_PRJ() throws SQLException { + insertComponents(); + + underTest.execute(); + + verifyComponents(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertComponents(); + + underTest.execute(); + verifyComponents(); + + underTest.execute(); + verifyComponents(); + } + + private void verifyComponents() { + verifyProjectUuid(PROJECT_UUID, PROJECT_UUID); + verifyProjectUuid(FILE_UUID, PROJECT_UUID); + verifyProjectUuid(DEVELOPER_UUID, DEVELOPER_UUID); + verifyProjectUuid(DEV1_IN_PROJECT_UUID, DEVELOPER_UUID); + verifyProjectUuid(DEV2_IN_PROJECT_UUID, DEVELOPER_UUID); + } + + private void insertComponents() { + // regular project + insert(PROJECT_UUID, "TRK", null, PROJECT_UUID); + insert(FILE_UUID, "FIL", null, PROJECT_UUID); + // developer + insert(DEVELOPER_UUID, "DEV", DEVELOPER_UUID, DEVELOPER_UUID); + insert(DEV1_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); + insert(DEV2_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); + db.commit(); + } + + private void verifyProjectUuid(String uuid, @Nullable String expectedProjectUuid) { + Map rows = db.selectFirst("select project_uuid as \"projectUuid\" from projects where uuid='" + uuid + "'"); + assertThat(rows.get("projectUuid")).isEqualTo(expectedProjectUuid); + } + + private String insert(String uuid, String qualifier, @Nullable String developerUuid, String projectUuid) { + db.executeInsert( + TABLE_PROJECTS, + "UUID", uuid, + "DEVELOPER_UUID", developerUuid, + "PROJECT_UUID", projectUuid, + "ROOT_UUID", "NOT_USED", + "QUALIFIER", qualifier); + return uuid; + } +} diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest.java deleted file mode 100644 index c1d82346580..00000000000 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest.java +++ /dev/null @@ -1,108 +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.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 org.assertj.core.api.Assertions.assertThat; - -public class FixProjectUuidOfDevelopersTest { - - private static final String TABLE_PROJECTS = "projects"; - private static final String PROJECT_UUID = "U1"; - private static final String FILE_UUID = "U2"; - private static final String DEVELOPER_UUID = "U3"; - private static final String DEV1_IN_PROJECT_UUID = "U4"; - private static final String DEV2_IN_PROJECT_UUID = "U5"; - - @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, FixProjectUuidOfDevelopersTest.class, - "in_progress_projects.sql"); - - private FixProjectUuidOfDevelopers underTest = new FixProjectUuidOfDevelopers(db.database()); - - @Test - public void migration_has_no_effect_on_empty_tables() throws SQLException { - underTest.execute(); - - assertThat(db.countRowsOfTable(TABLE_PROJECTS)).isEqualTo(0); - } - - @Test - public void migration_fixes_project_uuid_of_rows_with_qualifier_DEV_PRJ() throws SQLException { - insertComponents(); - - underTest.execute(); - - verifyComponents(); - } - - @Test - public void migration_is_reentrant() throws SQLException { - insertComponents(); - - underTest.execute(); - verifyComponents(); - - underTest.execute(); - verifyComponents(); - } - - private void verifyComponents() { - verifyProjectUuid(PROJECT_UUID, PROJECT_UUID); - verifyProjectUuid(FILE_UUID, PROJECT_UUID); - verifyProjectUuid(DEVELOPER_UUID, DEVELOPER_UUID); - verifyProjectUuid(DEV1_IN_PROJECT_UUID, DEVELOPER_UUID); - verifyProjectUuid(DEV2_IN_PROJECT_UUID, DEVELOPER_UUID); - } - - private void insertComponents() { - // regular project - insert(PROJECT_UUID, "TRK", null, PROJECT_UUID); - insert(FILE_UUID, "FIL", null, PROJECT_UUID); - // developer - insert(DEVELOPER_UUID, "DEV", DEVELOPER_UUID, DEVELOPER_UUID); - insert(DEV1_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); - insert(DEV2_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); - db.commit(); - } - - private void verifyProjectUuid(String uuid, @Nullable String expectedProjectUuid) { - Map rows = db.selectFirst("select project_uuid as \"projectUuid\" from projects where uuid='" + uuid + "'"); - assertThat(rows.get("projectUuid")).isEqualTo(expectedProjectUuid); - } - - private String insert(String uuid, String qualifier, @Nullable String developerUuid, String projectUuid) { - db.executeInsert( - TABLE_PROJECTS, - "UUID", uuid, - "DEVELOPER_UUID", developerUuid, - "PROJECT_UUID", projectUuid, - "ROOT_UUID", "NOT_USED", - "QUALIFIER", qualifier); - return uuid; - } -} diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql new file mode 100644 index 00000000000..760728a8dc3 --- /dev/null +++ b/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql @@ -0,0 +1,22 @@ +CREATE TABLE "PROJECTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(400), + "UUID" VARCHAR(50) NOT NULL, + "ROOT_UUID" VARCHAR(50) NOT NULL, + "PROJECT_UUID" VARCHAR(50), + "MODULE_UUID" VARCHAR(50), + "MODULE_UUID_PATH" VARCHAR(4000), + "NAME" VARCHAR(2000), + "DESCRIPTION" VARCHAR(2000), + "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE, + "SCOPE" VARCHAR(3), + "QUALIFIER" VARCHAR(10), + "DEPRECATED_KEE" VARCHAR(400), + "PATH" VARCHAR(2000), + "LANGUAGE" VARCHAR(20), + "COPY_COMPONENT_UUID" VARCHAR(50), + "LONG_NAME" VARCHAR(2000), + "DEVELOPER_UUID" VARCHAR(50), + "CREATED_AT" TIMESTAMP, + "AUTHORIZATION_UPDATED_AT" BIGINT +); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest/in_progress_projects.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest/in_progress_projects.sql deleted file mode 100644 index 760728a8dc3..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDevelopersTest/in_progress_projects.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE TABLE "PROJECTS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "KEE" VARCHAR(400), - "UUID" VARCHAR(50) NOT NULL, - "ROOT_UUID" VARCHAR(50) NOT NULL, - "PROJECT_UUID" VARCHAR(50), - "MODULE_UUID" VARCHAR(50), - "MODULE_UUID_PATH" VARCHAR(4000), - "NAME" VARCHAR(2000), - "DESCRIPTION" VARCHAR(2000), - "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE, - "SCOPE" VARCHAR(3), - "QUALIFIER" VARCHAR(10), - "DEPRECATED_KEE" VARCHAR(400), - "PATH" VARCHAR(2000), - "LANGUAGE" VARCHAR(20), - "COPY_COMPONENT_UUID" VARCHAR(50), - "LONG_NAME" VARCHAR(2000), - "DEVELOPER_UUID" VARCHAR(50), - "CREATED_AT" TIMESTAMP, - "AUTHORIZATION_UPDATED_AT" BIGINT -); -- cgit v1.2.3