]> SALOME platform Git repositories - modules/gde.git/commitdiff
Salome HOME
Cleanup DAO
authorKavoos Bojnourdi <kavoos.bojnourdi@edf.fr>
Wed, 19 Aug 2015 07:33:30 +0000 (09:33 +0200)
committerKavoos Bojnourdi <kavoos.bojnourdi@edf.fr>
Wed, 19 Aug 2015 07:33:30 +0000 (09:33 +0200)
The DAO should not see the transferables...

File / Chunk / Study

projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/ChunkDao.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/FileDao.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/StudyDao.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/ChunkDaoImpl.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/FileDaoImpl.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/dao/impl/StudyDaoImpl.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/ChunkEJB.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/FileEJB.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/ejb/StudyEJB.java
projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java

index a7007d16ec7d6d92730269c0818a0508657e4748..0f87f302fdf3ce14b10966795a872257addd4b51 100644 (file)
@@ -3,7 +3,7 @@
  */
 package com.edf.gde.dao;
 
-import com.edf.gde.transferables.ChunkTO;
+import com.edf.gde.entities.Chunk;
 
 /**
  *
@@ -11,16 +11,10 @@ import com.edf.gde.transferables.ChunkTO;
  */
 public interface ChunkDao {
 
-    ChunkTO createChunk(ChunkTO cto);
+    Chunk createChunk(Chunk cto);
 
-    void deleteChunk(ChunkTO cto);
+    public Chunk findByFileId(long fileId);
 
-    ChunkTO findByFileId(long fileId);
+    public Chunk findById(long id);
 
-    ChunkTO findById(long id);
-
-    ChunkTO findChunk(ChunkTO cto);
-
-    ChunkTO updateChunk(ChunkTO cto);
-    
 }
index ae7dbf28cc08c294a52abfdec24196ff5abcfcdd..a2e4b12178fa6f0064b88fdf89583947cacf5454 100644 (file)
@@ -3,7 +3,7 @@
  */
 package com.edf.gde.dao;
 
-import com.edf.gde.transferables.FileTO;
+import com.edf.gde.entities.GDEFile;
 import java.util.Date;
 
 /**
@@ -12,24 +12,22 @@ import java.util.Date;
  */
 public interface FileDao {
 
-    FileTO createFile(FileTO fto);
+    GDEFile createFile(GDEFile fto);
 
-    void deleteFile(FileTO fto);
+    void deleteFile(long id);
     
     void validate(long fileId);
 
-    FileTO findByCreationDate(Date creationDate);
+    GDEFile findByCreationDate(Date creationDate);
 
-    FileTO findByDeletionDate(Date deletionDate);
+    GDEFile findByDeletionDate(Date deletionDate);
 
-    FileTO findById(long id);
+    GDEFile findById(long id);
 
-    FileTO findByName(String name);
+    GDEFile findByName(String name);
 
-    FileTO findByUpdateDate(Date updateDate);
+    GDEFile findByUpdateDate(Date updateDate);
 
-    FileTO findFile(FileTO fto);
-
-    FileTO updateFile(FileTO fto);
+    GDEFile updateFile(GDEFile fto);
     
 }
index 385cf567fff47df304a1f0aa8234beb95387be3d..b5bb7913242daa10bf9c844c7ed07d3e76e6b1f9 100644 (file)
@@ -4,7 +4,7 @@
 package com.edf.gde.dao;
 
 import com.edf.gde.dao.lock.LockStatus;
