summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-03-24 17:39:57 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-03-29 19:12:00 +0200
commite2e23d7aefd4b8a0938412327f2d9f57c3389cda (patch)
tree511260600233b8d5ae03589cb6b5d8aa025a312a
parent9fc9cbd7ed08be84e9f16dc0cdacc41dff63acad (diff)
downloadsonarqube-e2e23d7aefd4b8a0938412327f2d9f57c3389cda.tar.gz
sonarqube-e2e23d7aefd4b8a0938412327f2d9f57c3389cda.zip
SONAR-7470 Remove 'manual' from SQL queries
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java48
-rw-r--r--sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java12
-rw-r--r--sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java6
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml11
-rw-r--r--sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java28
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabled.xml (renamed from sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml)9
9 files changed, 43 insertions, 81 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
index 3936627a40c..60b47e10347 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java
@@ -88,7 +88,7 @@ public class DebtModelBackup {
DbSession session = dbClient.openSession(false);
try {
List<RuleDebt> rules = newArrayList();
- for (RuleDto rule : dbClient.ruleDao().selectEnabledAndNonManual(session)) {
+ for (RuleDto rule : dbClient.ruleDao().selectEnabled(session)) {
if (languageKey == null || languageKey.equals(rule.getLanguage())) {
RuleDebt ruleDebt = toRuleDebt(rule);
if (ruleDebt != null) {
@@ -112,7 +112,7 @@ public class DebtModelBackup {
DbSession session = dbClient.openSession(false);
try {
// Restore rules
- List<RuleDto> ruleDtos = dbClient.ruleDao().selectEnabledAndNonManual(session);
+ List<RuleDto> ruleDtos = dbClient.ruleDao().selectEnabled(session);
if (!ruleDtos.isEmpty()) {
// Load default rule definitions
@@ -215,7 +215,7 @@ public class DebtModelBackup {
}
private List<RuleDto> rules(@Nullable String languageKey, DbSession session) {
- List<RuleDto> rules = dbClient.ruleDao().selectEnabledAndNonManual(session);
+ List<RuleDto> rules = dbClient.ruleDao().selectEnabled(session);
if (languageKey == null) {
return rules;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
index c6c3cd28a5d..36ad359472e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -147,7 +147,7 @@ public class RegisterRules implements Startable {
private Map<RuleKey, RuleDto> loadRules(DbSession session) {
Map<RuleKey, RuleDto> rules = new HashMap<>();
- for (RuleDto rule : dbClient.ruleDao().selectByNonManual(session)) {
+ for (RuleDto rule : dbClient.ruleDao().selectAll(session)) {
rules.put(rule.getKey(), rule);
}
return rules;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java
index e3600f906d6..5ffb6f0fd37 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java
@@ -57,7 +57,7 @@ public class ListAction implements RulesWsAction {
final ListResponse.Builder listResponseBuilder = ListResponse.newBuilder();
final ListResponse.Rule.Builder ruleBuilder = ListResponse.Rule.newBuilder();
try {
- dbClient.ruleDao().selectEnabledAndNonManual(dbSession, new ResultHandler() {
+ dbClient.ruleDao().selectEnabled(dbSession, new ResultHandler() {
@Override
public void handleResult(ResultContext resultContext) {
RuleDto dto = (RuleDto) resultContext.getResultObject();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java
index 8059f475f04..f1b87603ddb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java
@@ -114,7 +114,7 @@ public class DebtModelBackupTest {
@Test
public void backup() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(
+ when(ruleDao.selectEnabled(session)).thenReturn(
newArrayList(
// Rule with overridden debt values
new RuleDto().setRepositoryKey("squid").setRuleKey("UselessImportCheck")
@@ -150,7 +150,7 @@ public class DebtModelBackupTest {
@Test
public void backup_with_disabled_rules() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
// Debt disabled
new RuleDto().setRepositoryKey("squid").setRuleKey("UselessImportCheck"),
@@ -167,7 +167,7 @@ public class DebtModelBackupTest {
@Test
public void backup_with_rule_having_default_linear_and_overridden_offset() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
// Rule with default debt values : default value is linear (only coefficient is set) and overridden value is constant per issue (only
// offset is set)
// -> Ony offset should be set
@@ -195,7 +195,7 @@ public class DebtModelBackupTest {
@Test
public void backup_from_language() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck").setLanguage("java")
.setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.toString())
.setRemediationBaseEffort("15min"),
@@ -223,7 +223,7 @@ public class DebtModelBackupTest {
@Test
public void reset_model() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setRepositoryKey("squid").setRuleKey("NPE")
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString())
.setDefaultRemediationGapMultiplier("2h")
@@ -245,7 +245,7 @@ public class DebtModelBackupTest {
underTest.reset();
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(ruleDao).update(eq(session), ruleCaptor.capture());
verifyNoMoreInteractions(ruleDao);
@@ -267,7 +267,7 @@ public class DebtModelBackupTest {
@Test
public void reset_model_when_no_default_value() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setRepositoryKey("squid").setRuleKey("NPE")
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString())
.setDefaultRemediationGapMultiplier("2h")
@@ -288,7 +288,7 @@ public class DebtModelBackupTest {
underTest.reset();
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(ruleDao).update(eq(session), ruleCaptor.capture());
verifyNoMoreInteractions(ruleDao);
@@ -304,7 +304,7 @@ public class DebtModelBackupTest {
@Test
public void reset_model_on_custom_rules() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
// Template rule
new RuleDto().setId(5).setRepositoryKey("squid").setRuleKey("XPath")
.setRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
@@ -331,7 +331,7 @@ public class DebtModelBackupTest {
underTest.reset();
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(ruleDao, times(2)).update(eq(session), ruleCaptor.capture());
verifyNoMoreInteractions(ruleDao);
verify(session).commit();
@@ -353,11 +353,11 @@ public class DebtModelBackupTest {
@Test
public void reset_model_do_not_load_rule_definitions_if_no_rule() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(Collections.<RuleDto>emptyList());
+ when(ruleDao.selectEnabled(session)).thenReturn(Collections.<RuleDto>emptyList());
underTest.reset();
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(ruleDao, never()).update(eq(session), any(RuleDto.class));
verifyZeroInteractions(defLoader);
@@ -371,7 +371,7 @@ public class DebtModelBackupTest {
.setRuleKey(RuleKey.of("squid", "UselessImportCheck"))
.setFunction(DebtRemediationFunction.Type.LINEAR.name()).setCoefficient("2h")));
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck")
.setDefaultRemediationFunction("LINEAR").setDefaultRemediationGapMultiplier("2h")
));
@@ -380,14 +380,14 @@ public class DebtModelBackupTest {
verify(ruleOperations).updateRule(ruleCaptor.capture(), eq("LINEAR"), eq("2h"), isNull(String.class), eq(session));
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session).commit();
verify(ruleIndexer).index();
}
@Test
public void restore_from_xml_disable_rule_debt_when_not_in_xml_and_rule_have_default_debt_values() {
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck")
.setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationGapMultiplier("2h").setDefaultRemediationBaseEffort("15min")
));
@@ -396,7 +396,7 @@ public class DebtModelBackupTest {
verify(ruleOperations).updateRule(ruleCaptor.capture(), isNull(String.class), isNull(String.class), isNull(String.class), eq(session));
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session).commit();
verify(ruleIndexer).index();
}
@@ -406,7 +406,7 @@ public class DebtModelBackupTest {
when(rulesXMLImporter.importXML(anyString(), any(ValidationMessages.class))).thenReturn(newArrayList(new RuleDebt()
.setRuleKey(RuleKey.of("squid", "UselessImportCheck")).setFunction(DebtRemediationFunction.Type.LINEAR.name()).setCoefficient("2h")));
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck").setLanguage("java")
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString())
.setDefaultRemediationGapMultiplier("2h"),
@@ -420,7 +420,7 @@ public class DebtModelBackupTest {
verify(ruleOperations).updateRule(ruleCaptor.capture(), eq("LINEAR"), eq("2h"), isNull(String.class), eq(session));
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session).commit();
verify(ruleIndexer).index();
}
@@ -428,7 +428,7 @@ public class DebtModelBackupTest {
@Test
public void restore_from_xml_and_language_with_rule_not_in_xml() {
when(rulesXMLImporter.importXML(anyString(), any(ValidationMessages.class))).thenReturn(Collections.<RuleDebt>emptyList());
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
// Rule does not exits in XML -> debt will be disabled
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck").setLanguage("java")
.setDefaultRemediationFunction("LINEAR").setDefaultRemediationGapMultiplier("2h")
@@ -441,7 +441,7 @@ public class DebtModelBackupTest {
verify(ruleOperations).updateRule(ruleCaptor.capture(), isNull(String.class), isNull(String.class), isNull(String.class), eq(session));
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session).commit();
verify(ruleIndexer).index();
}
@@ -451,13 +451,13 @@ public class DebtModelBackupTest {
when(rulesXMLImporter.importXML(anyString(), any(ValidationMessages.class))).thenReturn(newArrayList(new RuleDebt()
.setRuleKey(RuleKey.of("squid", "UselessImportCheck")).setFunction(DebtRemediationFunction.Type.LINEAR.name()).setCoefficient("2h")));
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(Collections.<RuleDto>emptyList());
+ when(ruleDao.selectEnabled(session)).thenReturn(Collections.<RuleDto>emptyList());
assertThat(underTest.restoreFromXml("<xml/>").getWarnings()).hasSize(1);
verifyZeroInteractions(ruleOperations);
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session).commit();
verify(ruleIndexer).index();
}
@@ -467,7 +467,7 @@ public class DebtModelBackupTest {
when(rulesXMLImporter.importXML(anyString(), any(ValidationMessages.class))).thenReturn(newArrayList(new RuleDebt()
.setRuleKey(RuleKey.of("squid", "UselessImportCheck")).setFunction(DebtRemediationFunction.Type.LINEAR.name()).setCoefficient("2h")));
- when(ruleDao.selectEnabledAndNonManual(session)).thenReturn(newArrayList(
+ when(ruleDao.selectEnabled(session)).thenReturn(newArrayList(
new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck")
.setDefaultRemediationFunction("LINEAR").setDefaultRemediationGapMultiplier("2h")
));
@@ -476,7 +476,7 @@ public class DebtModelBackupTest {
assertThat(underTest.restoreFromXml("<xml/>").getErrors()).hasSize(1);
- verify(ruleDao).selectEnabledAndNonManual(session);
+ verify(ruleDao).selectEnabled(session);
verify(session, never()).commit();
verify(ruleIndexer, never()).index();
}
diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java
index 91b289f64a7..06941d1ccf4 100644
--- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java
@@ -69,16 +69,12 @@ public class RuleDao implements Dao {
return executeLargeInputs(keys, new KeyToDto(mapper(session)));
}
- public List<RuleDto> selectEnabledAndNonManual(DbSession session) {
- return mapper(session).selectEnabledAndNonManual();
+ public List<RuleDto> selectEnabled(DbSession session) {
+ return mapper(session).selectEnabled();
}
- public void selectEnabledAndNonManual(DbSession session, ResultHandler resultHandler) {
- mapper(session).selectEnabledAndNonManual(resultHandler);
- }
-
- public List<RuleDto> selectByNonManual(DbSession session) {
- return mapper(session).selectNonManual();
+ public void selectEnabled(DbSession session, ResultHandler resultHandler) {
+ mapper(session).selectEnabled(resultHandler);
}
public List<RuleDto> selectAll(DbSession session) {
diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java
index c98b551dbd0..7d457380839 100644
--- a/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java
@@ -31,11 +31,9 @@ public interface RuleMapper {
List<RuleDto> selectAll(ResultHandler resultHandler);
- List<RuleDto> selectEnabledAndNonManual();
+ List<RuleDto> selectEnabled();
- void selectEnabledAndNonManual(ResultHandler resultHandler);
-
- List<RuleDto> selectNonManual();
+ void selectEnabled(ResultHandler resultHandler);
RuleDto selectById(long id);
diff --git a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml
index d857846bb36..ea1a061b8c3 100644
--- a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml
@@ -40,11 +40,11 @@
from rules r
</select>
- <select id="selectEnabledAndNonManual" resultType="Rule">
+ <select id="selectEnabled" resultType="Rule">
select
<include refid="selectColumns"/>
from rules r
- where r.status != 'REMOVED' and r.plugin_name != 'manual'
+ where r.status != 'REMOVED'
</select>
<select id="selectById" parameterType="Long" resultType="Rule">
@@ -85,13 +85,6 @@
from rules r WHERE r.name=#{name}
</select>
- <select id="selectNonManual" resultType="Rule">
- select
- <include refid="selectColumns"/>
- from rules r
- where r.plugin_name != 'manual'
- </select>
-
<select id="selectByQuery" parameterType="map" resultType="Rule">
SELECT
<include refid="selectColumns"/>
diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
index cf40b8abf74..6cfc6ab5edc 100644
--- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java
@@ -121,9 +121,9 @@ public class RuleDaoTest {
}
@Test
- public void selectEnabledAndNonManual() {
- dbTester.prepareDbUnit(getClass(), "selectEnabledAndNonManual.xml");
- List<RuleDto> ruleDtos = underTest.selectEnabledAndNonManual(dbTester.getSession());
+ public void selectEnabled() {
+ dbTester.prepareDbUnit(getClass(), "selectEnabled.xml");
+ List<RuleDto> ruleDtos = underTest.selectEnabled(dbTester.getSession());
assertThat(ruleDtos.size()).isEqualTo(1);
RuleDto ruleDto = ruleDtos.get(0);
@@ -153,8 +153,8 @@ public class RuleDaoTest {
}
@Test
- public void selectEnabledAndNonManual_with_ResultHandler() {
- dbTester.prepareDbUnit(getClass(), "selectEnabledAndNonManual.xml");
+ public void selectEnabled_with_ResultHandler() {
+ dbTester.prepareDbUnit(getClass(), "selectEnabled.xml");
final List<RuleDto> rules = new ArrayList<>();
ResultHandler resultHandler = new ResultHandler() {
@@ -163,7 +163,7 @@ public class RuleDaoTest {
rules.add((RuleDto) resultContext.getResultObject());
}
};
- underTest.selectEnabledAndNonManual(dbTester.getSession(), resultHandler);
+ underTest.selectEnabled(dbTester.getSession(), resultHandler);
assertThat(rules.size()).isEqualTo(1);
RuleDto ruleDto = rules.get(0);
@@ -171,22 +171,6 @@ public class RuleDaoTest {
}
@Test
- public void select_non_manual() {
- dbTester.prepareDbUnit(getClass(), "selectNonManual.xml");
-
- List<RuleDto> ruleDtos = underTest.selectByNonManual(dbTester.getSession());
-
- assertThat(ruleDtos.size()).isEqualTo(1);
- RuleDto ruleDto = ruleDtos.get(0);
- assertThat(ruleDto.getId()).isEqualTo(1);
- assertThat(ruleDto.getName()).isEqualTo("Avoid Null");
- assertThat(ruleDto.getDescription()).isEqualTo("Should avoid NULL");
- assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY);
- assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle");
- }
-
-
- @Test
public void select_by_query() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
diff --git a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabled.xml
index 70caf821e54..e17e6ca13db 100644
--- a/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabledAndNonManual.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/rule/RuleDaoTest/selectEnabled.xml
@@ -18,13 +18,4 @@
created_at="1500000000000" updated_at="1600000000000"
/>
- <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="AvoidNull" plugin_name="manual" name="Manual Rule" description="Should not appear" status="READY"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" description_format="HTML"
- remediation_function="[null]" def_remediation_function="[null]"
- remediation_gap_mult="[null]" def_remediation_gap_mult="[null]"
- remediation_base_effort="[null]" def_remediation_base_effort="[null]"
- gap_description="[null]"
- created_at="1500000000000" updated_at="1600000000000"
- />
-
</dataset>