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