]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3778 Bad performances when Hibernate requests measures on quality models
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Sep 2012 13:08:48 +0000 (15:08 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Sep 2012 13:20:38 +0000 (15:20 +0200)
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 ad2ec8007b8f177bae84758e68ded4b2836a766e..8d34661cb257f6cba3a605498d373991fb3fc522 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.characteristic IS NULL");
+    sb.append(" AND m.characteristicId 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,8 +161,6 @@ 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 ec036f13da4d9c74531a043abe44fdb751d1affa..36b1e3837fb8e7a791a6cef315903e4fc1aedf54 100644 (file)
@@ -137,7 +137,9 @@ public final class MeasurePersister {
     model.setVariationValue4(measure.getVariation4());
     model.setVariationValue5(measure.getVariation5());
     model.setUrl(measure.getUrl());
-    model.setCharacteristic(measure.getCharacteristic());
+    if (measure.getCharacteristic()!=null) {
+      model.setCharacteristicId(measure.getCharacteristic().getId());
+    }
     model.setPersonId(measure.getPersonId());
     if (measure.getValue() != null) {
       model.setValue(measure.getValue().doubleValue());
index 0e82d047a1d950d743ae8815e3945574da0392c2..3485cbecbe9076231e35b4995765cbcf17c16ea6 100644 (file)
@@ -19,6 +19,7 @@
  */
 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;
@@ -27,7 +28,6 @@ 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,9 +112,8 @@ 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>();
 
-  @ManyToOne(fetch = FetchType.EAGER)
-  @JoinColumn(name = "characteristic_id")
-  private Characteristic characteristic;
+  @Column(name = "characteristic_id", updatable = true, nullable = true)
+  private Integer characteristicId;
 
   @Column(name = "person_id", updatable = true, nullable = true)
   private Integer personId;
@@ -497,12 +496,38 @@ 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() {
-    return characteristic;
+    Characteristic c = null;
+    if (characteristicId != null) {
+      c = Characteristic.create().setId(characteristicId);
+    }
+    return c;
   }
 
+  /**
+   * @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) {
-    this.characteristic = c;
+    if (c == null) {
+      this.characteristicId = null;
+    } else {
+      Preconditions.checkArgument(c.getId()!=null, "Characteristic id must not be null");
+      this.characteristicId = c.getId();
+    }
     return this;
   }
 
@@ -535,7 +560,7 @@ public class MeasureModel implements Cloneable {
     clone.setSnapshotId(getSnapshotId());
     clone.setMeasureDate(getMeasureDate());
     clone.setUrl(getUrl());
-    clone.setCharacteristic(getCharacteristic());
+    clone.setCharacteristicId(getCharacteristicId());
     clone.setPersonId(getPersonId());
     return clone;
   }
index c2a5da7fb9fcbd798926127cf61127c8b4deaf07..523ec19c2f305f70de1d5ea4bb9d9557d825dea0 100644 (file)
@@ -94,7 +94,7 @@ public final class Characteristic implements Comparable<Characteristic> {
     return id;
   }
 
-  Characteristic setId(Integer id) {
+  public Characteristic setId(Integer id) {
     this.id = id;
     return this;
   }