Salome HOME
- Code refactoring and simplification
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / entities / Attribute.java
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package com.edf.gde.entities;
7
8 import com.edf.gde.transferables.AttributeTO;
9 import java.io.Serializable;
10 import java.util.Objects;
11 import javax.persistence.Basic;
12 import javax.persistence.Column;
13 import javax.persistence.Entity;
14 import javax.persistence.GeneratedValue;
15 import javax.persistence.GenerationType;
16 import javax.persistence.Id;
17 import javax.persistence.NamedQueries;
18 import javax.persistence.NamedQuery;
19 import javax.persistence.SequenceGenerator;
20 import javax.persistence.Table;
21 import javax.validation.constraints.NotNull;
22 import javax.validation.constraints.Size;
23 import javax.xml.bind.annotation.XmlRootElement;
24
25 /**
26  *
27  * @author F62173
28  */
29 @Entity
30 @Table(name = "attribute")
31 @XmlRootElement
32 @NamedQueries({
33     @NamedQuery(name = "Attribute.findAll", query = "SELECT a FROM Attribute a"),
34     @NamedQuery(name = "Attribute.findById", query = "SELECT a FROM Attribute a WHERE a.id = :id"),
35     @NamedQuery(name = "Attribute.findByName", query = "SELECT a FROM Attribute a WHERE a.name = :name"),
36     @NamedQuery(name = "Attribute.findByType", query = "SELECT a FROM Attribute a WHERE a.type = :type"),
37     @NamedQuery(name = "Attribute.findByValue", query = "SELECT a FROM Attribute a WHERE a.value = :value"),
38     //@NamedQuery(name = "Attribute.findByMandatory", query = "SELECT a FROM Attribute a WHERE a.mandatory = :mandatory")
39 })
40 public class Attribute implements Serializable {
41     private static final long serialVersionUID = 1L;
42     @Id
43     @Basic(optional = false)
44     @NotNull
45     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
46     @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
47     @Column(name = "id")
48     private long id;
49     @Size(max = 255)
50     @Column(name = "name")
51     private String name;
52     @Size(max = 255)
53     @Column(name = "type")
54     private String type;
55     @Size(max = 255)
56     @Column(name = "value")
57     private String value;
58     @Column(name = "mandatory")
59     private Boolean mandatory;
60     @Column(name = "attribute_group_id")
61     private long attributeGroupId;
62
63     public Attribute() {
64     }
65
66     public Attribute(long id) {
67         this.id = id;
68     }
69
70     public long getId() {
71         return id;
72     }
73
74     public void setId(long id) {
75         this.id = id;
76     }
77
78     public String getName() {
79         return name;
80     }
81
82     public void setName(String name) {
83         this.name = name;
84     }
85
86     public String getType() {
87         return type;
88     }
89
90     public void setType(String type) {
91         this.type = type;
92     }
93
94     public String getValue() {
95         return value;
96     }
97
98     public void setValue(String value) {
99         this.value = value;
100     }
101
102     public Boolean getMandatory() {
103         return mandatory;
104     }
105
106     public void setMandatory(Boolean mandatory) {
107         this.mandatory = mandatory;
108     }
109
110     public long getAttributeGroupId() {
111         return attributeGroupId;
112     }
113
114     public void setAttributeGroupId(long groupId) {
115         this.attributeGroupId = groupId;
116     }
117
118     public static Attribute fromAttributeTO(AttributeTO ato) {
119         Attribute attribute = new Attribute();
120         attribute.id = ato.getId();
121         attribute.name = ato.getName();
122         attribute.type = ato.getType();
123         attribute.value = ato.getValue();
124         attribute.mandatory = ato.getMandatory();
125         attribute.attributeGroupId = ato.getGroupId();
126         return attribute;
127     }
128     
129     public AttributeTO toAttributeTO() {
130         AttributeTO ato = new AttributeTO();
131         ato.setId(this.id);
132         ato.setName(this.name);
133         ato.setType(this.type);
134         ato.setValue(this.value);
135         ato.setMandatory(this.mandatory);
136         ato.setGroupId(this.attributeGroupId);
137         return ato;
138     }
139     
140     @Override
141     public String toString() {
142         return "com.edf.gde.entities.Attribute[ id=" + id + " ]";
143     }
144
145     @Override
146     public int hashCode() {
147         int hash = 3;
148         hash = 67 * hash + (int) (this.id ^ (this.id >>> 32));
149         hash = 67 * hash + Objects.hashCode(this.name);
150         hash = 67 * hash + Objects.hashCode(this.type);
151         hash = 67 * hash + Objects.hashCode(this.value);
152         hash = 67 * hash + Objects.hashCode(this.mandatory);
153         hash = 67 * hash + (int) (this.attributeGroupId ^ (this.attributeGroupId >>> 32));
154         return hash;
155     }
156
157     @Override
158     public boolean equals(Object obj) {
159         if (obj == null) {
160             return false;
161         }
162         if (getClass() != obj.getClass()) {
163             return false;
164         }
165         final Attribute other = (Attribute) obj;
166         if (this.id != other.id) {
167             return false;
168         }
169         return true;
170     }
171
172 }