Salome HOME
Attribute DAO
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / entities / AttributeGroup.java
1 /*
2  * (C) 2015 EDF
3  */
4 package com.edf.gde.entities;
5
6 import com.edf.gde.transferables.AttributeGroupTO;
7 import com.edf.gde.transferables.AttributeTO;
8 import java.io.Serializable;
9 import java.util.ArrayList;
10 import java.util.Collection;
11 import java.util.Objects;
12 import javax.persistence.Basic;
13 import javax.persistence.CascadeType;
14 import javax.persistence.Column;
15 import javax.persistence.Entity;
16 import javax.persistence.FetchType;
17 import javax.persistence.GeneratedValue;
18 import javax.persistence.GenerationType;
19 import javax.persistence.Id;
20 import javax.persistence.NamedQueries;
21 import javax.persistence.NamedQuery;
22 import javax.persistence.OneToMany;
23 import javax.persistence.SequenceGenerator;
24 import javax.persistence.Table;
25 import javax.validation.constraints.NotNull;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import javax.xml.bind.annotation.XmlTransient;
28
29 /**
30  *
31  * @author F62173
32  */
33 @Entity(name = "AttributeGroup")
34 @Table(name = "attribute_group")
35 @XmlRootElement
36 @NamedQueries({
37     @NamedQuery(name = "AttributeGroup.findAll", query = "SELECT a FROM AttributeGroup a"),
38     @NamedQuery(name = "AttributeGroup.findById", query = "SELECT a FROM AttributeGroup a WHERE a.id = :id")
39 })
40 public class AttributeGroup implements Serializable {
41
42     private static final long serialVersionUID = 1L;
43     @Id
44     @Basic(optional = false)
45     @NotNull
46     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
47     @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
48     @Column(name = "id")
49     private long id;
50     
51     @OneToMany (fetch = FetchType.EAGER, orphanRemoval = true, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH})
52     private Collection<Attribute> attributeCollection;
53
54     public AttributeGroup() {
55     }
56
57     public AttributeGroup(long id) {
58         this.id = id;
59     }
60
61     public long getId() {
62         return id;
63     }
64
65     public void setId(long id) {
66         this.id = id;
67     }
68
69     @XmlTransient
70     public Collection<Attribute> getAttributeCollection() {
71         return attributeCollection;
72     }
73
74     public void setAttributeCollection(Collection<Attribute> attributeCollection) {
75         this.attributeCollection = attributeCollection;
76     }
77
78     public static AttributeGroup fromAttributeGroupTO(AttributeGroupTO agto) {
79         AttributeGroup group = new AttributeGroup();
80         group.id = agto.getId();
81         Collection<AttributeTO> attributes = agto.getAttributeCollection();
82         if (attributes != null) {
83             group.attributeCollection = new ArrayList<>();
84             for (AttributeTO ato : attributes) {
85                 group.attributeCollection.add(Attribute.fromAttributeTO(ato));
86             }
87         }
88         return group;
89     }
90
91     public AttributeGroupTO toAttributeGroupTO() {
92         AttributeGroupTO agto = new AttributeGroupTO();
93         agto.setId(this.id);
94
95         Collection<AttributeTO> atos = new ArrayList<>();
96         if (attributeCollection != null) {
97             for (Attribute a : this.attributeCollection) {
98                 atos.add(a.toAttributeTO());
99             }
100             agto.setAttributeCollection(atos);
101         }
102
103         return agto;
104     }
105
106     @Override
107     public String toString() {
108         return "com.edf.gde.entities.AttributeGroup[ id=" + id + " ]";
109     }
110
111     @Override
112     public int hashCode() {
113         int hash = 7;
114         hash = 79 * hash + (int) (this.id ^ (this.id >>> 32));
115         hash = 79 * hash + Objects.hashCode(this.attributeCollection);
116         return hash;
117     }
118
119     @Override
120     public boolean equals(Object obj) {
121         if (obj == null) {
122             return false;
123         }
124         if (getClass() != obj.getClass()) {
125             return false;
126         }
127         final AttributeGroup other = (AttributeGroup) obj;
128         if (this.id != other.id) {
129             return false;
130         }
131         return true;
132     }
133
134 }