-import com.edf.gde.transferables.StudyTO;
+import com.edf.gde.entities.Study;
 import java.util.Date;
 
 /**
@@ -13,23 +13,23 @@ import java.util.Date;
  */
 public interface StudyDao {
 
-    StudyTO createStudy(StudyTO sto);
+    Study createStudy(Study sto);
 
     void deleteStudy(long studyId);
 
-    StudyTO findByCreationDate(Date creationDate);
+    Study findByCreationDate(Date creationDate);
 
-    StudyTO findByDeletionDate(Date deletionDate);
+    Study findByDeletionDate(Date deletionDate);
 
-    StudyTO findById(long id);
+    Study findById(long id);
 
-    StudyTO findByName(String name);
+    Study findByName(String name);
 
-    StudyTO findByUpdateDate(Date updateDate);
+    Study findByUpdateDate(Date updateDate);
 
-    StudyTO findStudy(StudyTO sto);
+    Study findStudy(Study sto);
 
-    StudyTO updateStudy(StudyTO sto);
+    Study updateStudy(Study sto);
     
     LockStatus getLockStatus(long studyId);
     
index d65e8dc54c90f22d550b2322dafd2152cb72c4d8..8b5f8db9bae35e46861cfef715940308a4f55910 100644 (file)
@@ -22,52 +22,25 @@ public class ChunkDaoImpl implements ChunkDao {
     }
 
     @Override
-    public ChunkTO createChunk(ChunkTO cto) {
-        Chunk c = Chunk.fromChunkTO(cto);
-        GDEFile file = em.find(GDEFile.class, cto.getFileId());
-        if (file == null) {
-            throw new RuntimeException("Invalid file id");
-        }
-        if (file.isValid()) {
-            throw new RuntimeException("Cannot add chunk to validated file");
-        }
+    public Chunk createChunk(Chunk c) {
         em.persist(c);
-        return c.toChunkTO();
+        return c;
     }
 
     @Override
-    public void deleteChunk(ChunkTO cto) {
-        Chunk c = Chunk.fromChunkTO(cto);
-        em.remove(c);
-    }
-
-    @Override
-    public ChunkTO updateChunk(ChunkTO cto) {
-        Chunk c = Chunk.fromChunkTO(cto);
-        Chunk up = em.merge(c);
-        return up.toChunkTO();
-    }
-
-    @Override
-    public ChunkTO findChunk(ChunkTO cto) {
-        Chunk found = em.find(Chunk.class, cto.getId());
-        return found.toChunkTO();
-    }
-
-    @Override
-    public ChunkTO findById(long id) {
+    public Chunk findById(long id) {
         Chunk found = (Chunk) em.createNamedQuery("Chunk.findById")
                 .setParameter("id", id)
                 .getSingleResult();
-        return found.toChunkTO();
+        return found;
     }
 
     @Override
-    public ChunkTO findByFileId(long fileId) {
+    public Chunk findByFileId(long fileId) {
         Chunk found = (Chunk) em.createNamedQuery("Chunk.findByFileId")
                 .setParameter("fileId", fileId)
                 .getSingleResult();
-        return found.toChunkTO();
+        return found;
     }
 
 }
index ea6794d00d4ab31a86506e243779bd9249a7dd8a..80e0f62f98fe0fac00792496ec43de39d2ce8c0e 100644 (file)
@@ -5,7 +5,6 @@ package com.edf.gde.dao.impl;
 
 import com.edf.gde.dao.FileDao;
 import com.edf.gde.entities.GDEFile;
-import com.edf.gde.transferables.FileTO;
 import java.util.Date;
 import javax.persistence.EntityManager;
 
@@ -22,62 +21,54 @@ public class FileDaoImpl implements FileDao {
     }
 
     @Override
-    public FileTO createFile(FileTO fto) {
-        GDEFile f = GDEFile.fromFileTO(fto);
-        f.setValid(false);
-        f.setDeleted(false);
-        em.persist(f);
-        return f.toFileTO();
+    public GDEFile createFile(GDEFile file) {
+        file.setValid(false);
+        file.setDeleted(false);
+        em.persist(file);
+        return file;
     }
 
     @Override
-    public void deleteFile(FileTO fto) {
-        GDEFile f = GDEFile.fromFileTO(fto);
-        em.remove(f);
+    public void deleteFile(long id) {
+        GDEFile file = em.find(GDEFile.class, id);
+        em.remove(file);
     }
 
     @Override
-    public FileTO updateFile(FileTO fto) {
-        GDEFile f = GDEFile.fromFileTO(fto);
-        GDEFile up = em.merge(f);
-        return up.toFileTO();
+    public GDEFile updateFile(GDEFile file) {
+        GDEFile up = em.merge(file);
+        return up;
     }
 
-    @Override
-    public FileTO findFile(FileTO fto) {
-        GDEFile found = em.find(GDEFile.class, fto.getId());
-        return found.toFileTO();
-    }
-
-    private <T> FileTO findBy(String queryName, String varName, T value) {
+    private <T> GDEFile findBy(String queryName, String varName, T value) {
         GDEFile found = (GDEFile) em.createNamedQuery(queryName)
                 .setParameter(varName, value)
                 .getSingleResult();
-        return found.toFileTO();
+        return found;
     }
 
     @Override
-    public FileTO findById(long id) {
+    public GDEFile findById(long id) {
         return findBy("File.findById", "id", id);
     }
 
     @Override
-    public FileTO findByName(String name) {
+    public GDEFile findByName(String name) {
         return findBy("File.findByName", "name", name);
     }
 
     @Override
-    public FileTO findByCreationDate(Date creationDate) {
+    public GDEFile findByCreationDate(Date creationDate) {
         return findBy("File.findByCreationDate", "creationDate", creationDate);
     }
 
     @Override
-    public FileTO findByUpdateDate(Date updateDate) {
+    public GDEFile findByUpdateDate(Date updateDate) {
         return findBy("File.findByUpdateDate", "updateDate", updateDate);
     }
 
     @Override
-    public FileTO findByDeletionDate(Date deletionDate) {
+    public GDEFile findByDeletionDate(Date deletionDate) {
         return findBy("File.findByDeletionDate", "deletionDate", deletionDate);
     }
 
index f8df6d96e8ee19de4ab717df16c70fa91dd2db5c..0ca5fe80bef667e52aa1173e745f9a772f214536 100644 (file)
@@ -6,7 +6,6 @@ package com.edf.gde.dao.impl;
 import com.edf.gde.dao.StudyDao;
 import com.edf.gde.dao.lock.LockStatus;
 import com.edf.gde.entities.Study;
-import com.edf.gde.transferables.StudyTO;
 import java.util.Date;
 import javax.persistence.EntityManager;
 
@@ -23,10 +22,9 @@ public class StudyDaoImpl implements StudyDao {
     }
 
     @Override
-    public StudyTO createStudy(StudyTO sto) {
-        Study s = Study.fromStudyTO(sto);
-        em.persist(s);
-        return s.toStudyTO();
+    public Study createStudy(Study study) {
+        em.persist(study);
+        return study;
     }
 
     @Override
@@ -42,47 +40,45 @@ public class StudyDaoImpl implements StudyDao {
     }
 
     @Override
-    public StudyTO updateStudy(StudyTO sto) {
-        Study s = Study.fromStudyTO(sto);
-        Study up = em.merge(s);
-        return up.toStudyTO();
+    public Study updateStudy(Study study) {
+        return em.merge(study);
     }
 
     @Override
-    public StudyTO findStudy(StudyTO sto) {
-        Study found = em.find(Study.class, sto.getId());
-        return found.toStudyTO();
+    public Study findStudy(Study study) {
+        Study found = em.find(Study.class, study.getId());
+        return found;
     }
 
-    private <T> StudyTO findBy(String queryName, String varName, T value) {
+    private <T> Study findBy(String queryName, String varName, T value) {
         Study found = (Study) em.createNamedQuery(queryName)
                 .setParameter(varName, value)
                 .getSingleResult();
-        return found.toStudyTO();
+        return found;
     }
 
     @Override
-    public StudyTO findById(long id) {
+    public Study findById(long id) {
         return findBy("Study.findById", "id", id);
     }
 
     @Override
-    public StudyTO findByName(String name) {
+    public Study findByName(String name) {
         return findBy("Study.findByName", "name", name);
     }
 
     @Override
-    public StudyTO findByCreationDate(Date creationDate) {
+    public Study findByCreationDate(Date creationDate) {
         return findBy("Study.findByCreationDate", "creationDate", creationDate);
     }
 
     @Override
-    public StudyTO findByUpdateDate(Date updateDate) {
+    public Study findByUpdateDate(Date updateDate) {
         return findBy("Study.findByUpdateDate", "updateDate", updateDate);
     }
 
     @Override
-    public StudyTO findByDeletionDate(Date deletionDate) {
+    public Study findByDeletionDate(Date deletionDate) {
         return findBy("Study.findByDeletionDate", "deletionDate", deletionDate);
     }
 
index 51ba9bd59f0e11aa98d894dd5e99b20b1a6b96c0..c5450ceeb5f879b45dcd052bf46d8e0587785c09 100644 (file)
@@ -4,7 +4,11 @@
 package com.edf.gde.ejb;
 
 import com.edf.gde.dao.ChunkDao;
+import com.edf.gde.dao.FileDao;
 import com.edf.gde.dao.impl.ChunkDaoImpl;
+import com.edf.gde.dao.impl.FileDaoImpl;
+import com.edf.gde.entities.Chunk;
+import com.edf.gde.entities.GDEFile;
 import com.edf.gde.transferables.ChunkTO;
 import javax.ejb.Stateless;
 import javax.ejb.LocalBean;
@@ -22,34 +26,21 @@ public class ChunkEJB {
     @PersistenceContext(unitName = "GDE-ejbPU")
     private EntityManager em;
 
-    public ChunkTO createChunk(ChunkTO cto) {
+    public void createChunk(ChunkTO cto) {
         ChunkDao dao = new ChunkDaoImpl(em);
-        return dao.createChunk(cto);
+        FileDao fd = new FileDaoImpl(em);
+        GDEFile file = fd.findById(cto.getFileId());
+        if (file == null) {
+            throw new RuntimeException("Invalid file id");
+        }
+        if (file.isValid()) {
+            throw new RuntimeException("Cannot add chunk to validated file");
+        }
+        dao.createChunk(Chunk.fromChunkTO(cto));
     }
 
-    public void deleteChunk(ChunkTO cto) {
+    public ChunkTO readChunk(long id) {
         ChunkDao dao = new ChunkDaoImpl(em);
-        dao.deleteChunk(cto);
+        return dao.findById(id).toChunkTO();
     }
-
-    public ChunkTO updateChunk(ChunkTO cto) {
-        ChunkDao dao = new ChunkDaoImpl(em);
-        return dao.updateChunk(cto);
-    }
-
-    public ChunkTO findChunk(ChunkTO cto) {
-        ChunkDao dao = new ChunkDaoImpl(em);
-        return dao.findChunk(cto);
-    }
-
-    public ChunkTO findById(long id) {
-        ChunkDao dao = new ChunkDaoImpl(em);
-        return dao.findById(id);
-    }
-
-    public ChunkTO findByFileId(long fileId) {
-        ChunkDao dao = new ChunkDaoImpl(em);
-        return dao.findByFileId(fileId);
-    }
-
 }
index 134e5f2375a817a06c584273a8ff7e85762f91f9..df889c739aa47b432791a953fd88103323b52448 100644 (file)
@@ -5,6 +5,7 @@ package com.edf.gde.ejb;
 
 import com.edf.gde.dao.FileDao;
 import com.edf.gde.dao.impl.FileDaoImpl;
+import com.edf.gde.entities.GDEFile;
 import com.edf.gde.transferables.FileTO;
 import java.util.Date;
 import javax.ejb.Stateless;
@@ -25,47 +26,42 @@ public class FileEJB {
 
     public FileTO createFile(FileTO fto) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.createFile(fto);
+        return dao.createFile(GDEFile.fromFileTO(fto)).toFileTO();
     }
 
-    public void deleteFile(FileTO fto) {
+    public void deleteFile(long id) {
         FileDao dao = new FileDaoImpl(em);
-        dao.deleteFile(fto);
+        dao.deleteFile(id);
     }
 
     public FileTO updateFile(FileTO fto) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.updateFile(fto);
+        return dao.updateFile(GDEFile.fromFileTO(fto)).toFileTO();
     }
-
-    public FileTO findFile(FileTO fto) {
-        FileDao dao = new FileDaoImpl(em);
-        return dao.findFile(fto);
-    }
-
+    
     public FileTO findById(long id) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.findById(id);
+        return dao.findById(id).toFileTO();
     }
 
     public FileTO findByName(String name) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.findByName(name);
+        return dao.findByName(name).toFileTO();
     }
 
     public FileTO findByCreationDate(Date creationDate) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.findByCreationDate(creationDate);
+        return dao.findByCreationDate(creationDate).toFileTO();
     }
 
     public FileTO findByUpdateDate(Date updateDate) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.findByUpdateDate(updateDate);
+        return dao.findByUpdateDate(updateDate).toFileTO();
     }
 
     public FileTO findByDeletionDate(Date deletionDate) {
         FileDao dao = new FileDaoImpl(em);
-        return dao.findByDeletionDate(deletionDate);
+        return dao.findByDeletionDate(deletionDate).toFileTO();
     }
 
 }
index 704481716b0452635b934b1ad44b33def3895270..5cc98eb9ec2cd97af6c221ab37de206a18478dc9 100644 (file)
@@ -6,6 +6,7 @@ package com.edf.gde.ejb;
 import com.edf.gde.dao.StudyDao;
 import com.edf.gde.dao.impl.StudyDaoImpl;
 import com.edf.gde.dao.lock.LockStatus;
+import com.edf.gde.entities.Study;
 import com.edf.gde.transferables.StudyTO;
 import java.util.Date;
 import javax.ejb.Stateless;
@@ -27,7 +28,7 @@ public class StudyEJB {
     public StudyTO createStudy(long userId, StudyTO sto) {
         StudyDao dao = new StudyDaoImpl(em);
         sto.setLockOwner(userId);
-        return dao.createStudy(sto);
+        return dao.createStudy(Study.fromStudyTO(sto)).toStudyTO();
     }
 
     public void deleteStudy(long studyId) {
@@ -47,37 +48,37 @@ public class StudyEJB {
                 throw new RuntimeException("Study is locked");
             }
         }
-        return dao.updateStudy(sto);
+        return dao.updateStudy(Study.fromStudyTO(sto)).toStudyTO();
     }
 
     public StudyTO findStudy(StudyTO sto) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findStudy(sto);
+        return dao.findStudy(Study.fromStudyTO(sto)).toStudyTO();
     }
 
     public StudyTO findById(long id) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findById(id);
+        return dao.findById(id).toStudyTO();
     }
 
     public StudyTO findByName(String name) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findByName(name);
+        return dao.findByName(name).toStudyTO();
     }
 
     public StudyTO findByCreationDate(Date creationDate) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findByCreationDate(creationDate);
+        return dao.findByCreationDate(creationDate).toStudyTO();
     }
 
     public StudyTO findByUpdateDate(Date updateDate) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findByUpdateDate(updateDate);
+        return dao.findByUpdateDate(updateDate).toStudyTO();
     }
 
     public StudyTO findByDeletionDate(Date deletionDate) {
         StudyDao dao = new StudyDaoImpl(em);
-        return dao.findByDeletionDate(deletionDate);
+        return dao.findByDeletionDate(deletionDate).toStudyTO();
     }
 
     public void setStudyState(long userId, long studyId, boolean state) {
index 8e655e40df020df2cec4ce478ee90e7e24b3e489..d360865253458660fe22f7bedd8e05bc7afc127a 100644 (file)
@@ -5,7 +5,6 @@ package com.edf.gde.entities;
 
 import com.edf.gde.transferables.ChunkTO;
 import java.io.Serializable;
-import java.util.Arrays;
 import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.Column;