1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
public class ClientDAO {
//tant qu'à faire tu fais en sorte que ta classe soit un singleton
//si tu veux chercher, il y a plein d'article sur les singleton
private static ClientDAO instanceDAO = null ;
private ClientDAO(){
}
public static synchronized ClientDAO getInstance(){
if (instanceDAO == null){
instanceDAO = new ClientDAO();
}
return instanceDAO ;
}
public static List<Client> findAllClient(){
Query q = sessionDb.createQuery("from Client C");
return q.list();
}
public static Client findClientById(Integer idClient){
String hql="select C.nom,C.prenom,C.raison_sociale,C.nom_mededin,C.date_operation,C.date_accident,cc.objet from Client C,CommandeClient cc where C.id=cc.client.id and C.id="+id;
Query q = sessionDb.createQuery(hql);
return (Client)q.list().get(0);
}
} |