View Javadoc

1   /*
2    * Sonar, entreprise quality control tool.
3    * Copyright (C) 2007-2008 Hortis-GRC SA
4    * mailto:be_agile HAT hortis DOT ch
5    *
6    * Sonar is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * Sonar is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with {library}; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19   */
20  package ch.hortis.sonar.model;
21  
22  import org.apache.commons.lang.builder.EqualsBuilder;
23  import org.apache.commons.lang.builder.HashCodeBuilder;
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  import org.hibernate.annotations.Cache;
26  import org.hibernate.annotations.CacheConcurrencyStrategy;
27  import org.hibernate.annotations.Immutable;
28  
29  import javax.persistence.Column;
30  import javax.persistence.Entity;
31  import javax.persistence.GeneratedValue;
32  import javax.persistence.GenerationType;
33  import javax.persistence.Id;
34  import javax.persistence.NamedQueries;
35  import javax.persistence.NamedQuery;
36  import javax.persistence.SequenceGenerator;
37  import javax.persistence.Table;
38  
39  @Immutable
40  @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
41  @Entity
42  @Table(name = "rules_categories")
43  @NamedQueries(
44      {@NamedQuery(name = RulesCategory.SQL_SELECT_ALL, query = "SELECT r FROM RulesCategory r")}
45  )
46  public class RulesCategory {
47  
48    public final static String SQL_SELECT_ALL = "RulesCategory.selectAll";
49  
50    @Id
51    @Column(name = "id")
52    @SequenceGenerator(name = "RULES_CATEGORIES_SEQ", sequenceName = "RULES_CATEGORIES_SEQ")
53    @GeneratedValue(strategy = GenerationType.AUTO, generator = "RULES_CATEGORIES_SEQ")
54    private Integer id;
55  
56    @Column(name = "name", updatable = false, nullable = false)
57    private String name;
58  
59    @Column(name = "description", updatable = false, nullable = true)
60    private String description;
61  
62    public RulesCategory(String name) {
63      this.name = name;
64    }
65  
66    public RulesCategory(String name, String description) {
67      this.name = name;
68      this.description = description;
69    }
70  
71    public RulesCategory() {
72    }
73  
74    public Integer getId() {
75      return id;
76    }
77  
78    public void setId(Integer id) {
79      this.id = id;
80    }
81  
82    public String getName() {
83      return name;
84    }
85  
86    public void setName(String name) {
87      this.name = name;
88    }
89  
90    public String getDescription() {
91      return description;
92    }
93  
94    public void setDescription(String description) {
95      this.description = description;
96    }
97  
98    public boolean equals(Object obj) {
99      if (!(obj instanceof RulesCategory)) {
100       return false;
101     }
102     if (this == obj) {
103       return true;
104     }
105     RulesCategory other = (RulesCategory) obj;
106     return new EqualsBuilder()
107         .append(name, other.getName()).isEquals();
108   }
109 
110   public int hashCode() {
111     return new HashCodeBuilder(17, 37)
112         .append(name)
113         .toHashCode();
114   }
115 
116   public String toString() {
117     return new ToStringBuilder(this)
118         .append("id", id)
119         .append("name", name)
120         .append("desc", description)
121         .toString();
122   }
123 
124 }