/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
+ * (C) 2015 EDF
*/
package com.edf.gde.entities;
+import com.edf.gde.transferables.AttributeGroupTO;
+import com.edf.gde.transferables.AttributeTO;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import javax.persistence.Basic;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
-import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
@NamedQuery(name = "AttributeGroup.findById", query = "SELECT a FROM AttributeGroup a WHERE a.id = :id")
})
public class AttributeGroup implements Serializable {
+
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@SequenceGenerator(name = "SEQ_GEN_SEQUENCE", allocationSize = 50)
@Column(name = "id")
private long id;
- @OneToMany(mappedBy = "groupId")
+
+ @OneToMany (fetch = FetchType.EAGER, orphanRemoval = true, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH})
private Collection<Attribute> attributeCollection;
public AttributeGroup() {
this.attributeCollection = attributeCollection;
}
+ public static AttributeGroup fromAttributeGroupTO(AttributeGroupTO agto) {
+ AttributeGroup group = new AttributeGroup();
+ group.id = agto.getId();
+ Collection<AttributeTO> attributes = agto.getAttributeCollection();
+ if (attributes != null) {
+ group.attributeCollection = new ArrayList<>();
+ for (AttributeTO ato : attributes) {
+ group.attributeCollection.add(Attribute.fromAttributeTO(ato));
+ }
+ }
+ return group;
+ }
+
+ public AttributeGroupTO toAttributeGroupTO() {
+ AttributeGroupTO agto = new AttributeGroupTO();
+ agto.setId(this.id);
+
+ Collection<AttributeTO> atos = new ArrayList<>();
+ if (attributeCollection != null) {
+ for (Attribute a : this.attributeCollection) {
+ atos.add(a.toAttributeTO());
+ }
+ agto.setAttributeCollection(atos);
+ }
+
+ return agto;
+ }
+
@Override
public String toString() {
return "com.edf.gde.entities.AttributeGroup[ id=" + id + " ]";