Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None
  1. package com.andu033.restapi.basiccrud.DAO.Impl;
  2.  
  3. import com.andu033.restapi.basiccrud.DAO.spotDAO;
  4. import com.andu033.restapi.basiccrud.models.spot;
  5. import com.andu033.restapi.basiccrud.models.user;
  6. import org.hibernate.Criteria;
  7. import org.hibernate.HibernateException;
  8. import org.hibernate.SessionFactory;
  9. import org.hibernate.criterion.Restrictions;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Component;
  12. import org.springframework.stereotype.Controller;
  13.  
  14. import java.util.List;
  15. @Component
  16. public class HibernateSpotDAO implements spotDAO {
  17.  
  18. @Autowired
  19. public SessionFactory sessionFactory;
  20.  
  21. @Override
  22. public List<spot> getSpots(String country, double windProbability) {
  23. sessionFactory.getCurrentSession().beginTransaction();
  24. try {
  25.  
  26.  
  27. Criteria criteria = sessionFactory.getCurrentSession().createCriteria(spot.class);
  28. if (country != null)
  29. criteria.add(Restrictions.eq("country", country));
  30. criteria.add(Restrictions.eq("windProbability", windProbability));
  31.  
  32. List<spot> spotList = criteria.list();
  33.  
  34. if (spotList != null) {
  35. return spotList;
  36. }
  37.  
  38. sessionFactory.getCurrentSession().getTransaction().commit();
  39. } catch (HibernateException e) {
  40. e.printStackTrace();
  41. sessionFactory.getCurrentSession().getTransaction().rollback();
  42. }
  43. return null;
  44. }
  45.  
  46. @Override
  47. public void saveFavoriteSpot(int spotId) {
  48.  
  49. }
  50.  
  51. @Override
  52. public void deleteFavoriteSpot(int spotId) {
  53.  
  54. }
  55. }
Advertisement
RAW Paste Data Copied
Advertisement