예제 #1
0
 /**
  * {@inheritDoc}
  *
  * <p>此操作会清空 Cache 中 authorities 对应的 value 和 key = auth.getValue() 的数据,下次请求时装载。
  *
  * @see #getAll()
  */
 public void update(Authority auth) throws JibuException {
   Connection conn = null;
   try {
     conn = ConnectionUtils.getConnection();
     Authority old = authDAO.get(conn, auth.getId());
     authDAO.update(conn, auth);
     DbUtils.commitAndClose(conn);
     Cache cache = CacheUtils.getAuthCache();
     cache.remove("authorities");
     cache.remove(old.getValue());
   } catch (SQLException e) {
     DbUtils.rollbackAndCloseQuietly(conn);
     throw new JibuException(e.getMessage());
   }
 }
예제 #2
0
 public Authority get(String value) {
   Connection conn = null;
   Authority auth = null;
   try {
     conn = ConnectionUtils.getConnection();
     auth = authDAO.get(conn, value);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auth;
 }
예제 #3
0
 public List<Authority> find(Role role) {
   Connection conn = null;
   List<Authority> auths = null;
   try {
     conn = ConnectionUtils.getConnection();
     auths = authDAO.find(conn, role);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auths;
 }
예제 #4
0
 public List<Authority> find(Authority auth) {
   if (null == auth) return this.getAll();
   Connection conn = null;
   List<Authority> auths = null;
   try {
     conn = ConnectionUtils.getConnection();
     auths = authDAO.find(conn, auth);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auths;
 }
예제 #5
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;
  }
예제 #6
0
 private List<String> findRoleNamesByValue(String value) {
   Connection conn = null;
   Cache cache = CacheUtils.getAuthCache();
   List<String> names = (List<String>) cache.get(value);
   if (null != names) return names;
   try {
     conn = ConnectionUtils.getConnection();
     Authority auth = authDAO.get(conn, value);
     if (null != auth) {
       names = roleDAO.findByAuthid(conn, auth.getId());
       cache.put(value, names);
     }
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return names;
 }