From: Julien Lancelot Date: Fri, 26 Feb 2016 15:54:43 +0000 (+0100) Subject: SONAR-7330 Replace usage of selectParamsByActiveRuleKey by selectParamsByActiveRuleId X-Git-Tag: 5.5-M6~51 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5398bad124d6160f84822236cb651fec548d8738;p=sonarqube.git SONAR-7330 Replace usage of selectParamsByActiveRuleKey by selectParamsByActiveRuleId --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java index b227872fc61..6a3566435aa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java @@ -88,7 +88,7 @@ public class QProfileBackuper { xml.prop("key", activeRule.getKey().ruleKey().rule()); xml.prop("priority", activeRule.getSeverityString()); xml.begin("parameters"); - for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.getKey())) { + for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRule.getId())) { xml .begin("parameter") .prop("key", param.getKey()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java index 057b1dfb5e5..afe1620aa94 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java @@ -85,8 +85,8 @@ public class QProfileComparison { private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) { RuleKey key = leftRule.getKey().ruleKey(); - Map leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleKey(session, leftRule.getKey())); - Map rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleKey(session, rightRule.getKey())); + Map leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId())); + Map rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId())); if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) { result.same.put(key, leftRule); } else { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java index 17f0217d8c8..02b8bcd808d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java @@ -90,7 +90,7 @@ public class RuleActivatorContextFactory { Optional activeRule = db.activeRuleDao().selectByKey(session, key); Collection activeRuleParams = null; if (activeRule.isPresent()) { - activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleKey(session, key); + activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(session, activeRule.get().getId()); } if (parent) { context.setParentActiveRule(activeRule.orNull()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java index 38a58b16d6a..acaf6988523 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java @@ -253,7 +253,7 @@ public class RuleUpdater { Multimap activeRuleParams = ArrayListMultimap.create(); for (ActiveRuleDto activeRuleDto : dbClient.activeRuleDao().selectByRule(dbSession, customRule)) { activeRules.put(customRule, activeRuleDto); - for (ActiveRuleParamDto activeRuleParamDto : dbClient.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey())) { + for (ActiveRuleParamDto activeRuleParamDto : dbClient.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId())) { activeRuleParams.put(activeRuleDto, activeRuleParamDto); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java index c3a0ac2ee1c..b7cd2593804 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java @@ -41,6 +41,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; import org.sonar.db.qualityprofile.ActiveRuleDao; +import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QualityProfileDto; import org.sonar.db.rule.RuleDto; @@ -154,7 +155,8 @@ public class QProfileBackuperMediumTest { assertThat(activeRuleDoc.severity()).isEqualTo("BLOCKER"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE); - List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("7"); @@ -187,7 +189,8 @@ public class QProfileBackuperMediumTest { assertThat(activeRuleDoc.severity()).isEqualTo("BLOCKER"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE); - List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("7"); @@ -220,7 +223,9 @@ public class QProfileBackuperMediumTest { ActiveRuleDoc activeRuleDoc = activeRules.get(0); assertThat(activeRuleDoc.severity()).isEqualTo("INFO"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE); - List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("10"); @@ -231,7 +236,9 @@ public class QProfileBackuperMediumTest { activeRuleDoc = activeRules.get(0); assertThat(activeRuleDoc.severity()).isEqualTo("BLOCKER"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.OVERRIDES); - params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + + activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("7"); @@ -265,7 +272,9 @@ public class QProfileBackuperMediumTest { ActiveRuleDoc activeRuleDoc = activeRules.get(0); assertThat(activeRuleDoc.severity()).isEqualTo("BLOCKER"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE); - List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("7"); @@ -276,7 +285,9 @@ public class QProfileBackuperMediumTest { activeRuleDoc = activeRules.get(0); assertThat(activeRuleDoc.severity()).isEqualTo("BLOCKER"); assertThat(activeRuleDoc.inheritance()).isEqualTo(ActiveRule.Inheritance.INHERITED); - params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key()); + + activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key()); + params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("max"); assertThat(params.get(0).getValue()).isEqualTo("7"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java index 9c130568ebc..3ea8a2477d0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java @@ -201,7 +201,8 @@ public class QProfileCopierMediumTest { assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance)); // verify parameters - List params = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.key()); + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRule.key()); + List params = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(expectedParams.size()); Map paramsByKey = ActiveRuleParamDto.groupByKey(params); for (Map.Entry entry : expectedParams.entrySet()) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java index 41fbdb61e78..10a537d8ee0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java @@ -139,7 +139,7 @@ public class QProfileResetMediumTest { // Verify severity and param has changed ActiveRuleDto activeRuleDto = tester.get(ActiveRuleDao.class).selectOrFailByKey(dbSession, activeRuleKey); assertThat(activeRuleDto.getSeverityString()).isEqualTo(BLOCKER); - List activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleKey); + List activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(activeRuleParamDtos.get(0).getKey()).isEqualTo("acceptWhitespace"); assertThat(activeRuleParamDtos.get(0).getValue()).isEqualTo("false"); @@ -152,7 +152,7 @@ public class QProfileResetMediumTest { ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getNullableByKey(activeRuleKey); assertThat(activeRule.severity()).isEqualTo(CRITICAL); - activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleKey); + activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(activeRuleParamDtos.get(0).getKey()).isEqualTo("acceptWhitespace"); assertThat(activeRuleParamDtos.get(0).getValue()).isEqualTo("true"); } @@ -195,7 +195,8 @@ public class QProfileResetMediumTest { reset.resetLanguage(ServerTester.Xoo.KEY); // Parameter value come back to origin after reset - List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleKey); + ActiveRuleDto activeRuleDto = tester.get(ActiveRuleDao.class).selectOrFailByKey(dbSession, activeRuleKey); + List params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(1); assertThat(params.get(0).getKey()).isEqualTo("acceptWhitespace"); assertThat(params.get(0).getValue()).isEqualTo("true"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java index 9977ea4288b..89ef4f7aaae 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java @@ -105,7 +105,7 @@ public class RegisterQualityProfilesMediumTest { // TODO // Check ActiveRuleParameters in DB - Map params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleKey(dbSession, activeRule.getKey())); + Map params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId())); assertThat(params).hasSize(2); // set by profile assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true"); @@ -140,7 +140,7 @@ public class RegisterQualityProfilesMediumTest { // Check ActiveRuleParameters in DB Map params = - ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleKey(dbSession, activeRule.getKey())); + ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId())); assertThat(params).hasSize(2); // set by profile assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java index 3f4c4fcd16f..be82422bbaa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java @@ -1098,7 +1098,7 @@ public class RuleActivatorMediumTest { assertThat(activeRuleDto.getCreatedAt()).isNotNull(); assertThat(activeRuleDto.getUpdatedAt()).isNotNull(); - List paramDtos = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey()); + List paramDtos = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(paramDtos).hasSize(expectedParams.size()); for (Map.Entry entry : expectedParams.entrySet()) { ActiveRuleParamDto paramDto = db.activeRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java index bc2cdff1e47..ade56882e96 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java @@ -39,6 +39,7 @@ import org.sonar.api.server.rule.RulesDefinition; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleKey; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.rule.RuleDao; @@ -197,7 +198,8 @@ public class RegisterRulesMediumTest { } }); - List params = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, ActiveRuleKey.of(QProfileTesting.XOO_P1_KEY, RuleTesting.XOO_X1)); + ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, ActiveRuleKey.of(QProfileTesting.XOO_P1_KEY, RuleTesting.XOO_X1)); + List params = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); assertThat(params).hasSize(2); Map parmsByKey = FluentIterable.from(params).uniqueIndex(ActiveRuleParamToKey.INSTANCE); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java index 9cbc02b16a1..b8a7327131e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java @@ -469,7 +469,7 @@ public class RuleUpdaterMediumTest { assertThat(activeRuleDto.getSeverityString()).isEqualTo(Severity.BLOCKER); // Verify active rule parameters has been updated - List activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey()); + List activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId()); // FIXME why 4 parameters are returned ??? (This issue already exists in 5.4) //assertThat(activeRuleParams).hasSize(2); diff --git a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index b236d22776c..60b90c7e2cc 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -114,7 +114,10 @@ public class ActiveRuleDao implements Dao { return DatabaseUtils.executeLargeInputs(activeRuleIds, new ParamIdToDto(mapper(dbSession))); } - public List selectParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) { + /** + * Warning ! This method is executing 2 queries : one to get the active rule from the key, and another one to get parameters + */ + private List selectParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) { Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); ActiveRuleDto activeRule = selectOrFailByKey(session, key); return mapper(session).selectParamsByActiveRuleId(activeRule.getId());