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.ejb;
8 import com.edf.gde.entities.Attribute;
9 import com.edf.gde.entities.AttributeGroup;
10 import com.edf.gde.transferables.AttributeGroupTO;
11 import com.edf.gde.transferables.AttributeTO;
12 import javax.ejb.Stateless;
13 import javax.ejb.LocalBean;
14 import javax.persistence.EntityManager;
15 import javax.persistence.PersistenceContext;
23 public class MetadataDAO {
24 @PersistenceContext(unitName = "GDE-ejbPU")
25 private EntityManager em;
29 public AttributeTO createAttribute(AttributeTO ato) {
30 Attribute a = Attribute.fromAttributeTO(ato);
32 return a.toAttributeTO();
35 public void deleteAttribute(AttributeTO ato) {
36 Attribute a = Attribute.fromAttributeTO(ato);
40 public AttributeTO updateAttribute(AttributeTO ato) {
41 Attribute a = Attribute.fromAttributeTO(ato);
42 Attribute up = em.merge(a);
43 return up.toAttributeTO();
46 public AttributeTO findAttribute(AttributeTO ato) {
47 Attribute found = em.find(Attribute.class, ato.getId());
48 return found.toAttributeTO();
51 private <T> AttributeTO findBy(String queryName, String varName, T value) {
53 Attribute found = (Attribute) em.createNamedQuery(queryName)
54 .setParameter(varName, value)
56 return found.toAttributeTO();
63 public AttributeTO findById(long id) {
64 return findBy("Attribute.findById", "id", id);
67 public AttributeTO findByName(String name) {
68 return findBy("Attribute.findByName", "name", name);
71 public AttributeTO findByType(String type) {
72 return findBy("Attribute.findByType", "type", type);
75 public AttributeTO findByValue(String value) {
76 return findBy("Attribute.findByValue", "value", value);
79 /* Attributes Groups */
81 public AttributeGroupTO createAttributeGroup(AttributeGroupTO agto) {
82 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
84 return group.toAttributeGroupTO();
87 public void deleteAttributeGroup(AttributeGroupTO agto) {
88 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
92 public AttributeGroupTO updateAttributeGroup(AttributeGroupTO agto) {
93 AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
94 AttributeGroup up = em.merge(group);
95 return up.toAttributeGroupTO();
98 public AttributeGroupTO findAttributeGroup(AttributeGroupTO agto) {
99 AttributeGroup found = em.find(AttributeGroup.class, agto.getId());
100 return found.toAttributeGroupTO();
103 public AttributeGroupTO findGroupById(long groupId) {
105 AttributeGroup found = (AttributeGroup) em.createNamedQuery("AttributeGroup.findById")
106 .setParameter("id", groupId)
108 return found.toAttributeGroupTO();
110 catch (Exception e) {