]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 Replace usage of selectParamsByActiveRuleKey by selectParamsByActiveRuleId
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 26 Feb 2016 15:54:43 +0000 (16:54 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 12:26:54 +0000 (13:26 +0100)
12 files changed:
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleUpdaterMediumTest.java
sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java

index b227872fc61defe8046a005c5bfe19735494f8a5..6a3566435aaf36c5c92551bbbaadfd3398c32317 100644 (file)
@@ -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())
index 057b1dfb5e5667b5f1b899e6987f14c98e92b0e9..afe1620aa943fe4e2f9264196171e9c9a2ee51da 100644 (file)
@@ -85,8 +85,8 @@ public class QProfileComparison {
 
   private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) {
     RuleKey key = leftRule.getKey().ruleKey();
-    Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleKey(session, leftRule.getKey()));
-    Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleKey(session, rightRule.getKey()));
+    Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId()));
+    Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId()));
     if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) {
       result.same.put(key, leftRule);
     } else {
index 17f0217d8c8dc0ae31ac28a0daa2252cbba27ed4..02b8bcd808d965ebebc381af96c576d2f91c911a 100644 (file)
@@ -90,7 +90,7 @@ public class RuleActivatorContextFactory {
     Optional<ActiveRuleDto> activeRule = db.activeRuleDao().selectByKey(session, key);
     Collection<ActiveRuleParamDto> 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());
index 38a58b16d6ad96163cce2735bfbca378ee0c2e67..acaf69885231291011c4d8510fabd49ad1472bd2 100644 (file)
@@ -253,7 +253,7 @@ public class RuleUpdater {
       Multimap<ActiveRuleDto, ActiveRuleParamDto> 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);
         }
       }
index c3a0ac2ee1cc4776ee974c1af5c2403f06a8aab2..b7cd25938044bb365a1d27d6139841985fe0f046 100644 (file)
@@ -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<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key());
+    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key());
+    List<ActiveRuleParamDto> 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<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key());
+    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key());
+    List<ActiveRuleParamDto> 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<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key());
+
+    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key());
+    List<ActiveRuleParamDto> 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<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleDoc.key());
+
+    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.key());
+    List<ActiveRuleParamDto> 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");
index 9c130568ebc262969ba4516d62ca02430d3d2c0b..3ea8a2477d05a11d705d21e8647761c0852f4f97 100644 (file)
@@ -201,7 +201,8 @@ public class QProfileCopierMediumTest {
     assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance));
 
     // verify parameters
-    List<ActiveRuleParamDto> params = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.key());
+    ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRule.key());
+    List<ActiveRuleParamDto> params = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
     assertThat(params).hasSize(expectedParams.size());
     Map<String, ActiveRuleParamDto> paramsByKey = ActiveRuleParamDto.groupByKey(params);
     for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
index 41fbdb61e786e5e09b1c1782f85cb047937a6c63..10a537d8ee002f7e5a4304925d8a3eed05d97034 100644 (file)
@@ -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<ActiveRuleParamDto> activeRuleParamDtos = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleKey);
+    List<ActiveRuleParamDto> 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<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleKey(dbSession, activeRuleKey);
+    ActiveRuleDto activeRuleDto = tester.get(ActiveRuleDao.class).selectOrFailByKey(dbSession, activeRuleKey);
+    List<ActiveRuleParamDto> 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");
index 9977ea4288b6ee5525d0c4a105a54df9a650c852..89ef4f7aaae1a3fdd66eba0cfee5401341aa8198 100644 (file)
@@ -105,7 +105,7 @@ public class RegisterQualityProfilesMediumTest {
 
     // TODO
     // Check ActiveRuleParameters in DB
-    Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleKey(dbSession, activeRule.getKey()));
+    Map<String, ActiveRuleParamDto> 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<String, ActiveRuleParamDto> 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");
index 3f4c4fcd16fcf138ad669073c3ed5b8435912dc9..be82422bbaa7320a43c8d46516b2d928408c3549 100644 (file)
@@ -1098,7 +1098,7 @@ public class RuleActivatorMediumTest {
         assertThat(activeRuleDto.getCreatedAt()).isNotNull();
         assertThat(activeRuleDto.getUpdatedAt()).isNotNull();
 
-        List<ActiveRuleParamDto> paramDtos = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
+        List<ActiveRuleParamDto> paramDtos = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
         assertThat(paramDtos).hasSize(expectedParams.size());
         for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
           ActiveRuleParamDto paramDto = db.activeRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
index bc2cdff1e47f6da87773d01c24fa04d4e6f080e6..ade56882e969cb4e26bd46df2028e264ca0683de 100644 (file)
@@ -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<ActiveRuleParamDto> 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<ActiveRuleParamDto> params = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
     assertThat(params).hasSize(2);
 
     Map<String, ActiveRuleParamDto> parmsByKey = FluentIterable.from(params).uniqueIndex(ActiveRuleParamToKey.INSTANCE);
index 9cbc02b16a1073396cd91149faf936108b2c3dab..b8a7327131efb63896a2055c3a9dc77fb33e8407 100644 (file)
@@ -469,7 +469,7 @@ public class RuleUpdaterMediumTest {
     assertThat(activeRuleDto.getSeverityString()).isEqualTo(Severity.BLOCKER);
 
     // Verify active rule parameters has been updated
-    List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleKey(dbSession, activeRuleDto.getKey());
+    List<ActiveRuleParamDto> activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
 
     // FIXME why 4 parameters are returned ??? (This issue already exists in 5.4)
     //assertThat(activeRuleParams).hasSize(2);
index b236d22776cbc1d22c6e344be821858abd1674a2..60b90c7e2ccdce04b19839533a8d3eb25af7aab9 100644 (file)
@@ -114,7 +114,10 @@ public class ActiveRuleDao implements Dao {
     return DatabaseUtils.executeLargeInputs(activeRuleIds, new ParamIdToDto(mapper(dbSession)));
   }
 
-  public List<ActiveRuleParamDto> 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<ActiveRuleParamDto> 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());