summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-12-24 10:10:55 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-12-24 10:10:55 +0100
commite1af2f331051a08ea1f5dee369847340be85ad5e (patch)
tree802790d3ca7761c08324fe16247399ee3b862079 /sonar-core
parent937fb8fd998ea71d8697d927efaabe1de5ae34de (diff)
downloadsonarqube-e1af2f331051a08ea1f5dee369847340be85ad5e.tar.gz
sonarqube-e1af2f331051a08ea1f5dee369847340be85ad5e.zip
SONAR-4535 Update rule now use Java facade
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java20
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml15
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java16
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter-result.xml3
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter.xml3
6 files changed, 55 insertions, 4 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
index 482835a57b6..922efb2c782 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
@@ -72,10 +72,14 @@ public class RuleDao implements BatchComponent, ServerComponent {
}
}
+ public void update(RuleDto rule, SqlSession session) {
+ getMapper(session).update(rule);
+ }
+
public void update(RuleDto rule) {
SqlSession session = mybatis.openSession();
try {
- getMapper(session).update(rule);
+ update(rule, session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -144,6 +148,20 @@ public class RuleDao implements BatchComponent, ServerComponent {
}
}
+ public void update(RuleParamDto param, SqlSession session) {
+ getMapper(session).updateParameter(param);
+ }
+
+ public void update(RuleParamDto param) {
+ SqlSession session = mybatis.openSession();
+ try {
+ update(param, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
@CheckForNull
public RuleParamDto selectParamByRuleAndKey(Integer ruleId, String key, SqlSession session) {
return getMapper(session).selectParamByRuleAndKey(ruleId, key);
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
index 9b2698d9453..8c340b33569 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
@@ -45,4 +45,6 @@ public interface RuleMapper {
RuleParamDto selectParamByRuleAndKey(@Param("ruleId") Integer ruleId, @Param("key") String key);
void insertParameter(RuleParamDto param);
+
+ void updateParameter(RuleParamDto param);
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
index efa9a1f7290..95063093b9a 100644
--- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
@@ -41,7 +41,7 @@
</select>
<update id="update" parameterType="Rule">
- update rules set
+ UPDATE rules SET
plugin_rule_key=#{ruleKey},
plugin_name=#{repositoryKey},
description=#{description},
@@ -57,7 +57,7 @@
note_user_login=#{noteUserLogin},
note_created_at=#{noteCreatedAt},
note_updated_at=#{noteUpdatedAt}
- where id=#{id}
+ WHERE id=#{id}
</update>
<sql id="insertColumns">
@@ -105,10 +105,19 @@
</where>
</select>
- <insert id="insertParameter" parameterType="Rule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insertParameter" parameterType="RuleParam" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO rules_parameters (rule_id, name, param_type, default_value, description)
VALUES (#{ruleId}, #{name}, #{type}, #{defaultValue}, #{description})
</insert>
+ <update id="updateParameter" parameterType="RuleParam">
+ UPDATE rules_parameters SET
+ name=#{name},
+ param_type=#{type},
+ default_value=#{defaultValue},
+ description=#{description}
+ WHERE id=#{id}
+ </update>
+
</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
index f58e4790a15..43e0b9ce660 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
@@ -272,4 +272,20 @@ public class RuleDaoTest extends AbstractDaoTestCase {
checkTables("insert_parameter", "rules_parameters");
}
+
+ @Test
+ public void update_parameter() {
+ setupData("update_parameter");
+
+ RuleParamDto param = new RuleParamDto()
+ .setId(1)
+ .setName("format")
+ .setType("STRING")
+ .setDefaultValue("^[a-z]+(\\.[a-z][a-z0-9]*)*$")
+ .setDescription("Regular expression used to check the package names against.");
+
+ dao.update(param);
+
+ checkTables("update_parameter", "rules_parameters");
+ }
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter-result.xml
new file mode 100644
index 00000000000..d61889441d9
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter-result.xml
@@ -0,0 +1,3 @@
+<dataset>
+ <rules_parameters id="1" rule_id="1" name="format" param_type="STRING" default_value="^[a-z]+(\.[a-z][a-z0-9]*)*$" description="Regular expression used to check the package names against."/>
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter.xml
new file mode 100644
index 00000000000..5208b7a4a4c
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update_parameter.xml
@@ -0,0 +1,3 @@
+<dataset>
+ <rules_parameters id="1" rule_id="1" name="max" param_type="INTEGER" default_value="30" description="My Parameter"/>
+</dataset>