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     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     @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade = {CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REMOVE,CascadeType.REFRESH})
50     private Collection<Attribute> attributeCollection;
51
52     public AttributeGroup() {
53     }
54
55     public AttributeGroup(long id) {
56         this.id = id;
57     }
58
59     public long getId() {
60         return id;
61     }
62
63     public void setId(long id) {
64         this.id = id;
65     }
66
67     @XmlTransient
68     public Collection<Attribute> getAttributeCollection() {
69         return attributeCollection;
70     }
71
72     public void setAttributeCollection(Collection<Attribute> attributeCollection) {
73         this.attributeCollection = attributeCollection;
74     }
75
76     public static AttributeGroup fromAttributeGroupTO(AttributeGroupTO agto) {
77         AttributeGroup group = new AttributeGroup();
78         group.id = agto.getId();
79         
80         group.attributeCollection = new ArrayList<>();
81         Collection<AttributeTO> attributes = agto.getAttributeCollection();
82         for (AttributeTO ato : attributes) {
83             group.attributeCollection.add(Attribute.fromAttributeTO(ato));
84         }
85     
86         return group;
87     }
88     
89     public AttributeGroupTO toAttributeGroupTO() {
90         AttributeGroupTO agto = new AttributeGroupTO();
91         agto.setId(this.id);
92         
93         Collection<AttributeTO> atos = new ArrayList<>();
94         for (Attribute a : this.attributeCollection) {
95             atos.add(a.toAttributeTO());
96         }
97         agto.setAttributeCollection(atos);
98         return agto;
99     }
100     
101     @Override
102     public String toString() {
103         return "com.edf.gde.entities.AttributeGroup[ id=" + id + " ]";
104     }
105
106     @Override
107     public int hashCode() {
108         int hash = 7;
109         hash = 79 * hash + (int) (this.id ^ (this.id >>> 32));
110         hash = 79 * hash + Objects.hashCode(this.attributeCollection);
111         return hash;
112     }
113
114     @Override
115     public boolean equals(Object obj) {
116         if (obj == null) {
117             return false;
118         }
119         if (getClass() != obj.getClass()) {
120             return false;
121         }
122         final AttributeGroup other = (AttributeGroup) obj;
123         if (this.id != other.id) {
124             return false;
125         }
126         return true;
127     }
128
129 }