]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7400 Remove parentKey field from active rule index
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 May 2016 15:53:07 +0000 (17:53 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 16 May 2016 10:08:18 +0000 (12:08 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleDocTesting.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java

index 1afbaba5fa4feb66a6e092046c221143123ed68c..f863366203c2e4771c4dec365c0e1d659f56d496 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.qualityprofile;
 
-import javax.annotation.CheckForNull;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 
 public interface ActiveRule {
@@ -38,7 +37,4 @@ public interface ActiveRule {
 
   Inheritance inheritance();
 
-  @CheckForNull
-  ActiveRuleKey parentKey();
-
 }
index 472c048246b578ee9b43ef80fe7416e1092748b9..12cee53358e082fe433dfe9ce7b01a2c3480f374 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.qualityprofile.index;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import java.util.Map;
-import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.server.qualityprofile.ActiveRule;
@@ -32,7 +31,6 @@ import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
-import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PARENT_KEY;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY;
@@ -94,21 +92,6 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
     return this;
   }
 
-  @Override
-  @CheckForNull
-  public ActiveRuleKey parentKey() {
-    String data = getNullableField(FIELD_ACTIVE_RULE_PARENT_KEY);
-    if (data != null && !data.isEmpty()) {
-      return ActiveRuleKey.parse(data);
-    }
-    return null;
-  }
-
-  public ActiveRuleDoc setParentKey(@Nullable String s) {
-    setField(FIELD_ACTIVE_RULE_PARENT_KEY, s);
-    return this;
-  }
-
   @Override
   public long createdAt() {
     return (Long) getField(FIELD_ACTIVE_RULE_CREATED_AT);
index 5b5e944a84c14966a60135c806e05689e7b48d7a..362cebb834a5991409d8cd617e5c5be1f82b57a8 100644 (file)
@@ -43,15 +43,13 @@ public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc
     "r.plugin_rule_key",
     "r.plugin_name",
     "qp.kee",
-    "profile_parent.kee",
     "a.created_at",
     "a.updated_at"
   };
 
   private static final String SQL_ALL = "SELECT " + StringUtils.join(FIELDS, ",") + " FROM active_rules a " +
     "INNER JOIN rules_profiles qp ON qp.id=a.profile_id " +
-    "INNER JOIN rules r ON r.id = a.rule_id " +
-    "LEFT JOIN rules_profiles profile_parent ON profile_parent.kee=qp.parent_kee ";
+    "INNER JOIN rules r ON r.id = a.rule_id";
 
   private static final String SQL_AFTER_DATE = SQL_ALL + " WHERE a.updated_at>?";
 
@@ -83,22 +81,10 @@ public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc
     doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(1)));
 
     String inheritance = rs.getString(2);
-    if (inheritance != null) {
-      doc.setInheritance(inheritance);
-    } else {
-      doc.setInheritance(ActiveRule.Inheritance.NONE.name());
-    }
-
-    String parentProfileKey = rs.getString(6);
-    if (parentProfileKey != null) {
-      doc.setParentKey(ActiveRuleKey.of(parentProfileKey, ruleKey).toString());
-    } else {
-      doc.setParentKey(null);
-    }
-
-    doc.setCreatedAt(rs.getLong(7));
-    doc.setUpdatedAt(rs.getLong(8));
+    doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
 
+    doc.setCreatedAt(rs.getLong(6));
+    doc.setUpdatedAt(rs.getLong(7));
     return doc;
   }
 
index 87ea1ae7a28c689ba263a48a2da5ef6cc092eacc..e42975c7a9d8a1b1b3468643459535baf7289299 100644 (file)
@@ -65,7 +65,6 @@ public class RuleIndexDefinition implements IndexDefinition {
   public static final String FIELD_ACTIVE_RULE_INHERITANCE = "inheritance";
   public static final String FIELD_ACTIVE_RULE_PROFILE_KEY = "profile";
   public static final String FIELD_ACTIVE_RULE_SEVERITY = "severity";
-  public static final String FIELD_ACTIVE_RULE_PARENT_KEY = "parentKey";
   public static final String FIELD_ACTIVE_RULE_RULE_KEY = "ruleKey";
   public static final String FIELD_ACTIVE_RULE_CREATED_AT = "createdAt";
   public static final String FIELD_ACTIVE_RULE_UPDATED_AT = "updatedAt";
@@ -121,7 +120,6 @@ public class RuleIndexDefinition implements IndexDefinition {
     activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).docValues().build();
     activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE).docValues().build();
     activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY).docValues().build();
