Browse Source

SONAR-12061 Purge refresh flag on portfolio deletion

tags/7.8
Benoit 5 years ago
parent
commit
f167719e46

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesDao.java View 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);
}

/**

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/property/InternalComponentPropertiesMapper.java View 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);
}

+ 0
- 1
server/sonar-db-dao/src/main/resources/org/sonar/db/property/InternalComponentPropertiesMapper.xml View File

@@ -83,7 +83,6 @@
DELETE FROM internal_component_props
<where>
component_uuid = #{componentUuid, jdbcType=VARCHAR}
AND kee = #{key, jdbcType=VARCHAR}
</where>
</delete>


+ 7
- 0
server/sonar-db-dao/src/test/java/org/sonar/db/DbTester.java View 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) {

+ 7
- 5
server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertiesDaoTest.java View 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();
}


+ 46
- 0
server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDbTester.java View File

@@ -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);
}
}

+ 32
- 0
server/sonar-server-common/src/main/java/org/sonar/server/property/InternalComponentProperties.java View File

@@ -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
}
}

Loading…
Cancel
Save