--- /dev/null
+/*
+ * (C) 2015 EDF
+ */
+package com.edf.gde.dao;
+
+import com.edf.gde.entities.Attribute;
+import com.edf.gde.entities.AttributeGroup;
+import com.edf.gde.transferables.AttributeGroupTO;
+import com.edf.gde.transferables.AttributeTO;
+import javax.persistence.EntityManager;
+
+/**
+ *
+ * @author Kavoos
+ */
+public class MetadataDAO {
+
+ private EntityManager em;
+
+ public MetadataDAO(EntityManager em) {
+ this.em = em;
+ }
+
+ public AttributeTO createAttribute(AttributeTO ato) {
+ Attribute a = Attribute.fromAttributeTO(ato);
+ em.persist(a);
+ return a.toAttributeTO();
+ }
+
+ public void deleteAttribute(AttributeTO ato) {
+ Attribute a = Attribute.fromAttributeTO(ato);
+ em.remove(a);
+ }
+
+ public AttributeTO updateAttribute(AttributeTO ato) {
+ Attribute a = Attribute.fromAttributeTO(ato);
+ Attribute up = em.merge(a);
+ return up.toAttributeTO();
+ }
+
+ public AttributeTO findAttribute(AttributeTO ato) {
+ Attribute found = em.find(Attribute.class, ato.getId());
+ return found.toAttributeTO();
+ }
+
+ private <T> AttributeTO findBy(String queryName, String varName, T value) {
+ try {
+ Attribute found = (Attribute) em.createNamedQuery(queryName)
+ .setParameter(varName, value)
+ .getSingleResult();
+ return found.toAttributeTO();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public AttributeTO findById(long id) {
+ return findBy("Attribute.findById", "id", id);
+ }
+
+ public AttributeTO findByName(String name) {
+ return findBy("Attribute.findByName", "name", name);
+ }
+
+ public AttributeTO findByType(String type) {
+ return findBy("Attribute.findByType", "type", type);
+ }
+
+ public AttributeTO findByValue(String value) {
+ return findBy("Attribute.findByValue", "value", value);
+ }
+
+ /* Attributes Groups */
+ public AttributeGroupTO createAttributeGroup(AttributeGroupTO agto) {
+ AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
+ em.persist(group);
+ return group.toAttributeGroupTO();
+ }
+
+ public void deleteAttributeGroup(AttributeGroupTO agto) {
+ AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
+ em.remove(group);
+ }
+
+ public AttributeGroupTO updateAttributeGroup(AttributeGroupTO agto) {
+ AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
+ AttributeGroup up = em.merge(group);
+ return up.toAttributeGroupTO();
+ }
+
+ public AttributeGroupTO findAttributeGroup(AttributeGroupTO agto) {
+ AttributeGroup found = em.find(AttributeGroup.class, agto.getId());
+ return found.toAttributeGroupTO();
+ }
+
+ public AttributeGroupTO findGroupById(long groupId) {
+ AttributeGroup found = (AttributeGroup) em.createNamedQuery("AttributeGroup.findById")
+ .setParameter("id", groupId)
+ .getSingleResult();
+ return found.toAttributeGroupTO();
+ }
+}
+
+++ /dev/null
-package com.edf.gde.ejb;
-
-import com.edf.gde.entities.Attribute;
-import com.edf.gde.entities.AttributeGroup;
-import com.edf.gde.transferables.AttributeGroupTO;
-import com.edf.gde.transferables.AttributeTO;
-import javax.ejb.Stateless;
-import javax.ejb.LocalBean;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-/**
- *
- * @author F62173
- */
-@Stateless
-@LocalBean
-public class MetadataDAO {
- @PersistenceContext(unitName = "GDE-ejbPU")
- private EntityManager em;
-
- /* Attributes */
-
- public AttributeTO createAttribute(AttributeTO ato) {
- Attribute a = Attribute.fromAttributeTO(ato);
- em.persist(a);
- return a.toAttributeTO();
- }
-
- public void deleteAttribute(AttributeTO ato) {
- Attribute a = Attribute.fromAttributeTO(ato);
- em.remove(a);
- }
-
- public AttributeTO updateAttribute(AttributeTO ato) {
- Attribute a = Attribute.fromAttributeTO(ato);
- Attribute up = em.merge(a);
- return up.toAttributeTO();
- }
-
- public AttributeTO findAttribute(AttributeTO ato) {
- Attribute found = em.find(Attribute.class, ato.getId());
- return found.toAttributeTO();
- }
-
- private <T> AttributeTO findBy(String queryName, String varName, T value) {
- try {
- Attribute found = (Attribute) em.createNamedQuery(queryName)
- .setParameter(varName, value)
- .getSingleResult();
- return found.toAttributeTO();
- }
- catch (Exception e) {
- return null;
- }
- }
-
- public AttributeTO findById(long id) {
- return findBy("Attribute.findById", "id", id);
- }
-
- public AttributeTO findByName(String name) {
- return findBy("Attribute.findByName", "name", name);
- }
-
- public AttributeTO findByType(String type) {
- return findBy("Attribute.findByType", "type", type);
- }
-
- public AttributeTO findByValue(String value) {
- return findBy("Attribute.findByValue", "value", value);
- }
-
- /* Attributes Groups */
-
- public AttributeGroupTO createAttributeGroup(AttributeGroupTO agto) {
- AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
- em.persist(group);
- return group.toAttributeGroupTO();
- }
-
- public void deleteAttributeGroup(AttributeGroupTO agto) {
- AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
- em.remove(group);
- }
-
- public AttributeGroupTO updateAttributeGroup(AttributeGroupTO agto) {
- AttributeGroup group = AttributeGroup.fromAttributeGroupTO(agto);
- AttributeGroup up = em.merge(group);
- return up.toAttributeGroupTO();
- }
-
- public AttributeGroupTO findAttributeGroup(AttributeGroupTO agto) {
- AttributeGroup found = em.find(AttributeGroup.class, agto.getId());
- return found.toAttributeGroupTO();
- }
-
- public AttributeGroupTO findGroupById(long groupId) {
- try {
- AttributeGroup found = (AttributeGroup) em.createNamedQuery("AttributeGroup.findById")
- .setParameter("id", groupId)
- .getSingleResult();
- return found.toAttributeGroupTO();
- }
- catch (Exception e) {
- return null;
- }
- }
-
-}
--- /dev/null
+package com.edf.gde.ejb;
+
+import com.edf.gde.dao.MetadataDAO;
+import com.edf.gde.entities.Attribute;
+import com.edf.gde.entities.AttributeGroup;
+import com.edf.gde.transferables.AttributeGroupTO;
+import com.edf.gde.transferables.AttributeTO;
+import javax.ejb.Stateless;
+import javax.ejb.LocalBean;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ *
+ * @author F62173
+ */
+@Stateless
+@LocalBean
+public class MetadataEJB {
+
+ @PersistenceContext(unitName = "GDE-ejbPU")
+ private EntityManager em;
+
+ /* Attributes */
+ public AttributeTO createAttribute(AttributeTO ato) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.createAttribute(ato);
+ }
+
+ public void deleteAttribute(AttributeTO ato) {
+ MetadataDAO dao = new MetadataDAO(em);
+ dao.deleteAttribute(ato);
+ }
+
+ public AttributeTO updateAttribute(AttributeTO ato) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.updateAttribute(ato);
+ }
+
+ public AttributeTO findAttribute(AttributeTO ato) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findAttribute(ato);
+ }
+
+ public AttributeTO findById(long id) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findById(id);
+ }
+
+ public AttributeTO findByName(String name) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findByName(name);
+ }
+
+ public AttributeTO findByType(String type) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findByType(type);
+ }
+
+ public AttributeTO findByValue(String value) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findByValue(value);
+ }
+
+ /* Attributes Groups */
+ public AttributeGroupTO createAttributeGroup(AttributeGroupTO agto) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return createAttributeGroup(agto);
+ }
+
+ public void deleteAttributeGroup(AttributeGroupTO agto) {
+ MetadataDAO dao = new MetadataDAO(em);
+ dao.deleteAttributeGroup(agto);
+ }
+
+ public AttributeGroupTO updateAttributeGroup(AttributeGroupTO agto) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.updateAttributeGroup(agto);
+ }
+
+ public AttributeGroupTO findAttributeGroup(AttributeGroupTO agto) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findAttributeGroup(agto);
+ }
+
+ public AttributeGroupTO findGroupById(long groupId) {
+ MetadataDAO dao = new MetadataDAO(em);
+ return dao.findGroupById(groupId);
+ }
+
+}