Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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;
  }