/** * {@inheritDoc} * * <p>此操作会清空 Cache 中 authorities 对应的 value,下次请求时装载。 * * @see #getAll() */ public void delete(Authority auth) throws JibuException { Connection conn = null; try { conn = ConnectionUtils.getConnection(); authDAO.delete(conn, auth); DbUtils.commitAndClose(conn); Cache cache = CacheUtils.getAuthCache(); cache.remove("authorities"); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); throw new JibuException(e.getMessage()); } }
private List<String> findRoleNamesByUsername(String username) { Connection conn = null; Cache cache = CacheUtils.getUserCache(); List<String> names = (List<String>) cache.get(username); if (null != names) return names; try { conn = ConnectionUtils.getConnection(); names = roleDAO.findByUsername(conn, username); cache.put(username, names); } catch (SQLException e) { logger.error(e.getMessage()); } finally { DbUtils.closeQuietly(conn); } return names; }
/** * {@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; }
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; }