SHARE
TWEET

Untitled

a guest Mar 26th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.     public List<Beer> getDrank(int userId) {
  3.         List<Beer> beerList = new ArrayList<>();
  4.  
  5.         try (Session session = sessionFactory.openSession()) {
  6.             Transaction transaction = session.beginTransaction();
  7.             List list ;
  8.  
  9.             Query query = session.createSQLQuery(String.format("Select b.beer_id from user u" +
  10.                     "                 join beer_user_status_relationship st on u.user_id = st.user_id" +
  11.                     "                  join beer b on b.beer_id = st.beer_id" +
  12.                     "              join status s on s.status_id = st.beer_id_status" +
  13.                     "             where u.user_id = %d" +
  14.                     "           and  s.status_type in" +
  15.                     "           (select ss.status_type from Status ss where ss.status_id =1 )",userId));
  16.  
  17.             list =query.getResultList();
  18.             transaction.commit();
  19.  
  20.             for (Object o : list) {
  21.                Beer beer = session.get(Beer.class,(int) o);
  22.               beerList.add(beer);
  23.             }
  24.  
  25.         } catch (Exception e) {
  26.             e.printStackTrace();
  27.             throw e;
  28.         }
  29.  
  30.             return beerList;
  31.     }
  32.  
  33.     @Override
  34.     public List<Beer> getWantToDrink(int userId) {
  35.         List<Beer> beerList = new ArrayList<>();
  36.  
  37.         try (Session session = sessionFactory.openSession()) {
  38.             Transaction transaction = session.beginTransaction();
  39.             List list ;
  40.  
  41.             Query query = session.createSQLQuery(String.format("Select b.beer_id from user u" +
  42.                     "                 join beer_user_status_relationship st on u.user_id = st.user_id" +
  43.                     "                  join beer b on b.beer_id = st.beer_id" +
  44.                     "              join status s on s.status_id = st.beer_id_status" +
  45.                     "             where u.user_id = %d" +
  46.                     "           and  s.status_type in" +
  47.                     "           (select ss.status_type from Status ss where ss.status_id =2 )",userId));
  48.  
  49.             list =query.getResultList();
  50.             transaction.commit();
  51.  
  52.             for (Object o : list) {
  53.  
  54.                 Beer beer = session.get(Beer.class,(int) o);
  55.                 beerList.add(beer);
  56.  
  57.             }
  58.  
  59.         } catch (Exception e) {
  60.             e.printStackTrace();
  61.             throw e;
  62.         }
  63.  
  64.         return beerList;
  65.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top