package sn.unitech.stock.dao;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import sn.unitech.common.dao.ReadProperties;
import sn.unitech.stock.dao.iface.ISysGroupProdDao;
import sn.unitech.stock.entity.SysActivite;
import sn.unitech.stock.entity.SysAdherGroupProd;
import sn.unitech.stock.entity.SysAdherGroupProdId;
import sn.unitech.stock.entity.SysAdherent;
import sn.unitech.stock.entity.SysGroupProd;
public class SysGroupProdDao extends DataAccess implements ISysGroupProdDao {
private ReadProperties readProperties=ReadProperties.getReadProperties();
public SysGroupProdDao(){
}
@SuppressWarnings("unchecked")
public boolean saveGroupProduit(SysGroupProd sysGroupProd,SysAdherGroupProd sysAdherGroupProd){
EntityManager em=getEntityManager();
EntityTransaction tx= em.getTransaction();
try{
tx.begin();
SysActivite activite =(SysActivite)this.find(SysActivite.class,sysGroupProd.getSysActivite().getIdActivite(),em);
sysGroupProd.setSysActivite(activite);
this.persist(sysGroupProd, em);
sysAdherGroupProd.setSysGroupProd(sysGroupProd);
SysAdherent adherent=(SysAdherent)this.find(SysAdherent.class,sysAdherGroupProd.getSysAdherent().getIdAdherent(), em);
sysAdherGroupProd.setSysAdherent(adherent);
sysAdherGroupProd.setId(new SysAdherGroupProdId(adherent.getIdAdherent(),sysGroupProd.getIdGroupProd()));
this.persist(sysAdherGroupProd, em);
tx.commit();
return true;
}
catch(Exception ex){
if((tx!=null)&&(tx.isActive()))tx.rollback();
ex.printStackTrace();
return false;
}
finally{
em.close();
}
}
}