diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-12-24 11:30:40 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-12-24 11:30:40 +0100 |
commit | f43ee223be35c6162b9f9c4b976c8fd4c2d488b0 (patch) | |
tree | bf8aa20c986edb41069854a35a7ad3fe55da0a98 /sonar-core/src/main | |
parent | e1af2f331051a08ea1f5dee369847340be85ad5e (diff) | |
download | sonarqube-f43ee223be35c6162b9f9c4b976c8fd4c2d488b0.tar.gz sonarqube-f43ee223be35c6162b9f9c4b976c8fd4c2d488b0.zip |
SONAR-4535 Delete rule now use Java facade
Diffstat (limited to 'sonar-core/src/main')
3 files changed, 107 insertions, 65 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java index 1ab38d9a113..069b07d7cf6 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java @@ -83,6 +83,40 @@ public class ActiveRuleDao implements ServerComponent { return session.getMapper(ActiveRuleMapper.class).selectParamByActiveRuleAndKey(activeRuleId, key); } + public List<ActiveRuleDto> selectByRuleId(Integer ruleId) { + SqlSession session = mybatis.openSession(); + try { + return selectByRuleId(ruleId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByRuleId(Integer ruleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectByRuleId(ruleId); + } + + public List<ActiveRuleDto> selectByIds(List<Integer> ids) { + SqlSession session = mybatis.openSession(); + try { + return selectByIds(ids, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByIds(Collection<Integer> ids, SqlSession session) { + if (ids.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectByIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; + } public void insert(ActiveRuleDto dto, SqlSession session) { session.getMapper(ActiveRuleMapper.class).insert(dto); @@ -112,131 +146,124 @@ public class ActiveRuleDao implements ServerComponent { } } - public void insert(ActiveRuleParamDto dto, SqlSession session) { - session.getMapper(ActiveRuleMapper.class).insertParameter(dto); - } - - public void insert(ActiveRuleParamDto dto) { + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId) { SqlSession session = mybatis.openSession(); try { - insert(dto, session); - session.commit(); + return selectParamsByActiveRuleId(activeRuleId, session); } finally { MyBatis.closeQuietly(session); } } - public void update(ActiveRuleParamDto dto, SqlSession session) { - session.getMapper(ActiveRuleMapper.class).updateParameter(dto); + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectParamsByActiveRuleId(activeRuleId); } - public void update(ActiveRuleParamDto dto) { + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(List<Integer> activeRuleIds) { SqlSession session = mybatis.openSession(); try { - update(dto, session); - session.commit(); + return selectParamsByActiveRuleIds(activeRuleIds, session); } finally { MyBatis.closeQuietly(session); } } - public void delete(Integer activeRuleId, SqlSession session) { - session.getMapper(ActiveRuleMapper.class).delete(activeRuleId); + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(Collection<Integer> activeRuleIds, SqlSession session) { + if (activeRuleIds.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleParamDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(activeRuleIds), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByActiveRuleIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; } - public void delete(Integer activeRuleId) { + public void insert(ActiveRuleParamDto dto, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).insertParameter(dto); + } + + public void insert(ActiveRuleParamDto dto) { SqlSession session = mybatis.openSession(); try { - delete(activeRuleId, session); + insert(dto, session); session.commit(); } finally { MyBatis.closeQuietly(session); } } - public void deleteParameter(Integer activeRuleParamId, SqlSession session) { - session.getMapper(ActiveRuleMapper.class).deleteParameter(activeRuleParamId); + public void update(ActiveRuleParamDto dto, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).updateParameter(dto); } - public void deleteParameter(Integer activeRuleParamId) { + public void update(ActiveRuleParamDto dto) { SqlSession session = mybatis.openSession(); try { - deleteParameter(activeRuleParamId, session); + update(dto, session); session.commit(); } finally { MyBatis.closeQuietly(session); } } - public void deleteParameters(Integer activeRuleId, SqlSession session) { - session.getMapper(ActiveRuleMapper.class).deleteParameters(activeRuleId); + public void delete(Integer activeRuleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).delete(activeRuleId); } - public void deleteParameters(Integer activeRuleId) { + public void delete(Integer activeRuleId) { SqlSession session = mybatis.openSession(); try { - deleteParameters(activeRuleId, session); + delete(activeRuleId, session); session.commit(); } finally { MyBatis.closeQuietly(session); } } - public List<ActiveRuleDto> selectByIds(List<Integer> ids) { + public void deleteFromRule(Integer ruleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteFromRule(ruleId); + } + + public void deleteFromRule(Integer ruleId) { SqlSession session = mybatis.openSession(); try { - return selectByIds(ids, session); + deleteFromRule(ruleId, session); + session.commit(); } finally { MyBatis.closeQuietly(session); } } - public List<ActiveRuleDto> selectByIds(Collection<Integer> ids, SqlSession session) { - if (ids.isEmpty()) { - return Collections.emptyList(); - } - List<ActiveRuleDto> dtosList = newArrayList(); - List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); - for (List<Integer> idsPartition : idsPartitionList) { - List<ActiveRuleDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectByIds", newArrayList(idsPartition)); - dtosList.addAll(dtos); - } - return dtosList; + public void deleteParameter(Integer activeRuleParamId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParameter(activeRuleParamId); } - public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId) { + public void deleteParameter(Integer activeRuleParamId) { SqlSession session = mybatis.openSession(); try { - return selectParamsByActiveRuleId(activeRuleId, session); + deleteParameter(activeRuleParamId, session); + session.commit(); } finally { MyBatis.closeQuietly(session); } } - public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId, SqlSession session) { - return session.getMapper(ActiveRuleMapper.class).selectParamsByActiveRuleId(activeRuleId); + public void deleteParameters(Integer activeRuleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParameters(activeRuleId); } - public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(List<Integer> activeRuleIds) { + public void deleteParameters(Integer activeRuleId) { SqlSession session = mybatis.openSession(); try { - return selectParamsByActiveRuleIds(activeRuleIds, session); + deleteParameters(activeRuleId, session); + session.commit(); } finally { MyBatis.closeQuietly(session); } } - public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(Collection<Integer> activeRuleIds, SqlSession session) { - if (activeRuleIds.isEmpty()) { - return Collections.emptyList(); - } - List<ActiveRuleParamDto> dtosList = newArrayList(); - List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(activeRuleIds), 1000); - for (List<Integer> idsPartition : idsPartitionList) { - List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByActiveRuleIds", newArrayList(idsPartition)); - dtosList.addAll(dtos); - } - return dtosList; - } } diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java index dd142cd99bc..02d9a9b3604 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java @@ -23,7 +23,6 @@ package org.sonar.core.qualityprofile.db; import org.apache.ibatis.annotations.Param; import javax.annotation.CheckForNull; - import java.util.List; public interface ActiveRuleMapper { @@ -34,7 +33,11 @@ public interface ActiveRuleMapper { @CheckForNull ActiveRuleDto selectByProfileAndRule(@Param("profileId") Integer profileId, @Param("ruleId") Integer ruleId); - List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId); + List<ActiveRuleDto> selectByRuleId(Integer ruleId); + + void insert(ActiveRuleDto dto); + + void update(ActiveRuleDto dto); @CheckForNull ActiveRuleParamDto selectParamById(Integer activeRuleParamId); @@ -42,9 +45,7 @@ public interface ActiveRuleMapper { @CheckForNull ActiveRuleParamDto selectParamByActiveRuleAndKey(@Param("activeRuleId") Integer activeRuleId, @Param("key") String key); - void insert(ActiveRuleDto dto); - - void update(ActiveRuleDto dto); + List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId); void insertParameter(ActiveRuleParamDto dto); @@ -52,6 +53,8 @@ public interface ActiveRuleMapper { void delete(Integer activeRuleId); + void deleteFromRule(Integer ruleId); + void deleteParameters(Integer activeRuleId); void deleteParameter(Integer activeRuleParamId); diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml index 66346a0f28e..d7e0e5476b5 100644 --- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml @@ -27,7 +27,7 @@ SELECT <include refid="activeRuleColumns"/> FROM active_rules a <where> - AND id=#{id} + AND a.id=#{id} </where> </select> @@ -35,7 +35,15 @@ SELECT <include refid="activeRuleColumns"/> FROM active_rules a <where> - AND profile_id=#{profileId} + AND a.profile_id=#{profileId} + AND a.rule_id=#{ruleId} + </where> + </select> + + <select id="selectByRuleId" parameterType="Integer" resultType="ActiveRule"> + SELECT <include refid="activeRuleColumns"/> + FROM active_rules a + <where> AND rule_id=#{ruleId} </where> </select> @@ -44,7 +52,7 @@ SELECT <include refid="activeRuleParamColumns"/> FROM active_rule_parameters p <where> - AND id=#{id} + AND p.id=#{id} </where> </select> @@ -52,8 +60,8 @@ SELECT <include refid="activeRuleParamColumns"/> FROM active_rule_parameters p <where> - AND active_rule_id=#{activeRuleId} - AND rules_parameter_key=#{key} + AND p.active_rule_id=#{activeRuleId} + AND p.rules_parameter_key=#{key} </where> </select> @@ -93,6 +101,10 @@ DELETE FROM active_rules WHERE id=#{id} </update> + <update id="deleteFromRule" parameterType="Integer"> + DELETE FROM active_rules WHERE rule_id=#{ruleId} + </update> + <update id="deleteParameters" parameterType="Integer"> DELETE FROM active_rule_parameters WHERE active_rule_id=#{id} </update> |