Salome HOME
- Renamed MetadataDAO to MetadataEJB
authorBojnourdi <kavoos.bojnourdi@edf.fr>
Sat, 8 Aug 2015 20:17:06 +0000 (22:17 +0200)
committerBojnourdi <kavoos.bojnourdi@edf.fr>
Sat, 8 Aug 2015 20:17:06 +0000 (22:17 +0200)
- Created new MetadataDAO class
- Fixed exception in MetadataDAO

projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/MetadataDAO.java [new file with mode: 0644]
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataDAO.java [deleted file]
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataEJB.java [new file with mode: 0644]

diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/MetadataDAO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/MetadataDAO.java
new file mode 100644 (file)
index 0000000..16d3c84
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * (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();
+    }
+}
+
diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataDAO.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataDAO.java
deleted file mode 100644 (file)
index f053bbc..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-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;
-        }
-    }
-    
-}
diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataEJB.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/MetadataEJB.java
new file mode 100644 (file)
index 0000000..912ec49
--- /dev/null
@@ -0,0 +1,91 @@
+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);
+    }
+
+}