1 package com.edf.gde.ejb;
3 import com.edf.gde.entities.Attribute;
4 import com.edf.gde.entities.AttributeGroup;
5 import com.edf.gde.transferables.AttributeGroupTO;
6 import com.edf.gde.transferables.AttributeTO;
7 import javax.ejb.Stateless;
8 import javax.ejb.LocalBean;
9 import javax.persistence.EntityManager;
10 import javax.persistence.PersistenceContext;
18 public class MetadataDAO {
19 @PersistenceContext(unitName = "GDE-ejbPU")
20 private EntityManager em;
24 public AttributeTO createAttribute(AttributeTO ato) {
25 Attribute a = Attribute.fromAttributeTO(ato);
27 return a.toAttributeTO();
30 public void deleteAttribute(AttributeTO ato) {
31 Attribute a = Attribute.fromAttributeTO(ato);
35 public AttributeTO updateAttribute(AttributeTO ato) {
36 Attribute a = Attribute.fromAttributeTO(ato);
37 Attribute up = em.merge(a);
38 return up.toAttributeTO();
41 public AttributeTO findAttribute(AttributeTO ato) {
42 Attribute found = em.find(Attribute.class, ato.getId());
43 return found.toAttributeTO();
46 private <T> AttributeTO findBy(String queryName, String varName, T value) {
48 Attribute found = (Attribute) em.createNamedQuery(queryName)
49 .setParameter(varName, value)
51 return found.toAttributeTO();
58 public AttributeTO findById(long id) {
59 return findBy("Attribute.findById", "id", id);
62 public AttributeTO findByName(String name) {
63 return findBy("Attribute.findByName", "name", name);
66 public AttributeTO findByType(String type) {
67 return findBy("Attribute.findByType", "type", type);
70 public AttributeTO findByValue(String value) {
71 return findBy("Attribute.findByValue", "value", value);
74 /* Attributes Groups */
76 public AttributeGroupTO createAttributeGroup(AttributeGroupTO agto) {
77 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
79 return group.toAttributeGroupTO();
82 public void deleteAttributeGroup(AttributeGroupTO agto) {
83 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
87 public AttributeGroupTO updateAttributeGroup(AttributeGroupTO agto) {
88 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
89 AttributeGroup up = em.merge(group);
90 return up.toAttributeGroupTO();
93 public AttributeGroupTO findAttributeGroup(AttributeGroupTO agto) {
94 AttributeGroup found = em.find(AttributeGroup.class, agto.getId());
95 return found.toAttributeGroupTO();
98 public AttributeGroupTO findGroupById(long groupId) {
100 AttributeGroup found = (AttributeGroup) em.createNamedQuery("AttributeGroup.findById")
101 .setParameter("id", groupId)
103 return found.toAttributeGroupTO();
105 catch (Exception e) {