]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12061 Purge refresh flag on portfolio deletion
authorBenoit <benoit.gianinetti@sonarsource.com>
Tue, 14 May 2019 15:34:58 +0000 (17:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 15 May 2019 18:21:12 +0000 (20:21 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java
server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDbTester.java [new file with mode: 0644]
server/sonar-server-common/src/main/java/org/sonar/server/property/InternalComponentProperties.java [new file with mode: 0644]

index 842e1f270fa43874a19ef74a024338970d757693..5418eb9a1009b3e38be605f30e967db7acf63c0b 100644 (file)
@@ -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);
   }
 
   /**
index 9daa9c641f82762a986ef74d49cff62dec6a4cd5..dedf75566ab4bb20c5bfd6d772f3a0647a421d09 100644 (file)
@@ -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<String> selectDbKeys(@Param("key") String key, @Param("value") String value);
 }
index ec18d5afa4ca3bdbaf7b505c6c028d1083703cd5..0a079a62524824184331434fa0afbc7532ef3c60 100644 (file)
@@ -83,7 +83,6 @@
     DELETE FROM internal_component_props
     <where>
       component_uuid = #{componentUuid, jdbcType=VARCHAR}
-      AND kee = #{key, jdbcType=VARCHAR}
     </where>
   </delete>
 
index 28f50e60b0c6100e9cf2a8b6b0e8f6f5fb238579..930250b29438431fc428624df7356f5b7974b2ca 100644 (file)
@@ -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<TestDb> {
   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<TestDb> {
     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<TestDb> {
     return almDbTester;
   }
 
+  public InternalComponentPropertyDbTester internalComponentProperties() {
+    return internalComponentPropertyTester;
+  }
+
   @Override
   protected void after() {
     if (session != null) {
index 317492888acfda3b575facb0f15be3f2a4bde0dd..fafd9c85dee60afe037cdbe074f82a6c7c3cc735 100644 (file)
@@ -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 (file)
index 0000000..4588ad9
--- /dev/null
@@ -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<InternalComponentPropertyDto> 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 (file)
index 0000000..eaf1d4f
--- /dev/null
@@ -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
+  }
+}