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.design;
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
026 import javax.persistence.*;
027
028 @Entity
029 @Table(name = "dependencies")
030 public class DependencyDto {
031
032 @Id
033 @Column(name = "id")
034 @GeneratedValue
035 private Long id;
036
037 @Column(name = "from_snapshot_id", updatable = true, nullable = false)
038 private Integer fromSnapshotId;
039
040 @Column(name = "from_resource_id", updatable = true, nullable = false)
041 private Integer fromResourceId;
042
043 @Column(name = "from_scope", updatable = true, nullable = true)
044 private String fromScope;
045
046 @Column(name = "to_snapshot_id", updatable = true, nullable = false)
047 private Integer toSnapshotId;
048
049 @Column(name = "to_resource_id", updatable = true, nullable = false)
050 private Integer toResourceId;
051
052 @Column(name = "to_scope", updatable = true, nullable = true)
053 private String toScope;
054
055 @Column(name = "dep_weight", updatable = true, nullable = true)
056 private Integer weight;
057
058 @Column(name = "dep_usage", updatable = true, nullable = true, length = 30)
059 private String usage;
060
061 @Column(name = "project_snapshot_id", updatable = true, nullable = false)
062 private Integer projectSnapshotId;
063
064 @Column(name = "parent_dependency_id", updatable = true, nullable = true)
065 private Long parentDependencyId;
066
067 public Long getId() {
068 return id;
069 }
070
071 public void setId(Long id) {
072 this.id = id;
073 }
074
075 public Integer getFromSnapshotId() {
076 return fromSnapshotId;
077 }
078
079 public DependencyDto setFromSnapshotId(Integer fromSnapshotId) {
080 this.fromSnapshotId = fromSnapshotId;
081 return this;
082 }
083
084 public Integer getFromResourceId() {
085 return fromResourceId;
086 }
087
088 public DependencyDto setFromResourceId(Integer fromResourceId) {
089 this.fromResourceId = fromResourceId;
090 return this;
091 }
092
093 public Integer getToSnapshotId() {
094 return toSnapshotId;
095 }
096
097 public DependencyDto setToSnapshotId(Integer toSnapshotId) {
098 this.toSnapshotId = toSnapshotId;
099 return this;
100 }
101
102 public Integer getToResourceId() {
103 return toResourceId;
104 }
105
106 public DependencyDto setToResourceId(Integer toResourceId) {
107 this.toResourceId = toResourceId;
108 return this;
109 }
110
111 public Integer getWeight() {
112 return weight;
113 }
114
115 public DependencyDto setWeight(Integer weight) {
116 if (weight < 0) {
117 throw new IllegalArgumentException("Dependency weight can not be negative");
118 }
119 this.weight = weight;
120 return this;
121 }
122
123 public String getFromScope() {
124 return fromScope;
125 }
126
127 public DependencyDto setFromScope(String fromScope) {
128 this.fromScope = fromScope;
129 return this;
130 }
131
132 public String getToScope() {
133 return toScope;
134 }
135
136 public DependencyDto setToScope(String toScope) {
137 this.toScope = toScope;
138 return this;
139 }
140
141 public String getUsage() {
142 return usage;
143 }
144
145 public DependencyDto setUsage(String usage) {
146 this.usage = usage;
147 return this;
148 }
149
150 public Integer getProjectSnapshotId() {
151 return projectSnapshotId;
152 }
153
154 public DependencyDto setProjectSnapshotId(Integer projectSnapshotId) {
155 this.projectSnapshotId = projectSnapshotId;
156 return this;
157 }
158
159 public Long getParentDependencyId() {
160 return parentDependencyId;
161 }
162
163 public DependencyDto setParentDependencyId(Long parentDependencyId) {
164 this.parentDependencyId = parentDependencyId;
165 return this;
166 }
167
168 @Override
169 public boolean equals(Object obj) {
170 if (!(obj instanceof DependencyDto)) {
171 return false;
172 }
173 if (this == obj) {
174 return true;
175 }
176 DependencyDto other = (DependencyDto) obj;
177 return new EqualsBuilder()
178 .append(fromSnapshotId, other.fromSnapshotId)
179 .append(toSnapshotId, other.toSnapshotId)
180 .isEquals();
181 }
182
183 @Override
184 public int hashCode() {
185 return new HashCodeBuilder(17, 37)
186 .append(fromSnapshotId)
187 .append(toSnapshotId)
188 .toHashCode();
189 }
190
191 @Override
192 public String toString() {
193 return new ToStringBuilder(this)
194 .append("id", getId())
195 .append("fromSnapshotId", fromSnapshotId)
196 .append("fromResourceId", fromResourceId)
197 .append("fromScope", fromScope)
198 .append("toSnapshotId", toSnapshotId)
199 .append("toResourceId", toResourceId)
200 .append("toScope", toScope)
201 .append("weight", weight)
202 .append("usage", usage)
203 .append("projectSnapshotId", projectSnapshotId)
204 .append("parentDependencyId", parentDependencyId)
205 .toString();
206 }
207 }