From 5256c3359802df457fd49edfc74c06a24c2db708 Mon Sep 17 00:00:00 2001 From: Bojnourdi Date: Fri, 14 Aug 2015 11:51:17 +0200 Subject: [PATCH] Working on Profiles Updated SQL Created transferables Preparing ProfileDao --- .../src/java/com/edf/gde/dao/ProfileDao.java | 20 ++++++ .../java/com/edf/gde/entities/Profile.java | 14 ++++- .../edf/gde/entities/ProfileAttribute.java | 32 +++++++--- .../com/edf/gde/transferables/ChunkTO.java | 4 +- .../gde/transferables/ProfileAttributeTO.java | 62 +++++++++++++++++++ .../com/edf/gde/transferables/ProfileTO.java | 45 ++++++++++++++ projects/GDE_App/src/GDE_DB_Init.sql | 9 +++ 7 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/ProfileDao.java create mode 100644 projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java create mode 100644 projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileTO.java diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/ProfileDao.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/ProfileDao.java new file mode 100644 index 0000000..1781582 --- /dev/null +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/ProfileDao.java @@ -0,0 +1,20 @@ +/* + * (C) 2015 EDF + */ +package com.edf.gde.dao; + +import javax.persistence.EntityManager; + +/** + * + * @author Kavoos + */ +public class ProfileDao { + + private final EntityManager em; + + public ProfileDao(EntityManager em) { + this.em = em; + } + +} diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java index d215437..0e9affd 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java @@ -7,11 +7,15 @@ import java.io.Serializable; 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.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; @@ -35,6 +39,7 @@ import javax.xml.bind.annotation.XmlTransient; @NamedQuery(name = "Profile.findByName", query = "SELECT p FROM Profile p WHERE p.name = :name") }) public class Profile implements Serializable { + private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @@ -46,7 +51,12 @@ public class Profile implements Serializable { @Size(max = 255) @Column(name = "name") private String name; - @OneToMany(mappedBy = "profileId") + @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + @JoinTable(name = "PROFILE_ATTRIBUTE_PROFILE", + joinColumns = { + @JoinColumn(name = "profile_id", referencedColumnName = "id")}, + inverseJoinColumns = { + @JoinColumn(name = "attibute_id", referencedColumnName = "id", unique = true)}) private Collection profileAttributeCollection; public Profile() { @@ -109,5 +119,5 @@ public class Profile implements Serializable { } return true; } - + } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java index 66f4da9..3a90e3d 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java @@ -3,11 +3,13 @@ */ package com.edf.gde.entities; +import com.edf.gde.transferables.ProfileAttributeTO; import java.io.Serializable; import java.util.Objects; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -50,10 +52,10 @@ public class ProfileAttribute implements Serializable { @Column(name = "type") private String type; @Column(name = "mandatory") - private Boolean mandatory; - @JoinColumn(name = "profile_id", referencedColumnName = "id", nullable = false) + private boolean mandatory; @ManyToOne - private Profile profileId; + @JoinColumn(name = "profile_id", referencedColumnName = "id") + private Profile profile; public ProfileAttribute() { } @@ -86,20 +88,30 @@ public class ProfileAttribute implements Serializable { this.type = type; } - public Boolean getMandatory() { + public boolean getMandatory() { return mandatory; } - public void setMandatory(Boolean mandatory) { + public void setMandatory(boolean mandatory) { this.mandatory = mandatory; } - public Profile getProfileId() { - return profileId; + public Profile getProfile() { + return profile; } - public void setProfileId(Profile profileId) { - this.profileId = profileId; + public void setProfile(Profile profileId) { + this.profile = profileId; + } + + public static ProfileAttribute fromProfileAttributeTO (EntityManager em, ProfileAttributeTO attributeTO) { + ProfileAttribute attribute = new ProfileAttribute(); + attribute.id = attributeTO.getId(); + attribute.mandatory = attributeTO.isMandatory(); + attribute.name = attributeTO.getName(); + attribute.type = attributeTO.getType(); + attribute.profile = em.find(Profile.class, attributeTO.getProfileId()); + return attribute; } @Override @@ -114,7 +126,7 @@ public class ProfileAttribute implements Serializable { hash = 71 * hash + Objects.hashCode(this.name); hash = 71 * hash + Objects.hashCode(this.type); hash = 71 * hash + Objects.hashCode(this.mandatory); - hash = 71 * hash + Objects.hashCode(this.profileId); + hash = 71 * hash + Objects.hashCode(this.profile); return hash; } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ChunkTO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ChunkTO.java index 587584e..40b3d7b 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ChunkTO.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ChunkTO.java @@ -1,7 +1,5 @@ /* - * 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.transferables; diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java new file mode 100644 index 0000000..c23d497 --- /dev/null +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileAttributeTO.java @@ -0,0 +1,62 @@ +package com.edf.gde.transferables; + +import java.io.Serializable; + +/* + * (C) 2015 EDF + */ +/** + * + * @author Kavoos + */ +public class ProfileAttributeTO implements Serializable { + + private Long id; + private String name; + private String type; + private boolean mandatory; + private long profileId; + + public ProfileAttributeTO() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public boolean isMandatory() { + return mandatory; + } + + public void setMandatory(boolean mandatory) { + this.mandatory = mandatory; + } + + public long getProfileId() { + return profileId; + } + + public void setProfileId(long profileId) { + this.profileId = profileId; + } +} diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileTO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileTO.java new file mode 100644 index 0000000..c9aae13 --- /dev/null +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/transferables/ProfileTO.java @@ -0,0 +1,45 @@ +/* + * (C) 2015 EDF + */ +package com.edf.gde.transferables; + +import java.io.Serializable; +import java.util.List; + +/** + * + * @author Kavoos + */ +public class ProfileTO implements Serializable { + private long id; + private String name; + List attributes; + + public ProfileTO() { + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + +} diff --git a/projects/GDE_App/src/GDE_DB_Init.sql b/projects/GDE_App/src/GDE_DB_Init.sql index 56c62eb..78597a1 100644 --- a/projects/GDE_App/src/GDE_DB_Init.sql +++ b/projects/GDE_App/src/GDE_DB_Init.sql @@ -61,6 +61,8 @@ CREATE TABLE attribute_group_attribute ); alter table attribute_group_attribute add primary key (attributegroup_id, attribute_id); +/* PROFILE */ + DROP TABLE IF EXISTS profile CASCADE; CREATE TABLE profile ( id bigint NOT NULL PRIMARY KEY, @@ -76,6 +78,13 @@ CREATE TABLE profile_attribute ( profile_id bigint REFERENCES profile (id) ); +DROP TABLE IF EXISTS PROFILE_ATTRIBUTE_PROFILE CASCADE; +CREATE TABLE PROFILE_ATTRIBUTE_PROFILE ( + profile_id bigint references profile(id) on update no action on delete no action, + profile_attribute_id references profile_attribute on update no action on delete no action +); +alter table PROFILE_ATTRIBUTE_PROFILE add primary key (profile_id bigint, profile_attribute_id); + /* DATA */ DROP TABLE IF EXISTS gde_file CASCADE; -- 2.39.2