package com.megatim.fdxconvert.service;
|
|
import com.megatimfx.common.pojo.SearchCriteria;
|
import com.megatimfx.common.service.GenericCrudService;
|
import com.megatim.fdxconvert.dao.AbstractDAO;
|
import com.megatim.fdxconvert.dao.HibernateUtil;
|
import com.megatim.fdxconvert.model.Tache;
|
import com.megatim.fdxconvert.model.TypeFichier;
|
import com.megatim.fdxconvert.service.pojo.PaginationElts;
|
import java.util.List;
|
import org.hibernate.Session;
|
import org.hibernate.query.Query;
|
|
/**
|
*
|
* @author lenovo
|
*/
|
public class TacheService implements GenericCrudService<Tache> {
|
|
private static TacheService service;
|
|
private static AbstractDAO<Tache> dao;
|
|
private PaginationElts<Tache> pagination;
|
|
public static synchronized TacheService getInstance() {
|
if (service == null) {
|
service = new TacheService();
|
dao = new AbstractDAO<>(Tache.class);
|
}
|
return service;
|
}
|
|
@Override
|
public Tache add(Tache t) throws Exception {
|
return dao.add(t);
|
}
|
|
@Override
|
public Tache edit(Tache t) throws Exception {
|
return dao.edit(t);
|
}
|
|
@Override
|
public List<Tache> getAll() throws Exception {
|
return dao.getAll("Tache");
|
}
|
|
@Override
|
public void delete(Tache t) throws Exception {
|
dao.delete(t);
|
Thread th = new Thread(() -> {
|
TacheJobService.getInstance().restartJob();
|
});
|
|
th.setDaemon(true);
|
th.start();
|
}
|
|
public Tache findByTacheId(String tacheId) {
|
|
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
|
|
Query query = session.createQuery("from Tache where libelle = :tacheId");
|
query.setParameter("tacheId", tacheId);
|
return (Tache) query.uniqueResult();
|
|
}
|
|
}
|
|
public Tache findByTypefichier(TypeFichier typeFichier) {
|
|
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
|
|
Query query = session.createQuery("from Tache where typeFichier = :typeFichier");
|
query.setParameter("typeFichier", typeFichier);
|
return (Tache) query.uniqueResult();
|
|
}
|
|
}
|
|
public Tache findByRepertoireSource(String repertoireSource) {
|
|
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
|
|
Query query = session.createQuery("from Tache where repertoireSource = :repertoireSource");
|
query.setParameter("repertoireSource", repertoireSource);
|
return (Tache) query.uniqueResult();
|
|
}
|
|
}
|
|
public Tache findByRepertoireDestination(String repertoireDestination) {
|
|
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
|
|
Query query = session.createQuery("from Tache where repertoireDestination = :repertoireDestination");
|
query.setParameter("repertoireDestination", repertoireDestination);
|
return (Tache) query.uniqueResult();
|
|
}
|
|
}
|
|
public Tache findByRepertoireErreur(String repertoireErreur) {
|
|
try ( Session session = HibernateUtil.getSessionFactory().openSession()) {
|
|
Query query = session.createQuery("from Tache where repertoireErreur = :repertoireErreur");
|
query.setParameter("repertoireErreur", repertoireErreur);
|
return (Tache) query.uniqueResult();
|
|
}
|
|
}
|
|
//PAGINATION BLOCK
|
@Override
|
public boolean isLast() {
|
return pagination.isLast();
|
}
|
|
@Override
|
public boolean isFirst() {
|
return pagination.isFirst();
|
}
|
|
@Override
|
public int getCurrentPage() {
|
return pagination.getPage();
|
}
|
|
@Override
|
public int getNumberOfElements() {
|
return pagination.getNumberOfElts();
|
}
|
|
@Override
|
public int getNumberPerPage() {
|
return pagination.getNbEltsPerPage();
|
}
|
|
@Override
|
public Long getTotalElements() {
|
return pagination.getTotalElts();
|
}
|
|
@Override
|
public List<Tache> getAllByPage(int pageNumber, List<SearchCriteria> searchCriterias) {
|
pagination = dao.initPaginationElts(pageNumber, searchCriterias);
|
return pagination.getListe();
|
}
|
}
|