The DAO should not see the transferables...
File / Chunk / Study
*/
package com.edf.gde.dao;
-import com.edf.gde.transferables.ChunkTO;
+import com.edf.gde.entities.Chunk;
/**
*
*/
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);
-
}
*/
package com.edf.gde.dao;
-import com.edf.gde.transferables.FileTO;
+import com.edf.gde.entities.GDEFile;
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);
}
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;
/**
*/
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);
}
@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;
}
}
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;
}
@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);
}
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;
}
@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
}
@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);
}
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;
@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);
- }
-
}
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;
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();
}
}
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;
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) {
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) {
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;