Пример #1
0
  public List<MusicComment> getMusicCommentsByCondition(MusicComment m) {
    if (m == null) {
      return null;
    }
    Session session = TribusHibernateSessionFactory.currentSession();
    try {

      Criteria c = session.createCriteria(MusicComment.class);
      if (m.getCommentId() != 0) {
        c.add(Restrictions.eq("commentId", m.getCommentId()));
      }
      if (m.getCommentDate() != null) {
        c.add(Restrictions.eq("commentDate", m.getCommentDate()));
      }

      List<MusicComment> ms = c.list();
      return ms;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Пример #2
0
  @SuppressWarnings("unchecked")
  public List<MusicComment> getCommentByMusicIdAndRating(int musicId, int rating) {
    List<MusicComment> mcs = new ArrayList<MusicComment>();
    List<MusicComment> result = new ArrayList<MusicComment>();
    try {
      Session session = TribusHibernateSessionFactory.currentSession();
      String hql = "from MusicComment mc where mc.music.musicId=:musicId";
      mcs = session.createQuery(hql).setInteger("musicId", musicId).list();

      MusicMarkDao mmd = new MusicMarkDao();
      Iterator<MusicComment> iterator = mcs.iterator();
      while (iterator.hasNext()) {
        MusicComment mc = iterator.next();
        if (mmd.getGradeByMusicIdAndUseId(mc.getMusic().getMusicId(), mc.getUser().getUserId())
            == rating) {
          result.add(mc);
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
      System.out.println(e.getMessage());
    }
    return result;
  }