public int updateKlinikaId(Korisnici korisnik, int klinikaId) { int updated = 0; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { session.beginTransaction(); List<Korisnici> lista = (List<Korisnici>) session .createQuery("from Korisnici k where k.id = :id") .setParameter("id", korisnik.getId()); if (lista.size() > 0) { updated = session .createQuery("update Korisnici k set k.klinika_id = :klinid where k.id = :id") .setParameter("klinid", klinikaId) .setParameter("id", korisnik.getId()) .executeUpdate(); } } catch (Exception e) { System.err.println(e); } finally { session.close(); } return updated; }
public int updatePassword(Korisnici korisnik, String oldPass, String newPass) { int updated = 0; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { session.beginTransaction(); // provera radi sigurnosti... List<Korisnici> lista = (List<Korisnici>) session .createQuery( "from Korisnici k where k.jmbg = :jmbg and k.lozinka = :pass and prihvacen = 1") .setParameter("jmbg", korisnik.getJmbg()) .setParameter("pass", oldPass) .list(); if (lista.size() > 0) { session.close(); session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); korisnik.setLozinka(newPass); session.update(korisnik); session.getTransaction().commit(); updated = 1; } } catch (Exception e) { System.err.println(e); } finally { if (session.isOpen()) session.close(); } return updated; }
public int prihvatiKorisnika(Korisnici korisnik) { int updated = 0; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { session.beginTransaction(); korisnik.setPrihvacen(1); session.update(korisnik); session.getTransaction().commit(); updated = 1; } catch (Exception e) { System.err.println(e); updated = -1; } finally { if (session.isOpen()) session.close(); } return updated; }