public UsersDataSet getUser(long id) throws DBException { try { Session session = sessionFactory.openSession(); UsersDao dao = new UsersDao(session); UsersDataSet dataSet = dao.get(id); session.close(); return dataSet; } catch (HibernateException e) { throw new DBException(e); } }
public long addUser(String login, String password) throws DBException { try { Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); UsersDao dao = new UsersDao(session); long id = dao.insertUser(login, password); transaction.commit(); session.close(); return id; } catch (HibernateException e) { throw new DBException(e); } }
public UsersDataSet getUserByName(String name) throws DBException { try { Session session = sessionFactory.openSession(); UsersDao dao = new UsersDao(session); long id = dao.getUserId(name); UsersDataSet dataSet = dao.get(id); if (id == -2) { return null; } session.close(); return dataSet; } catch (HibernateException e) { throw new DBException(e); } }