Пример #1
0
 public List<Movie> findAll() {
   List<Movie> movieList = (List<Movie>) EhcacheUtil.get("movieList");
   if (movieList == null) {
     String sql = "SELECT  * FROM movie";
     movieList = DbHelp.query(sql, new BeanListHandler<>(Movie.class));
     EhcacheUtil.set("movieList", movieList);
   }
   return movieList;
 }
Пример #2
0
  public Movie findById(Integer id) {

    Movie movie = (Movie) EhcacheUtil.get("movie:" + id);
    if (movie == null) {
      String sql = "select * from movie where id=?";

      movie = DbHelp.query(sql, new BeanHandler<>(Movie.class), id);
      EhcacheUtil.set("movie:" + id, movie);

    } else {
      logger.debug("load movie from cache");
    }
    return movie;
  }
Пример #3
0
 public void save(Movie movie) {
   String sql =
       "INSERT INTO movie(id, title, rate, releaseyear, sendtime, daoyan, jianjie) VALUES (?,?,?,?,?,?,?)";
   DbHelp.update(
       sql,
       movie.getId(),
       movie.getTitle(),
       movie.getRate(),
       movie.getReleaseyear(),
       movie.getSendtime(),
       movie.getDaoyan(),
       movie.getJianjie());
   EhcacheUtil.remove("movieList");
 }