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; }
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; }
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"); }