aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-29 17:00:54 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-29 17:00:54 +0000
commit6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d (patch)
tree0770d083d359e3e644ff64bf06dc8b9abc3ad04b /sonar-plugin-api
parent0c4893c83a6873b224a50db86311082fd5af555f (diff)
downloadsonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.tar.gz
sonarqube-6ce6cc598fdcd6e3d6eb662b47668b0c6b898f3d.zip
SONAR-249 improve core components to load rules and metrics
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java76
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java1
3 files changed, 12 insertions, 69 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
index 3a9c1a4bca0..e829e6e786e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
@@ -20,14 +20,9 @@
package org.sonar.api.database.model;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.hibernate.annotations.Cache;
-import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.RuleMeasure;
import org.sonar.api.qualitymodel.Characteristic;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import javax.persistence.*;
@@ -74,10 +69,8 @@ public class MeasureModel implements Cloneable {
@Column(name = "measure_date", updatable = true, nullable = true)
private Date measureDate;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "rule_id")
- @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
- private Rule rule;
+ @Column(name = "rule_id", updatable = true, nullable = true)
+ private Integer ruleId;
@Column(name = "rules_category_id")
private Integer rulesCategoryId;
@@ -223,7 +216,7 @@ public class MeasureModel implements Cloneable {
* @return whether the measure is about rule
*/
public boolean isRuleMeasure() {
- return rule != null || rulePriority != null || rulesCategoryId != null;
+ return ruleId != null || rulePriority != null || rulesCategoryId != null;
}
/**
@@ -261,11 +254,8 @@ public class MeasureModel implements Cloneable {
return this;
}
- /**
- * @return the rule
- */
- public Rule getRule() {
- return rule;
+ public Integer getRuleId() {
+ return ruleId;
}
/**
@@ -273,8 +263,8 @@ public class MeasureModel implements Cloneable {
*
* @return the current object
*/
- public MeasureModel setRule(Rule rule) {
- this.rule = rule;
+ public MeasureModel setRuleId(Integer ruleId) {
+ this.ruleId = ruleId;
return this;
}
@@ -454,16 +444,6 @@ public class MeasureModel implements Cloneable {
}
/**
- * @return the rule id of the measure
- */
- public Integer getRuleId() {
- if (getRule() != null) {
- return getRule().getId();
- }
- return null;
- }
-
- /**
* @return diffValue1
*/
public Double getDiffValue1() {
@@ -548,51 +528,11 @@ public class MeasureModel implements Cloneable {
clone.setValue(getValue());
clone.setRulesCategoryId(getRulesCategoryId());
clone.setRulePriority(getRulePriority());
- clone.setRule(getRule());
+ clone.setRuleId(getRuleId());
clone.setSnapshotId(getSnapshotId());
clone.setMeasureDate(getMeasureDate());
clone.setUrl(getUrl());
clone.setCharacteristic(getCharacteristic());
return clone;
}
-
-/**
- * True if other fields than 'value' are set.
- */
- public boolean hasOptionalData() {
- return getAlertStatus()!=null ||
- getAlertText()!=null ||
- getDescription()!=null ||
- getDiffValue1()!=null ||
- getDiffValue2()!=null ||
- getDiffValue3()!=null ||
- getMeasureData()!=null ||
- getTendency()!=null ||
- getUrl()!=null;
- }
-
- /**
- * @return a measure from the current object
- */
- public Measure toMeasure(Metric metric) {
- Measure measure;
- if (isRuleMeasure()) {
- measure = new RuleMeasure(metric, getRule(), getRulePriority(), getRulesCategoryId());
- } else {
- measure = new Measure(metric);
- }
- measure.setId(getId());
- measure.setDescription(getDescription());
- measure.setValue(getValue());
- measure.setData(getData(metric));
- measure.setAlertStatus(getAlertStatus());
- measure.setAlertText(getAlertText());
- measure.setTendency(getTendency());
- measure.setDiffValue1(getDiffValue1());
- measure.setDiffValue2(getDiffValue2());
- measure.setDiffValue3(getDiffValue3());
- measure.setUrl(getUrl());
- measure.setCharacteristic(getCharacteristic());
- return measure;
- }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
index acd85a01e51..d05609c607a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
@@ -31,7 +31,9 @@ import java.util.List;
*/
public interface MetricFinder extends BatchComponent {
- Metric find(String key);
+ Metric findById(int id);
+
+ Metric findByKey(String key);
Collection<Metric> findAll(List<String> metricKeys);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
index 83581280908..b96249622e1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
@@ -29,6 +29,7 @@ import java.util.Collection;
*/
public interface RuleFinder extends BatchComponent, ServerComponent {
+ Rule findById(int ruleId);
Rule findByKey(String repositoryKey, String key);
Rule find(RuleQuery query);
Collection<Rule> findAll(RuleQuery query);