diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-24 18:05:36 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-24 18:06:12 +0200 |
commit | 478383011bba15b19869380384aa569697706681 (patch) | |
tree | 1f0f66340ab9ea018b73049cbb836e5eb7a4731e /sonar-plugin-api | |
parent | 26680d528d424837683d5a1edf4e3c7f85c53d92 (diff) | |
download | sonarqube-478383011bba15b19869380384aa569697706681.tar.gz sonarqube-478383011bba15b19869380384aa569697706681.zip |
Revert "SONAR-3437 Remove Measure from Hibernate model"
This reverts commit cafd76d5317716817c0f15a402d820a6e80d19a9.
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java | 21 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java | 52 |
2 files changed, 57 insertions, 16 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java index 09b8f3b118a..b0275b64c39 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java @@ -23,17 +23,23 @@ import com.google.common.base.Charsets; import com.google.common.base.Throwables; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import org.sonar.api.database.BaseIdentifiable; +import javax.persistence.*; import java.io.UnsupportedEncodingException; -public class MeasureData { - - private Integer id; +@Entity +@Table(name = "measure_data") +public class MeasureData extends BaseIdentifiable { + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "measure_id") private MeasureModel measure; + @Column(name = "snapshot_id", updatable = true, nullable = true) private Integer snapshotId; + @Column(name = "data", updatable = true, nullable = true, length = 167772150) private byte[] data; public MeasureData(MeasureModel measure) { @@ -53,14 +59,6 @@ public class MeasureData { public MeasureData() { } - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - public MeasureModel getMeasure() { return measure; } @@ -106,3 +104,4 @@ public class MeasureData { .toString(); } } + 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 795af64bb27..f2a00deccfb 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 @@ -25,62 +25,96 @@ import org.sonar.api.database.DatabaseSession; import org.sonar.api.measures.Metric; import org.sonar.api.rules.RulePriority; +import javax.persistence.*; + import java.util.ArrayList; import java.util.Date; import java.util.List; +/** + * This class is the Hibernate model to store a measure in the DB + */ +@Entity +@Table(name = "project_measures") public class MeasureModel implements Cloneable { public static final int TEXT_VALUE_LENGTH = 96; + @Id + @Column(name = "id") + @GeneratedValue private Long id; + @Column(name = "value", updatable = true, nullable = true, precision = 30, scale = 20) private Double value = 0.0; + @Column(name = "text_value", updatable = true, nullable = true, length = TEXT_VALUE_LENGTH) private String textValue; + @Column(name = "tendency", updatable = true, nullable = true) private Integer tendency; + @Column(name = "metric_id", updatable = false, nullable = false) private Integer metricId; + @Column(name = "snapshot_id", updatable = true, nullable = true) private Integer snapshotId; + @Column(name = "project_id", updatable = true, nullable = true) private Integer projectId; + @Column(name = "description", updatable = true, nullable = true, length = 4000) private String description; + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "measure_date", updatable = true, nullable = true) private Date measureDate; + @Column(name = "rule_id", updatable = true, nullable = true) private Integer ruleId; /** * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 */ @Deprecated - private Integer rulesCategoryId;// NOSONAR this field is kept for backward-compatiblity of API + @Column(name = "rules_category_id", nullable = true) + private Integer rulesCategoryId;//NOSONAR this field is kept for backward-compatiblity of API + @Column(name = "rule_priority", updatable = false, nullable = true) + @Enumerated(EnumType.ORDINAL) private RulePriority rulePriority; + @Column(name = "alert_status", updatable = true, nullable = true, length = 5) private String alertStatus; + @Column(name = "alert_text", updatable = true, nullable = true, length = 4000) private String alertText; + @Column(name = "variation_value_1", updatable = true, nullable = true) private Double variationValue1; + @Column(name = "variation_value_2", updatable = true, nullable = true) private Double variationValue2; + @Column(name = "variation_value_3", updatable = true, nullable = true) private Double variationValue3; + @Column(name = "variation_value_4", updatable = true, nullable = true) private Double variationValue4; + @Column(name = "variation_value_5", updatable = true, nullable = true) private Double variationValue5; + @Column(name = "url", updatable = true, nullable = true, length = 2000) private String url; + @OneToMany(mappedBy = "measure", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) private List<MeasureData> measureData = new ArrayList<MeasureData>(); + @Column(name = "characteristic_id", nullable = true) private Integer characteristicId; + @Column(name = "person_id", updatable = true, nullable = true) private Integer personId; public Long getId() { @@ -361,7 +395,7 @@ public class MeasureModel implements Cloneable { /** * Use setData() instead */ - // @Deprecated + //@Deprecated public void setMeasureData(MeasureData data) { measureData.clear(); if (data != null) { @@ -446,11 +480,19 @@ public class MeasureModel implements Cloneable { * Saves the current object to database * * @return the current object - * @deprecated since 4.4 We don't use Hibernate anymore. See {@link MeasureMapper}. */ - @Deprecated public MeasureModel save(DatabaseSession session) { - throw new UnsupportedOperationException(); + MeasureData data = getMeasureData(); + setMeasureData(null); + session.save(this); + + if (data != null) { + data.setMeasure(session.getEntity(MeasureModel.class, getId())); + data.setSnapshotId(snapshotId); + session.save(data); + setMeasureData(data); + } + return this; } public Integer getCharacteristicId() { |