Package sn.unitech.stock.dao

Source Code of sn.unitech.stock.dao.ClientDao

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) {
  }

 
}
TOP

Related Classes of sn.unitech.stock.dao.ClientDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.