From: Sébastien Lesaint Date: Fri, 9 Sep 2016 09:43:26 +0000 (+0200) Subject: SONAR-7676 remove PropertyDao#deleteById and add deleteByQuery X-Git-Tag: 6.1-RC1~148 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5eb6d7a579e9fb8839e7c028ea6563e5110654ad;p=sonarqube.git SONAR-7676 remove PropertyDao#deleteById and add deleteByQuery the later is used by Governance --- diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java index 7af84391331..fb7718edcda 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -213,12 +213,19 @@ public class PropertiesDao implements Dao { } } - public int delete(DbSession dbSession, PropertyDto dto) { - return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getResourceId()); + /** + * Delete either global, user, component or component per user properties. + *

Behaves in exactly the same way as {@link #selectByQuery(PropertyQuery, DbSession)} but deletes rather than + * selects

+ * + * Used by Governance. + */ + public int deleteByQuery(DbSession dbSession, PropertyQuery query) { + return getMapper(dbSession).deleteByQuery(query); } - public void deleteById(DbSession dbSession, long id) { - getMapper(dbSession).deleteById(id); + public int delete(DbSession dbSession, PropertyDto dto) { + return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getResourceId()); } public void deleteProjectProperty(String key, Long projectId) { diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java index e438c73c8c9..05ea17e97fc 100644 --- a/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -63,5 +63,7 @@ public interface PropertiesMapper { int deleteGlobalProperty(@Param("key") String key); + int deleteByQuery(@Param("query") PropertyQuery query); + int renamePropertyKey(@Param("oldKey") String oldKey, @Param("newKey") String newKey); } diff --git a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index 206195eab86..d1fbc569e55 100644 --- a/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -249,12 +249,6 @@ - - delete from properties - where - id=#{id} - - delete from properties where @@ -287,6 +281,21 @@ and user_id is null + + delete from properties + + + and prop_key=#{query.key} + + + and resource_id=#{query.componentId} + + + and user_id=#{query.userId} + + + + update properties set prop_key=#{newKey} diff --git a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index e95511e8a3e..fa6a9ee3fb9 100644 --- a/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -679,55 +679,6 @@ public class PropertiesDaoTest { }; } - @Test - @UseDataProvider("possibleValuesProvider") - public void deleteById(String value) throws SQLException { - long id1 = insertProperty("global.key", value, null, null); - long id2 = insertProperty("component.key", value, 10L, null); - long id3 = insertProperty("user.key", value, null, 100L); - - underTest.deleteById(dbTester.getSession(), id1); - dbTester.getSession().commit(); - - assertThatPropertiesRow(id1) - .doesNotExist(); - assertThatPropertiesRow(id2) - .hasKey("component.key"); - assertThatPropertiesRow(id3) - .hasKey("user.key"); - - underTest.deleteById(dbTester.getSession(), id2); - dbTester.getSession().commit(); - - assertThatPropertiesRow(id2) - .doesNotExist(); - assertThatPropertiesRow(id3) - .hasKey("user.key"); - - underTest.deleteById(dbTester.getSession(), id3); - dbTester.getSession().commit(); - - assertThatPropertiesRow(id3) - .doesNotExist(); - } - - @DataProvider - public static Object[][] possibleValuesProvider() { - return new Object[][] { - {null}, - {""}, - {"some value"}, - {VALUE_SIZE_4000}, - {VALUE_SIZE_4001} - }; - } - - @Test - public void deleteById_does_not_fail_if_row_with_specified_id_does_not_exist() { - underTest.deleteById(dbTester.getSession(), 12L); - dbTester.getSession().commit(); - } - @Test public void delete_project_property() throws SQLException { long projectId1 = insertProject("A").getId();