From: Benoit Date: Tue, 14 May 2019 15:34:58 +0000 (+0200) Subject: SONAR-12061 Purge refresh flag on portfolio deletion X-Git-Tag: 7.8~226 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f167719e46408daff650cda6b4df5c0a547d2257;p=sonarqube.git SONAR-12061 Purge refresh flag on portfolio deletion --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java index 842e1f270fa..5418eb9a100 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java @@ -73,8 +73,8 @@ public class InternalComponentPropertiesDao implements Dao { return getMapper(dbSession).selectByComponentUuidAndKey(componentUuid, key); } - public int deleteByComponentUuidAndKey(DbSession dbSession, String componentUuid, String key) { - return getMapper(dbSession).deleteByComponentUuidAndKey(componentUuid, key); + public int deleteByComponentUuid(DbSession dbSession, String componentUuid) { + return getMapper(dbSession).deleteByComponentUuidAndKey(componentUuid); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java index 9daa9c641f8..dedf75566ab 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java @@ -37,7 +37,7 @@ public interface InternalComponentPropertiesMapper { void replaceValue(@Param("componentUuid") String componentUuid, @Param("key") String key, @Param("oldValue") String oldValue, @Param("newValue") String newValue, @Param("updatedAt") Long updatedAt); - int deleteByComponentUuidAndKey(@Param("componentUuid") String componentUuid, @Param("key") String key); + int deleteByComponentUuidAndKey(@Param("componentUuid") String componentUuid); Set selectDbKeys(@Param("key") String key, @Param("value") String value); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml index ec18d5afa4c..0a079a62524 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml @@ -83,7 +83,6 @@ DELETE FROM internal_component_props component_uuid = #{componentUuid, jdbcType=VARCHAR} - AND kee = #{key, jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java index 28f50e60b0c..930250b2943 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java @@ -45,6 +45,7 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.organization.OrganizationTesting; import org.sonar.db.permission.template.PermissionTemplateDbTester; import org.sonar.db.plugin.PluginDbTester; +import org.sonar.db.property.InternalComponentPropertyDbTester; import org.sonar.db.property.PropertyDbTester; import org.sonar.db.qualitygate.QualityGateDbTester; import org.sonar.db.qualityprofile.QualityProfileDbTester; @@ -92,6 +93,7 @@ public class DbTester extends AbstractDbTester { private final WebhookDbTester webhookDbTester; private final WebhookDeliveryDbTester webhookDeliveryDbTester; private final AlmDbTester almDbTester; + private final InternalComponentPropertyDbTester internalComponentPropertyTester; private DbTester(System2 system2, @Nullable String schemaPath, MyBatisConfExtension... confExtensions) { super(TestDb.create(schemaPath, confExtensions)); @@ -118,6 +120,7 @@ public class DbTester extends AbstractDbTester { this.webhookDbTester = new WebhookDbTester(this); this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this); this.almDbTester = new AlmDbTester(this); + this.internalComponentPropertyTester = new InternalComponentPropertyDbTester(this); } public static DbTester create() { @@ -280,6 +283,10 @@ public class DbTester extends AbstractDbTester { return almDbTester; } + public InternalComponentPropertyDbTester internalComponentProperties() { + return internalComponentPropertyTester; + } + @Override protected void after() { if (session != null) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java index 317492888ac..fafd9c85dee 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java @@ -151,19 +151,21 @@ public class InternalComponentPropertiesDaoTest { } @Test - public void delete_by_component_uuid_and_key_deletes_property() { - saveDto(); + public void delete_by_component_uuid_deletes_all_properties_with_given_componentUuid() { + underTest.insertOrUpdate(dbSession, SOME_COMPONENT, SOME_KEY, SOME_VALUE); + underTest.insertOrUpdate(dbSession, SOME_COMPONENT, "other_key", "foo"); + underTest.insertOrUpdate(dbSession, "other_component", SOME_KEY, SOME_VALUE); - assertThat(underTest.deleteByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isEqualTo(1); + assertThat(underTest.deleteByComponentUuid(dbSession, SOME_COMPONENT)).isEqualTo(2); assertThat(underTest.selectByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isEmpty(); + assertThat(underTest.selectByComponentUuidAndKey(dbSession, "other_component", SOME_KEY)).isNotEmpty(); } @Test public void delete_by_component_uuid_and_key_does_nothing_if_property_doesnt_exist() { saveDto(); - assertThat(underTest.deleteByComponentUuidAndKey(dbSession, SOME_COMPONENT, "other_key")).isEqualTo(0); - assertThat(underTest.deleteByComponentUuidAndKey(dbSession, "other_component", SOME_KEY)).isEqualTo(0); + assertThat(underTest.deleteByComponentUuid(dbSession, "other_component")).isEqualTo(0); assertThat(underTest.selectByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isNotEmpty(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDbTester.java new file mode 100644 index 00000000000..4588ad91853 --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDbTester.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.property; + +import java.util.Optional; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.DbTester; + +public class InternalComponentPropertyDbTester { + private final DbTester db; + private final DbClient dbClient; + private final DbSession dbSession; + + public InternalComponentPropertyDbTester(DbTester db) { + this.db = db; + this.dbClient = db.getDbClient(); + this.dbSession = db.getSession(); + } + + public void insertProperty(String componentUuid, String key, String value) { + dbClient.internalComponentPropertiesDao().insertOrUpdate(dbSession, componentUuid, key, value); + db.commit(); + } + + public Optional getProperty(String componentUuid, String key) { + return dbClient.internalComponentPropertiesDao().selectByComponentUuidAndKey(dbSession, componentUuid, key); + } +} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalComponentProperties.java b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalComponentProperties.java new file mode 100644 index 00000000000..eaf1d4f4a22 --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalComponentProperties.java @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.property; + +/** + * List of internal component property keys + */ +public class InternalComponentProperties { + + public static final String PORTFOLIO_REFRESH_STATE = "portfolio.refresh.state"; + + private InternalComponentProperties() { + // Static constants only + } +}