package sn.unitech.stock.dao;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import sn.unitech.stock.dao.iface.ISysAdherActiviteDao;
import sn.unitech.stock.dao.iface.ISysAdherEventDao;
import sn.unitech.stock.dao.iface.ISysAdherentDao;
import sn.unitech.stock.entity.SysAdherActivite;
import sn.unitech.stock.entity.SysAdherEvent;
import sn.unitech.stock.entity.SysAdherent;
import sn.unitech.stock.modal.Resultat;
public class SysAdherentDao<E> extends DataAccess<SysAdherent> implements ISysAdherentDao<SysAdherent>{
private ISysAdherEventDao<SysAdherEvent> iAdherEventDao=new SysAdherEventDao<SysAdherEvent>();
private ISysAdherActiviteDao<SysAdherActivite> iAdherActiviteDao=new SysAdherActiviteDao<SysAdherActivite>();
public SysAdherentDao() {
}
@Override
public Resultat persistAdherent(SysAdherent adherent) {
EntityManager em=getEntityManager();
EntityTransaction tx=em.getTransaction();
tx.begin();
this.persist(adherent, em);
for(SysAdherEvent adherEvent:adherent.getSysAdherEvents()){
this.iAdherEventDao.persist(adherEvent, em);
}
for(SysAdherActivite adherActivite:adherent.getSysAdherActivites()){
this.iAdherActiviteDao.persist(adherActivite, em);
}
tx.commit();
em.close();
return new Resultat(true,"Validation reussie!");
}
}