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.
6 package com.edf.gde.entities;
8 import com.edf.gde.transferables.AttributeGroupTO;
9 import com.edf.gde.transferables.AttributeTO;
10 import java.io.Serializable;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Objects;
14 import javax.persistence.Basic;
15 import javax.persistence.Column;
16 import javax.persistence.Entity;
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;
33 @Entity(name = "AttributeGroup")
34 @Table(name = "attribute_group")
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")
40 public class AttributeGroup implements Serializable {
41 private static final long serialVersionUID = 1L;
43 @Basic(optional = false)
45 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN_SEQUENCE")
46 @SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
50 private Collection<Attribute> attributeCollection;
52 public AttributeGroup() {
55 public AttributeGroup(long id) {
63 public void setId(long id) {
68 public Collection<Attribute> getAttributeCollection() {
69 return attributeCollection;
72 public void setAttributeCollection(Collection<Attribute> attributeCollection) {
73 this.attributeCollection = attributeCollection;
76 public static AttributeGroup fromAttributeGroupTO(AttributeGroupTO agto) {
77 AttributeGroup group = new AttributeGroup();
78 group.id = agto.getId();
80 group.attributeCollection = new ArrayList<>();
81 Collection<AttributeTO> attributes = agto.getAttributeCollection();
82 for (AttributeTO ato : attributes) {
83 group.attributeCollection.add(Attribute.fromAttributeTO(ato));
89 public AttributeGroupTO toAttributeGroupTO() {
90 AttributeGroupTO agto = new AttributeGroupTO();
93 Collection<AttributeTO> atos = new ArrayList<>();
94 for (Attribute a : this.attributeCollection) {
95 atos.add(a.toAttributeTO());
97 agto.setAttributeCollection(atos);
102 public String toString() {
103 return "com.edf.gde.entities.AttributeGroup[ id=" + id + " ]";
107 public int hashCode() {
109 hash = 79 * hash + (int) (this.id ^ (this.id >>> 32));
110 hash = 79 * hash + Objects.hashCode(this.attributeCollection);
115 public boolean equals(Object obj) {
119 if (getClass() != obj.getClass()) {
122 final AttributeGroup other = (AttributeGroup) obj;
123 if (this.id != other.id) {