public List<User> getUserSearchResults(int topicId) { // TODO Auto-generated method stub List<User> userArr = new ArrayList<User>(); Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); Query query1 = session.createQuery("select userId from UserTopic where topicId = :topicId"); query1.setString("topicId", String.valueOf(topicId)); Query query2 = session.createQuery("from User where userId in (:userList)"); query2.setParameterList("userList", query1.list()); userArr = query2.list(); /*for(Topic topic : topicArr){ System.out.println("Topic Description----"+topic.getTopicDescription()); System.out.println("Topic Id----"+topic.getTopicId()); }*/ } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return userArr; }
@Override public List<Forum> getForumsOfaUser(int userId) { // TODO Auto-generated method stub List<Forum> forums = new ArrayList<Forum>(); Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); Query query = session.createQuery("from Subscription where userId = :userId"); query.setString("userId", String.valueOf(userId)); List<Subscription> userSubscribedGroups = query.list(); for (Subscription subsc : userSubscribedGroups) { query = session.createQuery("from Forum where forumId = :forumId"); query.setParameter("forumId", subsc.getForumId()); // add this to a list variable query.uniqueResult(); forums.add((Forum) query.uniqueResult()); } } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return forums; }
public User getUser(String username) { // TODO Auto-generated method stub System.out.println("DbHelper->getUser..."); Session session = sessionFactory.openSession(); Transaction tx = null; User user = new User(); try { tx = session.beginTransaction(); Query query = session.createQuery("from User where emailId = :emailId"); query.setString("emailId", username); user = (User) query.uniqueResult(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return user; }
public List<Forum> getSearchResults(int topicId) { List<Forum> forumArr = new ArrayList<Forum>(); Session session = sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); Query query = session.createQuery("from Forum where topicId = :topicId"); query.setString("topicId", String.valueOf(topicId)); forumArr = query.list(); /*for(Topic topic : topicArr){ System.out.println("Topic Description----"+topic.getTopicDescription()); System.out.println("Topic Id----"+topic.getTopicId()); }*/ } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } return forumArr; }