示例#1
0
  public List<Music> getMusicByCondition(Music m) {
    if (m == null) {
      return null;
    }
    Session session = TribusHibernateSessionFactory.currentSession();
    try {

      Criteria c = session.createCriteria(Music.class);
      if (m.getMusicId() != 0) {
        c.add(Restrictions.eq("musicId", m.getMusicId()));
      }
      if (m.getMusicAlias() != null) {
        c.add(Restrictions.eq("musicAlias", m.getMusicAlias()));
      }
      if (m.getMusicClassified() != null) {
        c.add(Restrictions.eq("musicClassified", m.getMusicClassified()));
      }
      if (m.getMusicCode() != null) {
        c.add(Restrictions.eq("musicCode", m.getMusicCode()));
      }

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

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
示例#2
0
  public List<MovieMarkVo> getMovieAndGradeByUserId(int id) {
    String sql =
        "select m.movieId,m.movieNameOriginal,mm.movieGrade from book b, book_mark bb, user_account u, user_profile up"
            + " where b.bookId = bb.bookId and u.userId = bb.userId and up.userId = u.userId"
            + " and u.userId = ? ";

    List<MovieMarkVo> l_movie_vo = new ArrayList<MovieMarkVo>();

    Session session = TribusHibernateSessionFactory.currentSession();
    List l = session.createSQLQuery(sql).setInteger(0, id).list();
    if (l != null) {
      Iterator itr = l.iterator();
      while (itr.hasNext()) {

        Object[] obj = (Object[]) itr.next();
        MovieMarkVo bmv = new MovieMarkVo();

        bmv.setMovieId(Integer.parseInt(obj[0].toString()));

        bmv.setMovieNameAlias(obj[1].toString());

        bmv.setMovieGrade(Integer.parseInt(obj[2].toString()));

        l_movie_vo.add(bmv);
      }
    }
    return l_movie_vo;
  }
示例#3
0
  public List<MusicMarkVo> getMusicAndGradeByUserId(int id) {
    String sql =
        "select m.musicId,m.musicName,mm.musicGrade from "
            + " music m, music_mark mm, user_account u, user_profile up"
            + " where m.musicId = mm.musicId and u.userId = mm.userId and up.userId = u.userId"
            + " and u.userId = ? ";

    List<MusicMarkVo> l_music_vo = new ArrayList<MusicMarkVo>();

    Session session = TribusHibernateSessionFactory.currentSession();
    List<Music> l = session.createSQLQuery(sql).setInteger(0, id).list();
    if (l != null) {
      Iterator itr = l.iterator();
      while (itr.hasNext()) {

        Object[] obj = (Object[]) itr.next();
        MusicMarkVo bmv = new MusicMarkVo();

        // bmv.setMovieId(Integer.parseInt(obj[0].toString()));
        bmv.setMusicId(Integer.parseInt(obj[0].toString()));

        bmv.setMusicName(obj[1].toString());
        // bmv.setMovieNameAlias(obj[1].toString());
        if (obj[2] == null) obj[2] = 1;
        bmv.setMusicGrade(Integer.parseInt(obj[2].toString()));
        // bmv.setMovieGrade(Integer.parseInt(obj[2].toString()));

        l_music_vo.add(bmv);
      }
    }
    return l_music_vo;
  }
示例#4
0
 @SuppressWarnings("unchecked")
 public List<Movie> searchMovieByName(String name) {
   // String sql = "from Movie where tags.tagName = :movieTag";
   // String[] tags = {"Drama"};
   /*String hql = "select m from Movie m "+
   "join m.tags t "+
   "where t.tagName in (:tags)";*/
   String hql = "from Movie";
   Session session = TribusHibernateSessionFactory.currentSession();
   List<Movie> allMovies = new ArrayList<Movie>();
   List<Movie> result = new ArrayList<Movie>();
   try {
     allMovies = session.createQuery(hql).list();
     Iterator<Movie> iterator = allMovies.iterator();
     while (iterator.hasNext()) {
       Movie m = iterator.next();
       if (m.getMovieNameOriginal().indexOf(name) != -1) {
         result.add(m);
       }
     }
     System.out.println("success");
   } catch (Exception e) {
     e.printStackTrace();
   }
   return result;
 }
示例#5
0
 /**
  * @param id
  * @return
  */
 public List<Movie> getMoviesWatchedByUserId(int id) {
   String sql =
       "select m.* from movie m, movie_mark mm, user_account u "
           + " where m.movieId = mm.movieId and u.userId = mm.userId "
           + " and mm.movieWatch = 1 and u.userId = ?";
   Session session = TribusHibernateSessionFactory.currentSession();
   return session.createSQLQuery(sql).addEntity(Movie.class).setInteger(0, id).list();
 }
示例#6
0
 public List<Music> getMusicsListenedByUserId(int id) {
   String sql =
       "select m.* from music m, music_mark mm, user_account u"
           + " where m.musicId = mm.musicId and u.userId = mm.userId"
           + " and mm.musicListen = 2 and u.userId = ?";
   Session session = TribusHibernateSessionFactory.currentSession();
   return session.createSQLQuery(sql).addEntity(Music.class).setInteger(0, id).list();
 }
 @SuppressWarnings("unchecked")
 public List<MusicComment> getMusicCommentByMusicId(int musicId) {
   Session session = TribusHibernateSessionFactory.currentSession();
   List<MusicComment> mcs = new ArrayList<MusicComment>();
   try {
     String hql = "from MusicComment as mc where mc.music.musicId=:musicId";
     mcs = session.createQuery(hql).setInteger("musicId", musicId).list();
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   return mcs;
 }
示例#8
0
 @SuppressWarnings("unchecked")
 public List<Music> searchMusicByName(String name) {
   String hql = "select m from Music m where lower(m.musicName) like :name";
   List<Music> musics = null;
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     musics = session.createQuery(hql).setString("name", "%" + name.toLowerCase() + "%").list();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return musics;
 }
示例#9
0
 @SuppressWarnings("unchecked")
 public List<Movie> getRecentHotMovie() {
   String sql = "from Movie where movieDate>='2010-10-21'";
   List<Movie> recentHotMovies = null;
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     recentHotMovies = session.createQuery(sql).list();
     System.out.println("success");
   } catch (Exception e) {
     e.printStackTrace();
   }
   return recentHotMovies;
 }
示例#10
0
 public List<Movie> getMoviesByUserId(int id) {
   String sql =
       "select m.* from movie m, movie_mark bm, user_account u where m.movieId = bm.movieId and"
           + " u.userId = bm.userId and bm.userId = ?";
   List<Movie> bs = new ArrayList<Movie>();
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     bs = session.createSQLQuery(sql).addEntity(Movie.class).setInteger(0, id).list();
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   return bs;
 }
 @SuppressWarnings("unchecked")
 public List<MusicComment> getAllMusicComment() {
   List<MusicComment> mcs = null;
   try {
     Session session = TribusHibernateSessionFactory.currentSession();
     String hql = "from MusicComment";
     mcs = session.createQuery(hql).list();
   } catch (Exception e) {
     // TODO: handle exception
     System.out.println(e.getMessage());
   }
   return mcs;
 }
示例#12
0
 @SuppressWarnings("unchecked")
 public Movie getMovieById(int movieId) {
   Movie m = null;
   try {
     Session session = TribusHibernateSessionFactory.currentSession();
     String sql = "from Movie where movieId=:movieId";
     List<Movie> ms = session.createQuery(sql).setInteger("movieId", movieId).list();
     m = ms.get(0);
   } catch (Exception e) {
     // TODO: handle exception
     System.out.println(e.getMessage());
   }
   return m;
 }
 @SuppressWarnings("unchecked")
 public MusicComment getMusicCommentByCommentId(int commentId) {
   MusicComment mc = null;
   Session session = TribusHibernateSessionFactory.currentSession();
   List<MusicComment> mcs = new ArrayList<MusicComment>();
   try {
     String hql = "from MusicComment where commentId=:commentId";
     mcs = session.createQuery(hql).setInteger("commentId", commentId).list();
     mc = mcs.get(0);
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   return mc;
 }
示例#14
0
 @SuppressWarnings("unchecked")
 public List<Music> getMusicsByUserId(int id) {
   String sql =
       "select m.* from music m, music_mark mm, user_account u where m.musicId = mm.musicId and"
           + " u.userId = mm.userId and mm.userId = ?";
   List<Music> bs = new ArrayList<Music>();
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     bs = session.createSQLQuery(sql).addEntity(Music.class).setInteger(0, id).list();
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   return bs;
 }
示例#15
0
 @SuppressWarnings("unchecked")
 public Music getMusicByName(String musicName) {
   Music m = null;
   try {
     Session session = TribusHibernateSessionFactory.currentSession();
     String sql = "from Music where musicName=:musicName";
     List<Music> ms = session.createQuery(sql).setString("musicName", musicName).list();
     m = ms.get(0);
     // System.out.println(b.getBookName());
   } catch (Exception e) {
     // TODO: handle exception
     System.out.println(e.getMessage());
   }
   return m;
 }
示例#16
0
  public int update(Movie m) {
    Session session = TribusHibernateSessionFactory.currentSession();
    Transaction tx = session.beginTransaction();
    try {
      session.update(m);
      // session.flush();
      tx.commit();
      return 1;

    } catch (Exception e) {
      e.printStackTrace();
      tx.rollback();
    }
    return -1;
  }
 @SuppressWarnings("unchecked")
 public List<MusicComment> getMusicCommentByUserId(int UserId, int num) {
   Session session = TribusHibernateSessionFactory.currentSession();
   List<MusicComment> mcs = new ArrayList<MusicComment>();
   try {
     String hql = "from MusicComment as mc where mc.user.userId=:UserId";
     mcs = session.createQuery(hql).setInteger("UserId", UserId).list();
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   if (mcs != null && mcs.size() > num) {
     return mcs.subList(0, num);
   }
   return mcs;
 }
  public int save(MusicComment mc) {
    Session session = TribusHibernateSessionFactory.currentSession();
    Transaction tx = session.beginTransaction();
    try {
      session.save(mc);
      session.flush();
      tx.commit();
      return 1;

    } catch (Exception e) {
      System.out.println(e.getMessage());
      tx.rollback();
    }
    return -1;
  }
示例#19
0
 @SuppressWarnings("unchecked")
 public List<Music> searchMusicByTag(String musicTag) {
   // String sql = "from Movie where tags.tagName = :movieTag";
   // String[] tags = {"Drama"};
   /*String hql = "select m from Movie m "+
   "join m.tags t "+
   "where t.tagName in (:tags)";*/
   String hql = "select m from Music m " + "join m.tags t " + "where t.tagName like :musicTag";
   List<Music> musics = null;
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     musics = session.createQuery(hql).setString("musicTag", "%" + musicTag + "%").list();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return musics;
 }
示例#20
0
 @SuppressWarnings("unchecked")
 public List<Music> getRecentHotMusic() {
   List<Music> hotMusics = new ArrayList<Music>();
   int id = 31;
   try {
     Session session = TribusHibernateSessionFactory.currentSession();
     for (int i = 0; i < 6; i++) {
       String sql = "from Music where musicId=" + id++;
       List<Music> ms = session.createQuery(sql).list();
       hotMusics.add(ms.get(0));
     }
     // System.out.println(b.getBookName());
   } catch (Exception e) {
     // TODO: handle exception
     System.out.println(e.getMessage());
   }
   return hotMusics;
 }
示例#21
0
  public int updateMovieNameOriginal(Movie movie) {
    System.out.println(movie.getMovieId() + "*" + movie.getMovieNameOriginal());
    int result = 0;
    Session session = TribusHibernateSessionFactory.currentSession();
    Transaction tx = session.beginTransaction();

    try {
      session.update(movie);
      // session.flush();
      tx.commit();
      result = 1;
    } catch (Exception e) {
      // TODO: handle exception
      System.out.println(e.getMessage());
      tx.rollback();
    }
    return result;
  }
示例#22
0
 @SuppressWarnings("unchecked")
 public List<Movie> getMovieByTag(String movieTag) {
   // String sql = "from Movie where tags.tagName = :movieTag";
   // String[] tags = {"Drama"};
   /*String hql = "select m from Movie m "+
   "join m.tags t "+
   "where t.tagName in (:tags)";*/
   String hql = "select m from Movie m " + "join m.tags t " + "where t.tagName = :movieTag";
   List<Movie> movies = null;
   Session session = TribusHibernateSessionFactory.currentSession();
   try {
     movies = session.createQuery(hql).setString("movieTag", movieTag).list();
     System.out.println("success");
   } catch (Exception e) {
     e.printStackTrace();
   }
   return movies;
 }
  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;
  }
示例#24
0
  public List<Movie> getMoviesByCondition(Movie m) {
    if (m == null) {
      return null;
    }
    Session session = TribusHibernateSessionFactory.currentSession();
    try {

      Criteria c = session.createCriteria(Movie.class);
      if (m.getMovieId() != 0) {
        c.add(Restrictions.eq("movieId", m.getMovieId()));
      }
      if (m.getMovieNameOriginal() != null) {
        c.add(Restrictions.eq("movieNameOriginal", m.getMovieNameOriginal()));
      }

      List<Movie> mo = c.list();
      return mo;

    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return null;
  }
  @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;
  }