-    activeRuleMapping.stringFieldBuilder(RuleIndexDefinition.FIELD_ACTIVE_RULE_PARENT_KEY).disableSearch().docValues().build();
 
     activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT);
     activeRuleMapping.createLongField(RuleIndexDefinition.FIELD_ACTIVE_RULE_UPDATED_AT);
index 9bc6811b19e38419a4e9f111c53f6078754de293..75de01617f4a8395d8a74dfb9bbd709f071f62f1 100644 (file)
@@ -32,7 +32,6 @@ public class ActiveRuleDocTesting {
   public static ActiveRuleDoc newDoc(ActiveRuleKey key) {
     return new ActiveRuleDoc(key)
       .setSeverity(Severity.CRITICAL)
-      .setParentKey(null)
       .setInheritance(null).setCreatedAt(150000000L)
       .setUpdatedAt(160000000L);
   }
index 8274fb8505d5d239f666cd2302ddf7d854bca594..2f47190f8a9e83ae287dd84d9bc7fed7a8c612a6 100644 (file)
@@ -105,10 +105,8 @@ public class ActiveRuleIndexTest {
       ActiveRuleDocTesting.newDoc(activeRuleKey1).setSeverity(BLOCKER),
       ActiveRuleDocTesting.newDoc(activeRuleKey2).setSeverity(MINOR),
       // Profile 2 is a child a profile 1
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR)
-        .setParentKey(activeRuleKey1.toString()).setInheritance(INHERITED.name()),
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER)
-        .setParentKey(activeRuleKey2.toString()).setInheritance(OVERRIDES.name()));
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR).setInheritance(INHERITED.name()),
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER).setInheritance(OVERRIDES.name()));
 
     // 0. Test base case
     assertThat(tester.countDocuments(INDEX, TYPE_ACTIVE_RULE)).isEqualTo(4);
@@ -137,7 +135,7 @@ public class ActiveRuleIndexTest {
       docs.add(ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_1)).setSeverity(BLOCKER));
       docs.add(ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_2)).setSeverity(MAJOR));
     }
-    indexActiveRules(docs.toArray(new ActiveRuleDoc[]{}));
+    indexActiveRules(docs.toArray(new ActiveRuleDoc[] {}));
 
     Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(profileKeys);
     assertThat(stats).hasSize(30);
@@ -158,8 +156,7 @@ public class ActiveRuleIndexTest {
     indexRules(
       RuleDocTesting.newDoc(RULE_KEY_1),
       RuleDocTesting.newDoc(RULE_KEY_2),
-      RuleDocTesting.newDoc(RuleKey.of("xoo", "removed")).setStatus(RuleStatus.REMOVED.name())
-    );
+      RuleDocTesting.newDoc(RuleKey.of("xoo", "removed")).setStatus(RuleStatus.REMOVED.name()));
 
     indexActiveRules(
       ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1)),
@@ -168,8 +165,7 @@ public class ActiveRuleIndexTest {
       // Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not
       // removed
       // because if the plugin is re-install, quality profiles using these rule are not changed.
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RuleKey.of("xoo", "removed")))
-    );
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RuleKey.of("xoo", "removed"))));
 
     // 1. find by rule key
 
index 2f0fb5e6f5b3d861f899cd8efff6213b4c1a6465..d63c14fe102440fd931525f2ab0a6144ece683c1 100644 (file)
@@ -443,12 +443,9 @@ public class RuleIndexTest {
       ActiveRuleDocTesting.newDoc(activeRuleKey2),
       ActiveRuleDocTesting.newDoc(activeRuleKey3),
       // Profile 2 is a child a profile 1
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1))
-        .setParentKey(activeRuleKey1.toString()).setInheritance(INHERITED.name()),
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2))
-        .setParentKey(activeRuleKey2.toString()).setInheritance(OVERRIDES.name()),
-      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3))
-        .setParentKey(activeRuleKey3.toString()).setInheritance(INHERITED.name()));
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setInheritance(INHERITED.name()),
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setInheritance(OVERRIDES.name()),
+      ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3)).setInheritance(INHERITED.name()));
 
     // 0. get all rules
     assertThat(index.search(new RuleQuery(), new SearchOptions()).getIds())