summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-16 19:04:09 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-16 19:04:09 +0100
commite0d70cf1dd9879b56de3ae1801c391685bc44f1f (patch)
tree6a27ed6b6dc25fa7d4755b1b82a9cb07bd834bbe /sonar-core
parent95f097f8487dd0577219e7d308deca2843562022 (diff)
downloadsonarqube-e0d70cf1dd9879b56de3ae1801c391685bc44f1f.tar.gz
sonarqube-e0d70cf1dd9879b56de3ae1801c391685bc44f1f.zip
SONAR-4535 Remove a project to a quality profile now uses MyBatis
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java15
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml4
-rw-r--r--sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java9
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property-result.xml22
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property.xml22
6 files changed, 72 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
index ab65fdde041..ed0a9c47b23 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
@@ -46,8 +46,8 @@ public class PropertiesDao implements BatchComponent, ServerComponent {
* If a resource ID is passed, the search is made on users who have specifically subscribed for the given resource.
*
* @param notificationDispatcherKey the key of the notification dispatcher
- * @param notificationChannelKey the key of the notification channel
- * @param resourceId the resource id
+ * @param notificationChannelKey the key of the notification channel
+ * @param resourceId the resource id
* @return the list of logins (maybe be empty - obviously)
*/
public List<String> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable Long resourceId) {
@@ -129,6 +129,17 @@ public class PropertiesDao implements BatchComponent, ServerComponent {
}
}
+ public void deleteProjectProperty(String key, Long projectId) {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ mapper.deleteProjectProperty(key, projectId);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
public void deleteGlobalProperties() {
SqlSession session = mybatis.openSession();
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
index d881040cf84..45aaa71e700 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
@@ -43,6 +43,8 @@ public interface PropertiesMapper {
void insert(PropertyDto property);
+ void deleteProjectProperty(@Param("key") String key, @Param("rId") Long resourceId);
+
void deleteGlobalProperty(String key);
void deleteAllProperties(String key);
diff --git a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
index 139e05508f4..fecc4be5e5e 100644
--- a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
@@ -73,6 +73,10 @@
VALUES (#{key}, #{resourceId}, #{userId}, #{value})
</insert>
+ <delete id="deleteProjectProperty" parameterType="map">
+ delete from properties where prop_key=#{key} and resource_id=#{rId} and user_id is null
+ </delete>
+
<delete id="deleteGlobalProperty" parameterType="string">
delete from properties where prop_key=#{id} and resource_id is null and user_id is null
</delete>
diff --git a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
index a8d1b3ca651..c234424a13c 100644
--- a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
@@ -166,6 +166,15 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void delete_project_property() {
+ setupData("delete_project_property");
+
+ dao.deleteProjectProperty("struts.one", 10L);
+
+ checkTables("delete_project_property", "properties");
+ }
+
+ @Test
public void deleteGlobalProperties() {
setupData("deleteGlobalProperties");
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property-result.xml
new file mode 100644
index 00000000000..00458094c34
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property-result.xml
@@ -0,0 +1,22 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- struts -->
+ <!--<properties id="3" prop_key="struts.one" text_value="one" resource_id="10" user_id="[null]"/>-->
+
+ <!-- commons -->
+ <properties id="4" prop_key="commonslang.one" text_value="two" resource_id="11" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="5" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="6" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+ <properties id="7" prop_key="commonslang.one" text_value="one" resource_id="12" user_id="[null]"/>
+
+ <projects id="10" kee="org.struts:struts"/>
+ <projects id="11" kee="org.apache:commons-lang"/>
+ <projects id="12" kee="other"/>
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property.xml
new file mode 100644
index 00000000000..27c48034999
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/delete_project_property.xml
@@ -0,0 +1,22 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- struts -->
+ <properties id="3" prop_key="struts.one" text_value="one" resource_id="10" user_id="[null]"/>
+
+ <!-- commons -->
+ <properties id="4" prop_key="commonslang.one" text_value="two" resource_id="11" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="5" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="6" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+ <properties id="7" prop_key="commonslang.one" text_value="one" resource_id="12" user_id="[null]"/>
+
+ <projects id="10" kee="org.struts:struts"/>
+ <projects id="11" kee="org.apache:commons-lang"/>
+ <projects id="12" kee="other"/>
+</dataset>