001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.api.database.model;
021
022 import org.apache.commons.lang.builder.EqualsBuilder;
023 import org.apache.commons.lang.builder.HashCodeBuilder;
024 import org.apache.commons.lang.builder.ToStringBuilder;
025 import org.sonar.api.database.BaseIdentifiable;
026
027 import java.util.Date;
028 import javax.persistence.*;
029
030 /**
031 * Class to map an aysync measure with hibernate model
032 */
033 @Entity
034 @Table(name = "async_measure_snapshots")
035 public class AsyncMeasureSnapshot extends BaseIdentifiable {
036
037 @Column(name = "project_measure_id", updatable = true, nullable = true)
038 private Long measureId;
039
040 @Temporal(TemporalType.TIMESTAMP)
041 @Column(name = "measure_date", updatable = true, nullable = true)
042 private Date measureDate;
043
044 @Column(name = "snapshot_id", updatable = true, nullable = true)
045 private Integer snapshotId;
046
047 @Temporal(TemporalType.TIMESTAMP)
048 @Column(name = "snapshot_date", updatable = true, nullable = true)
049 private Date snapshotDate;
050
051 @Column(name = "metric_id", updatable = true, nullable = true)
052 private Integer metricId;
053
054 @Column(name = "project_id", updatable = true, nullable = true)
055 private Integer projectId;
056
057 /**
058 * This is the constructor to use
059 *
060 * @param measureId
061 * @param snapshotId the snapshot id to which the measure is attached
062 * @param measureDate the date of the measure
063 * @param snapshotDate the snapshot date
064 * @param metricId the metric the measure is attached to
065 * @param projectId the id of the project
066 */
067 public AsyncMeasureSnapshot(Long measureId, Integer snapshotId, Date measureDate, Date snapshotDate, Integer metricId, Integer projectId) {
068 this.measureId = measureId;
069 this.measureDate = measureDate;
070 this.snapshotId = snapshotId;
071 this.snapshotDate = snapshotDate;
072 this.projectId = projectId;
073 this.metricId = metricId;
074 }
075
076 /**
077 * Default constructor
078 */
079 public AsyncMeasureSnapshot() {
080 }
081
082 public Long getMeasureId() {
083 return measureId;
084 }
085
086 public void setMeasureId(Long measureId) {
087 this.measureId = measureId;
088 }
089
090 public Integer getSnapshotId() {
091 return snapshotId;
092 }
093
094 public void setSnapshotId(Integer snapshotId) {
095 this.snapshotId = snapshotId;
096 }
097
098 public Date getMeasureDate() {
099 return measureDate;
100 }
101
102 public void setMeasureDate(Date measureDate) {
103 this.measureDate = measureDate;
104 }
105
106 public Date getSnapshotDate() {
107 return snapshotDate;
108 }
109
110 public void setSnapshotDate(Date snapshotDate) {
111 this.snapshotDate = snapshotDate;
112 }
113
114 public Integer getMetricId() {
115 return metricId;
116 }
117
118 public void setMetricId(Integer metricId) {
119 this.metricId = metricId;
120 }
121
122 public Integer getProjectId() {
123 return projectId;
124 }
125
126 public void setProjectId(Integer projectId) {
127 this.projectId = projectId;
128 }
129
130 public void setMeasure(MeasureModel measure) {
131 setMeasureId(measure.getId());
132 setMeasureDate(measure.getMeasureDate());
133 }
134
135 @Override
136 public boolean equals(Object obj) {
137 if (!(obj instanceof AsyncMeasureSnapshot)) {
138 return false;
139 }
140 if (this == obj) {
141 return true;
142 }
143 AsyncMeasureSnapshot other = (AsyncMeasureSnapshot) obj;
144 return new EqualsBuilder()
145 .append(measureId, other.getMeasureId())
146 .append(measureDate, other.getMeasureDate())
147 .append(snapshotId, other.getSnapshotId())
148 .append(snapshotDate, other.getSnapshotDate())
149 .isEquals();
150 }
151
152 @Override
153 public int hashCode() {
154 return new HashCodeBuilder(17, 37)
155 .append(measureId)
156 .append(measureDate)
157 .append(snapshotDate)
158 .append(snapshotId)
159 .toHashCode();
160 }
161
162 @Override
163 public String toString() {
164 return new ToStringBuilder(this)
165 .append("id", getId())
166 .append("measureId", measureId)
167 .append("measureDate", measureDate)
168 .append("snapshotId", snapshotId)
169 .append("snapshotDate", snapshotDate)
170 .toString();
171 }
172 }