]> source.dussan.org Git - sonarqube.git/commitdiff
Add PropertiesDao.deleteById
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 11 Apr 2016 15:01:56 +0000 (17:01 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 11 Apr 2016 15:38:13 +0000 (17:38 +0200)
sonar-db/src/main/java/org/sonar/db/property/PropertiesDao.java
sonar-db/src/main/java/org/sonar/db/property/PropertiesMapper.java
sonar-db/src/main/resources/org/sonar/db/property/PropertiesMapper.xml
sonar-db/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete-result.xml [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete.xml [new file with mode: 0644]

index 111bf7ba8b0cb1479890ade1a36d3533270d98f0..b7325cee8a3c9558de5039942f5ee6048fb25bb3 100644 (file)
@@ -182,6 +182,10 @@ public class PropertiesDao implements Dao {
     }
   }
 
+  public void deleteById(DbSession dbSession, long id) {
+    dbSession.getMapper(PropertiesMapper.class).deleteById(id);
+  }
+
   public void deleteProjectProperty(String key, Long projectId) {
     DbSession session = mybatis.openSession(false);
     try {
index e4d09bd4732bfd8ab0a3cf72dd14a6c2200f9fb4..a90fed439af6a1b3e4a1cdff6bc4814a7f13a387 100644 (file)
@@ -48,6 +48,8 @@ public interface PropertiesMapper {
 
   void insert(PropertyDto property);
 
+  void deleteById(long id);
+
   void deleteProjectProperty(@Param("key") String key, @Param("rId") Long resourceId);
 
   void deleteProjectProperties(@Param("key") String key, @Param("value") String value);
index d36c205772caa3ec9da6726a8422722a334dee65..afb6f9d5c1dd9351b8773c4072e2a54e7a580984 100644 (file)
     VALUES (#{key}, #{resourceId}, #{userId}, #{value})
   </insert>
 
+  <delete id="deleteById" parameterType="long">
+    delete from properties where id=#{id}
+  </delete>
+
   <delete id="deleteProjectProperty" parameterType="map">
     delete from properties where prop_key=#{key} and resource_id=#{rId} and user_id is null
   </delete>
index 0071be12609966d7534409e65de23191657ab415..a31013ac096b66831fb2203bcf9e09b54935b624 100644 (file)
@@ -216,6 +216,16 @@ public class PropertiesDaoTest {
     dbTester.assertDbUnit(getClass(), "insert-result.xml", "properties");
   }
 
+  @Test
+  public void delete_property_by_id() {
+    dbTester.prepareDbUnit(getClass(), "delete.xml");
+
+    dao.deleteById(dbTester.getSession(), 1L);
+    dbTester.getSession().commit();
+
+    dbTester.assertDbUnit(getClass(), "delete-result.xml", "properties");
+  }
+
   @Test
   public void delete_project_property() {
     dbTester.prepareDbUnit(getClass(), "delete_project_property.xml");
diff --git a/sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete-result.xml b/sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete-result.xml
new file mode 100644 (file)
index 0000000..ef4ec2a
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <!-- global -->
+  <!--<properties id="1" prop_key="global.key" text_value="global" resource_id="[null]" user_id="[null]"/>-->
+
+  <!-- project -->
+  <properties id="2" prop_key="project.key" text_value="project" resource_id="10" user_id="[null]"/>
+
+  <!-- user -->
+  <properties id="3" prop_key="user.key" text_value="user" resource_id="[null]" user_id="100"/>
+
+  <!-- null value -->
+  <properties id="4" prop_key="null.value" text_value="not null" resource_id="[null]" user_id="[null]"/>
+</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete.xml b/sonar-db/src/test/resources/org/sonar/db/property/PropertiesDaoTest/delete.xml
new file mode 100644 (file)
index 0000000..5229a2b
--- /dev/null
@@ -0,0 +1,14 @@
+<dataset>
+
+  <!-- global -->
+  <properties id="1" prop_key="global.key" text_value="global" resource_id="[null]" user_id="[null]"/>
+
+  <!-- project -->
+  <properties id="2" prop_key="project.key" text_value="project" resource_id="10" user_id="[null]"/>
+
+  <!-- user -->
+  <properties id="3" prop_key="user.key" text_value="user" resource_id="[null]" user_id="100"/>
+
+  <!-- null value -->
+  <properties id="4" prop_key="null.value" text_value="not null" resource_id="[null]" user_id="[null]"/>
+</dataset>