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    @Entity
031    @Table(name = "async_measure_snapshots")
032    public class AsyncMeasureSnapshot extends BaseIdentifiable {
033    
034      @Column(name = "project_measure_id", updatable = true, nullable = true)
035      private Integer measureId;
036    
037      @Temporal(TemporalType.TIMESTAMP)
038      @Column(name = "measure_date", updatable = true, nullable = true)
039      private Date measureDate;
040    
041      @Column(name = "snapshot_id", updatable = true, nullable = true)
042      private Integer snapshotId;
043    
044      @Temporal(TemporalType.TIMESTAMP)
045      @Column(name = "snapshot_date", updatable = true, nullable = true)
046      private Date snapshotDate;
047    
048      @Column(name = "metric_id", updatable = true, nullable = true)
049      private Integer metricId;
050    
051      @Column(name = "project_id", updatable = true, nullable = true)
052      private Integer projectId;
053    
054      public AsyncMeasureSnapshot(Integer measureId, Integer snapshotId, Date measureDate, Date snapshotDate, Integer metricId, Integer projectId) {
055        this.measureId = measureId;
056        this.measureDate = measureDate;
057        this.snapshotId = snapshotId;
058        this.snapshotDate = snapshotDate;
059        this.projectId = projectId;
060        this.metricId = metricId;
061      }
062    
063      public AsyncMeasureSnapshot() {
064      }
065    
066      public Integer getMeasureId() {
067        return measureId;
068      }
069    
070      public void setMeasureId(Integer measureId) {
071        this.measureId = measureId;
072      }
073    
074      public Integer getSnapshotId() {
075        return snapshotId;
076      }
077    
078      public void setSnapshotId(Integer snapshotId) {
079        this.snapshotId = snapshotId;
080      }
081    
082      public Date getMeasureDate() {
083        return measureDate;
084      }
085    
086      public void setMeasureDate(Date measureDate) {
087        this.measureDate = measureDate;
088      }
089    
090      public Date getSnapshotDate() {
091        return snapshotDate;
092      }
093    
094      public void setSnapshotDate(Date snapshotDate) {
095        this.snapshotDate = snapshotDate;
096      }
097    
098      public Integer getMetricId() {
099        return metricId;
100      }
101    
102      public void setMetricId(Integer metricId) {
103        this.metricId = metricId;
104      }
105    
106      public Integer getProjectId() {
107        return projectId;
108      }
109    
110      public void setProjectId(Integer projectId) {
111        this.projectId = projectId;
112      }
113    
114      public void setMeasure(MeasureModel measure) {
115        setMeasureId(measure.getId());
116        setMeasureDate(measure.getMeasureDate());
117      }
118    
119      @Override
120      public boolean equals(Object obj) {
121        if (!(obj instanceof AsyncMeasureSnapshot)) {
122          return false;
123        }
124        if (this == obj) {
125          return true;
126        }
127        AsyncMeasureSnapshot other = (AsyncMeasureSnapshot) obj;
128        return new EqualsBuilder()
129            .append(measureId, other.getMeasureId())
130            .append(measureDate, other.getMeasureDate())
131            .append(snapshotId, other.getSnapshotId())
132            .append(snapshotDate, other.getSnapshotDate())
133            .isEquals();
134      }
135    
136      @Override
137      public int hashCode() {
138        return new HashCodeBuilder(17, 37)
139            .append(measureId)
140            .append(measureDate)
141            .append(snapshotDate)
142            .append(snapshotId)
143            .toHashCode();
144      }
145    
146      @Override
147      public String toString() {
148        return new ToStringBuilder(this)
149            .append("id", getId())
150            .append("measureId", measureId)
151            .append("measureDate", measureDate)
152            .append("snapshotId", snapshotId)
153            .append("snapshotDate", snapshotDate)
154            .toString();
155      }
156    }