Ejemplo n.º 1
0
  /**
   * {@inheritDoc}
   *
   * <p>如果 Cache 中的 authorities 对应的 value 为空,从 DAO 得到最新的 value 并装入 Cache。
   */
  public List<Authority> getAll() {
    Connection conn = null;
    List<Authority> auths = null;

    Cache cache = CacheUtils.getAuthCache();
    auths = (List<Authority>) cache.get("authorities");
    if (null != auths) return auths;
    try {
      conn = ConnectionUtils.getConnection();
      auths = authDAO.getAll(conn);
      cache.put("authorities", auths);
    } catch (SQLException e) {
      logger.error(e.getMessage());
    } finally {
      DbUtils.closeQuietly(conn);
    }
    return auths;
  }