@SuppressWarnings("unchecked") @Override public List<Color> getAllColors() { Session session = dbHandler.getSessionFactory().openSession(); String queryString = "from Color c order by c.price"; Query query = session.createQuery(queryString); List<Color> cols = (List<Color>) query.list(); session.close(); return cols; }
@SuppressWarnings("unchecked") @Override public List<CarModel> getAllCarModels() { Session session = dbHandler.getSessionFactory().openSession(); String queryString = "from CarModel m order by m.price"; Query query = session.createQuery(queryString); List<CarModel> models = (List<CarModel>) query.list(); session.close(); return models; }
@Override public Color getColor(String name) { Session session = dbHandler.getSessionFactory().openSession(); String queryString = "from Color where name = :name"; Query query = session.createQuery(queryString); query.setParameter("name", name); Color c = (Color) query.uniqueResult(); session.close(); return c; }
@Override public CarModel getCarModel(String name) { Session session = dbHandler.getSessionFactory().openSession(); String queryString = "from CarModel where name = :name"; Query query = session.createQuery(queryString); query.setParameter("name", name); CarModel m = (CarModel) query.uniqueResult(); session.close(); return m; }