From: Julien Lancelot Date: Thu, 24 Mar 2016 16:39:57 +0000 (+0100) Subject: SONAR-7470 Remove 'manual' from SQL queries X-Git-Tag: 5.5-M12~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e2e23d7aefd4b8a0938412327f2d9f57c3389cda;p=sonarqube.git SONAR-7470 Remove 'manual' from SQL queries --- 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 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 ruleDtos = dbClient.ruleDao().selectEnabledAndNonManual(session); + List ruleDtos = dbClient.ruleDao().selectEnabled(session); if (!ruleDtos.isEmpty()) { // Load default rule definitions @@ -215,7 +215,7 @@ public class DebtModelBackup { } private List rules(@Nullable String languageKey, DbSession session) { - List rules = dbClient.ruleDao().selectEnabledAndNonManual(session); + List 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 loadRules(DbSession session) { Map 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.emptyList()); + when(ruleDao.selectEnabled(session)).thenReturn(Collections.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.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.emptyList()); + when(ruleDao.selectEnabled(session)).thenReturn(Collections.emptyList()); assertThat(underTest.restoreFromXml("").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("").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 selectEnabledAndNonManual(DbSession session) { - return mapper(session).selectEnabledAndNonManual(); + public List selectEnabled(DbSession session) { + return mapper(session).selectEnabled(); } - public void selectEnabledAndNonManual(DbSession session, ResultHandler resultHandler) { - mapper(session).selectEnabledAndNonManual(resultHandler); - } - - public List selectByNonManual(DbSession session) { - return mapper(session).selectNonManual(); + public void selectEnabled(DbSession session, ResultHandler resultHandler) { + mapper(session).selectEnabled(resultHandler); } public List 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 selectAll(ResultHandler resultHandler); - List selectEnabledAndNonManual(); + List selectEnabled(); - void selectEnabledAndNonManual(ResultHandler resultHandler); - - List 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 from rules r - where r.status != 'REMOVED' and r.plugin_name != 'manual' + where r.status != 'REMOVED' - -