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 })
37 public class Attribute implements Serializable {
38     private static final long serialVersionUID = 1L;
39     @Id
40     @Basic(optional = false)
41     @NotNull
42     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
43     @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
44     @Column(name = "id")
45     private long id;
46     @Size(max = 255)
47     @Column(name = "name")
48     private String name;
49     @Size(max = 255)
50     @Column(name = "type")
51     private String type;
52     @Size(max = 255)
53     @Column(name = "value")
54     private String value;
55     @Column(name = "mandatory")
56     private Boolean mandatory;
57     @Column(name = "attribute_group_id")
58     private long attributeGroupId;
59
60     public Attribute() {
61     }
62
63     public Attribute(long id) {
64         this.id = id;
65     }
66
67     public long getId() {
68         return id;
69     }
70
71     public void setId(long id) {
72         this.id = id;
73     }
74
75     public String getName() {
76         return name;
77     }
78
79     public void setName(String name) {
80         this.name = name;
81     }
82
83     public String getType() {
84         return type;
85     }
86
87     public void setType(String type) {
88         this.type = type;
89     }
90
91     public String getValue() {
92         return value;
93     }
94
95     public void setValue(String value) {
96         this.value = value;
97     }
98
99     public Boolean getMandatory() {
100         return mandatory;
101     }
102
103     public void setMandatory(Boolean mandatory) {
104         this.mandatory = mandatory;
105     }
106
107     public long getAttributeGroupId() {
108         return attributeGroupId;
109     }
110
111     public void setAttributeGroupId(long groupId) {
112         this.attributeGroupId = groupId;
113     }
114
115     public static Attribute fromAttributeTO(AttributeTO ato) {
116         Attribute attribute = new Attribute();
117         attribute.id = ato.getId();
118         attribute.name = ato.getName();
119         attribute.type = ato.getType();
120         attribute.value = ato.getValue();
121         attribute.mandatory = ato.getMandatory();
122         attribute.attributeGroupId = ato.getGroupId();
123         return attribute;
124     }
125     
126     public AttributeTO toAttributeTO() {
127         AttributeTO ato = new AttributeTO();
128         ato.setId(this.id);
129         ato.setName(this.name);
130         ato.setType(this.type);
131         ato.setValue(this.value);
132         ato.setMandatory(this.mandatory);
133         ato.setGroupId(this.attributeGroupId);
134         return ato;
135     }
136     
137     @Override
138     public String toString() {
139         return "com.edf.gde.entities.Attribute[ id=" + id + " ]";
140     }
141
142     @Override
143     public int hashCode() {
144         int hash = 3;
145         hash = 67 * hash + (int) (this.id ^ (this.id >>> 32));
146         hash = 67 * hash + Objects.hashCode(this.name);
147         hash = 67 * hash + Objects.hashCode(this.type);
148         hash = 67 * hash + Objects.hashCode(this.value);
149         hash = 67 * hash + Objects.hashCode(this.mandatory);
150         hash = 67 * hash + (int) (this.attributeGroupId ^ (this.attributeGroupId >>> 32));
151         return hash;
152     }
153
154     @Override
155     public boolean equals(Object obj) {
156         if (obj == null) {
157             return false;
158         }
159         if (getClass() != obj.getClass()) {
160             return false;
161         }
162         final Attribute other = (Attribute) obj;
163         if (this.id != other.id) {
164             return false;
165         }
166         return true;
167     }
168
169 }