diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-06-02 18:13:20 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-06-02 18:19:33 +0200 |
commit | 5381835db07e40e02cd4e9d214988ab6418dffd6 (patch) | |
tree | c40c87a9c02cd1202bac2109657da9e4aaba674c /server | |
parent | 0c318501905650d920a44a429edaa43f29f7cf5b (diff) | |
download | sonarqube-5381835db07e40e02cd4e9d214988ab6418dffd6.tar.gz sonarqube-5381835db07e40e02cd4e9d214988ab6418dffd6.zip |
SONAR-6571 fix use of Boolean for boolean db column in Metrics table
Diffstat (limited to 'server')
12 files changed, 159 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java index 23956d9bbba..c87da9be3a7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java @@ -80,7 +80,6 @@ public class GlobalAction implements BatchWsAction { private void addMetrics(GlobalRepositories ref, DbSession session) { for (MetricDto metric : dbClient.metricDao().selectEnabled(session)) { - Boolean optimizedBestValue = metric.isOptimizedBestValue(); ref.addMetric( new org.sonar.batch.protocol.input.Metric(metric.getId(), metric.getKey(), metric.getValueType(), @@ -91,7 +90,7 @@ public class GlobalAction implements BatchWsAction { metric.isUserManaged(), metric.getWorstValue(), metric.getBestValue(), - optimizedBestValue != null ? optimizedBestValue : false)); + metric.isOptimizedBestValue())); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java index cde817e8024..a6371738726 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java @@ -70,6 +70,7 @@ import org.sonar.server.db.migrations.v52.DropDependenciesComponentColumns; import org.sonar.server.db.migrations.v52.FeedDependenciesComponentUuids; import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid; import org.sonar.server.db.migrations.v52.FeedFileSourcesDataType; +import org.sonar.server.db.migrations.v52.FeedMetricsBooleans; import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation; @@ -144,6 +145,7 @@ public class MigrationStepModule extends Module { FeedDependenciesComponentUuids.class, DropDependenciesComponentColumns.class, FeedFileSourcesDataType.class, + FeedMetricsBooleans.class, AddDependenciesColumns.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleans.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleans.java new file mode 100644 index 00000000000..27b75343e12 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleans.java @@ -0,0 +1,42 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v52; + +import java.sql.SQLException; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; + +public class FeedMetricsBooleans extends BaseDataChange { + + public FeedMetricsBooleans(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.prepareUpsert("update metrics set OPTIMIZED_BEST_VALUE=?, HIDDEN=?, DELETE_HISTORICAL_DATA=? where user_managed=? or OPTIMIZED_BEST_VALUE is null or HIDDEN is null or DELETE_HISTORICAL_DATA is null") + .setBoolean(1, false) + .setBoolean(2, false) + .setBoolean(3, false) + .setBoolean(4, true) + .execute().commit(); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java index d1511cea26c..59b9054b14e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java @@ -158,6 +158,9 @@ public class CreateAction implements MetricsWsAction { .setUserManaged(true) .setDirection(0) .setQualitative(false) + .setHidden(false) + .setOptimizedBestValue(false) + .setDeleteHistoricalData(false) .setOrigin("GUI"); dbClient.metricDao().insert(dbSession, metric); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java index b0522568bed..abc50e78e77 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() throws Exception { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(54); + assertThat(container.size()).isEqualTo(55); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java new file mode 100644 index 00000000000..aac8b55a99b --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +package org.sonar.server.db.migrations.v52; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.db.migrations.MigrationStep; + +public class FeedMetricsBooleansTest { + @ClassRule + public static DbTester db = new DbTester().schema(FeedMetricsBooleansTest.class, "schema.sql"); + + MigrationStep migration; + + @Before + public void setUp() { + db.executeUpdateSql("truncate table metrics"); + + migration = new FeedMetricsBooleans(db.database()); + } + + @Test + public void migrate_empty_db() throws Exception { + migration.execute(); + } + + @Test + public void migrate() throws Exception { + db.prepareDbUnit(this.getClass(), "migrate.xml"); + migration.execute(); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "metrics"); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java index 1f77cf7c866..d83ea6e9491 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java @@ -99,9 +99,9 @@ public class MetricDaoTest { assertThat(result.isUserManaged()).isTrue(); assertThat(result.getWorstValue()).isNull(); assertThat(result.getBestValue()).isNull(); - assertThat(result.isOptimizedBestValue()).isNull(); - assertThat(result.isDeleteHistoricalData()).isNull(); - assertThat(result.isHidden()).isNull(); + assertThat(result.isOptimizedBestValue()).isFalse(); + assertThat(result.isDeleteHistoricalData()).isFalse(); + assertThat(result.isHidden()).isFalse(); assertThat(result.isEnabled()).isTrue(); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate-result.xml new file mode 100644 index 00000000000..026d2dbe83a --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate-result.xml @@ -0,0 +1,7 @@ +<dataset> + + <metrics id="1" user_managed="[true]" optimized_best_value="[false]" hidden="[false]" delete_historical_data="[false]" /> + <metrics id="2" user_managed="[false]" optimized_best_value="[true]" hidden="[true]" delete_historical_data="[true]" /> + <metrics id="3" user_managed="[false]" optimized_best_value="[false]" hidden="[false]" delete_historical_data="[false]"/> + +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate.xml new file mode 100644 index 00000000000..7fee0be9b77 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/migrate.xml @@ -0,0 +1,7 @@ +<dataset> + + <metrics id="1" user_managed="[true]" optimized_best_value="[null]" hidden="[null]" delete_historical_data="[null]"/> + <metrics id="2" user_managed="[false]" optimized_best_value="[true]" hidden="[true]" delete_historical_data="[true]"/> + <metrics id="3" user_managed="[false]" optimized_best_value="[null]" hidden="[null]" delete_historical_data="[null]"/> + +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/schema.sql new file mode 100644 index 00000000000..d65487d7677 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedMetricsBooleansTest/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE "METRICS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "USER_MANAGED" BOOLEAN DEFAULT FALSE, + "OPTIMIZED_BEST_VALUE" BOOLEAN, + "HIDDEN" BOOLEAN, + "DELETE_HISTORICAL_DATA" BOOLEAN +); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml index 630722c4d75..8dc260a5fae 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml @@ -1,7 +1,7 @@ <dataset> <metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric" - qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]" - origin="GUI" delete_historical_data="[null]" user_managed="[true]"/> + qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[false]" best_value="[null]" direction="0" hidden="[false]" + origin="GUI" delete_historical_data="[false]" user_managed="[true]"/> </dataset> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/916_feed_metrics_booleans.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/916_feed_metrics_booleans.rb new file mode 100644 index 00000000000..347164f04ef --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/916_feed_metrics_booleans.rb @@ -0,0 +1,31 @@ +# +# 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 5.2 +# SONAR-6571 +# +class FeedMetricsBooleans < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.FeedMetricsBooleans') + end + +end |