]> source.dussan.org Git - sonarqube.git/commitdiff
Revert "SONAR-3778 Bad performances when Hibernate requests measures on quality models"
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 17 Sep 2012 14:45:06 +0000 (16:45 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 17 Sep 2012 14:45:06 +0000 (16:45 +0200)
This reverts commit 5000405959b05fb3562a2f2cd55a1ba10e6464e2.

sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java

index 8d34661cb257f6cba3a605498d373991fb3fc522..ad2ec8007b8f177bae84758e68ded4b2836a766e 100644 (file)
@@ -99,7 +99,7 @@ public class DefaultTimeMachine implements TimeMachine {
     params.put("status", Snapshot.STATUS_PROCESSED);
     params.put("lib", Qualifiers.LIBRARY);
 
-    sb.append(" AND m.characteristicId IS NULL");
+    sb.append(" AND m.characteristic IS NULL");
     sb.append(" AND m.personId IS NULL");
     sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL");
     if (!metricIds.isEmpty()) {
@@ -161,6 +161,8 @@ public class DefaultTimeMachine implements TimeMachine {
     measure.setVariation4(model.getVariationValue4());
     measure.setVariation5(model.getVariationValue5());
     measure.setUrl(model.getUrl());
+    measure.setCharacteristic(model.getCharacteristic());
+    measure.setPersonId(model.getPersonId());
     return measure;
   }
 }
index 36b1e3837fb8e7a791a6cef315903e4fc1aedf54..ec036f13da4d9c74531a043abe44fdb751d1affa 100644 (file)
@@ -137,9 +137,7 @@ public final class MeasurePersister {
     model.setVariationValue4(measure.getVariation4());
     model.setVariationValue5(measure.getVariation5());
     model.setUrl(measure.getUrl());
-    if (measure.getCharacteristic()!=null) {
-      model.setCharacteristicId(measure.getCharacteristic().getId());
-    }
+    model.setCharacteristic(measure.getCharacteristic());
     model.setPersonId(measure.getPersonId());
     if (measure.getValue() != null) {
       model.setValue(measure.getValue().doubleValue());
index 3485cbecbe9076231e35b4995765cbcf17c16ea6..0e82d047a1d950d743ae8815e3945574da0392c2 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.database.model;
 
-import com.google.common.base.Preconditions;
 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.database.DatabaseSession;
@@ -28,6 +27,7 @@ import org.sonar.api.qualitymodel.Characteristic;
 import org.sonar.api.rules.RulePriority;
 
 import javax.persistence.*;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -112,8 +112,9 @@ public class MeasureModel implements Cloneable {
   @OneToMany(mappedBy = "measure", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
   private List<MeasureData> measureData = new ArrayList<MeasureData>();
 
-  @Column(name = "characteristic_id", updatable = true, nullable = true)
-  private Integer characteristicId;
+  @ManyToOne(fetch = FetchType.EAGER)
+  @JoinColumn(name = "characteristic_id")
+  private Characteristic characteristic;
 
   @Column(name = "person_id", updatable = true, nullable = true)
   private Integer personId;
@@ -496,38 +497,12 @@ public class MeasureModel implements Cloneable {
     return this;
   }
 
-  public Integer getCharacteristicId() {
-    return characteristicId;
-  }
-
-  public MeasureModel setCharacteristicId(Integer i) {
-    this.characteristicId = i;
-    return this;
-  }
-
-  /**
-   * @deprecated replaced by {@link org.sonar.api.database.model.MeasureModel#getCharacteristicId()} since 3.3. See https://jira.codehaus.org/browse/SONAR-3778
-   */
-  @Deprecated
   public Characteristic getCharacteristic() {
-    Characteristic c = null;
-    if (characteristicId != null) {
-      c = Characteristic.create().setId(characteristicId);
-    }
-    return c;
+    return characteristic;
   }
 
-  /**
-   * @deprecated replaced by {@link org.sonar.api.database.model.MeasureModel#setCharacteristicId(Integer)} since 3.3. See https://jira.codehaus.org/browse/SONAR-3778
-   */
-  @Deprecated
   public MeasureModel setCharacteristic(Characteristic c) {
-    if (c == null) {
-      this.characteristicId = null;
-    } else {
-      Preconditions.checkArgument(c.getId()!=null, "Characteristic id must not be null");
-      this.characteristicId = c.getId();
-    }
+    this.characteristic = c;
     return this;
   }
 
@@ -560,7 +535,7 @@ public class MeasureModel implements Cloneable {
     clone.setSnapshotId(getSnapshotId());
     clone.setMeasureDate(getMeasureDate());
     clone.setUrl(getUrl());
-    clone.setCharacteristicId(getCharacteristicId());
+    clone.setCharacteristic(getCharacteristic());
     clone.setPersonId(getPersonId());
     return clone;
   }
index 523ec19c2f305f70de1d5ea4bb9d9557d825dea0..c2a5da7fb9fcbd798926127cf61127c8b4deaf07 100644 (file)
@@ -94,7 +94,7 @@ public final class Characteristic implements Comparable<Characteristic> {
     return id;
   }
 
-  public Characteristic setId(Integer id) {
+  Characteristic setId(Integer id) {
     this.id = id;
     return this;
   }