public List<String> getclientinfo(String token) { Session session = createSessionFactory().openSession(); String email; String password; List<Clients> list = null; List<String> info = null; Transaction tx = null; try { tx = session.beginTransaction(); list = (List<Clients>) session.createQuery("FROM Clients").list(); for (Clients c : list) { if (c.getToken().equalsIgnoreCase(token)) { email = c.getEmail(); password = c.getPassword(); info.add(email); info.add(password); } } } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } return info; }
public boolean exist(String email) { Session session = createSessionFactory().openSession(); List<Clients> list = null; Transaction tx = null; try { tx = session.beginTransaction(); list = (List<Clients>) session.createQuery("FROM Clients").list(); for (Clients c : list) { if (c.getEmail().equalsIgnoreCase(email)) return true; } } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } return false; }
/** * an method for registering a client entity in the DB * * @param client the client to be registered in the DB * @return the id of the client in DB */ public boolean signup(Clients client) { Session session = createSessionFactory().openSession(); int id = 0; Transaction tx = null; if (exist(client.getEmail())) { return false; } else { try { tx = session.beginTransaction(); id = (Integer) session.save(client); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } } return true; }
/** * method returning the client id based on his username and password * * @param username of the client * @param pass of the client * @return the id of the client */ public int getClientId(String email, String pass) { Session session = createSessionFactory().openSession(); int id = 0; List<Clients> list = null; Transaction tx = null; try { tx = session.beginTransaction(); list = (List<Clients>) session.createQuery("FROM Clients").list(); for (Clients c : list) { if (c.getEmail().equalsIgnoreCase(email) && c.getPassword().equals(pass)) { id = c.getId(); } } } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } return id; }