package sn.unitech.stock.dao;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import sn.unitech.stock.dao.iface.IClientDao;
import sn.unitech.stock.entity.Client;
public class ClientDao extends DataAccess<Client> implements IClientDao<Client>{
public ClientDao() {
}
public boolean persistClient(Client client) {
EntityManager em=getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Object obj;
obj=client.getIdClient()!=null?this.find(Client.class, client.getIdClient(), em):null;
if(obj==null)
persist(client, em);
else {
Client oldclient=(Client) obj;
oldclient.setAdresse(client.getAdresse());
oldclient.setPrenom(client.getPrenom());
oldclient.setNom(client.getNom());
oldclient.setTel1(client.getTel1());
oldclient.setTel2(client.getTel2());
oldclient.setDatNaiss(client.getDatNaiss());
oldclient.setEmail(client.getEmail());
oldclient.setFax(client.getFax());
oldclient.setLieuNaiss(client.getLieuNaiss());
oldclient.setNumPiece(client.getNumPiece());
persist(oldclient, em);
}
tx.commit();
em.close();
return true;
}
public static void main(String[] args) {
}
}