缓存查询列表并提供更新处理方案
来源:互联网 发布:人工智能龙头企业 编辑:程序博客网 时间:2024/06/14 16:39
package cn.com.iboyaa.ifservice.client.cache.util;import java.io.Serializable;import java.util.List;import java.util.Map;import javax.annotation.PostConstruct;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.expression.ExpressionParser;import org.springframework.expression.spel.standard.SpelExpressionParser;import org.springframework.stereotype.Component;import cn.com.iboyaa.ifservice.client.cache.ListCache;import cn.com.iboyaa.ifservice.client.entity.IdEntity;import cn.com.iboyaa.ifservice.client.util.ListUtil;import com.google.common.collect.Lists;import com.google.common.collect.Maps;/** * 实体类的list。用于缓存list型的查询结果 * * @author 盼庚 * @Package cn.com.iboyaa.ifservice.client.memcached.util.maps.EntityList.java * @version 1.0 * @since Service 1.0 * @date 2014年1月12日 下午6:25:04 * @control *//** * * @author 盼庚 * @Package cn.com.iboyaa.ifservice.client.cache.util.EntityList.java * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:36:22 * @control */@Componentpublic class EntityList<T extends IdEntity> implements Serializable { private static final long serialVersionUID = 7790662020703118917L; private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(EntityList.class); /** spel表达式解析器 */ private static ExpressionParser expParser = new SpelExpressionParser(); /** 唯一entitylist缓存,用来调用listcache */ private static EntityList<IdEntity> cached; /** 记录id对应的list中未知 */ private Map<Long, T> map = Maps.newHashMap(); /** 对象列表 */ private List<T> list = Lists.newArrayList(); /** 缓存处理对象 */ @Autowired private ListCache listCache; /** * 处理spel表达式 * * @param key * @return spel表达式处理结果字符串 * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:33:07 */ private String parseSpel(String key) { return expParser.parseExpression(key).getValue(String.class); } /** * 启动参数,启动时注入静态cached。实现listcache的缓存注入 * * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:33:32 */ @SuppressWarnings("unchecked") @PostConstruct public void init() { cached = (EntityList<IdEntity>) this; cached.listCache = this.listCache; } /** * 创建EntityList对象。并将列表对象缓存 * * @param list * @param key * key+id生成缓存id */ public EntityList(List<T> list, String key) { this.list = ListUtil.NotNullList(list); for (T t : list) { cached.listCache.cacheEntity(t, parseSpel(key + t.getId())); this.map.put(t.getId(), t); } } /** * 创建entitylist,不缓存类表对象 * * @param list */ public EntityList(List<T> list) { this.list = ListUtil.NotNullList(list); for (T t : list) { this.map.put(t.getId(), t); } } /** * 创建空的entitylist */ public EntityList() { } /** * 通过id获取list中的对象 * * @param id * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:36:43 */ public T getEntity(Long id) { return map.get(id); } /** * 检查id是否存在 * * @param id * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:37:02 */ public Boolean check(Long id) { if (map.get(id) == null) { logger.warn("此id" + id + "在列表中不存在"); return false; } return true; } /** * 注入对象 * * @param id * @param entity * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:37:25 */ public Boolean setEntity(T entity) { if (!check(entity.getId())) { list.add(entity); } map.put(entity.getId(), entity); return true; } /** * 获取map, * * @return map中记录id与在list中的未知 * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:38:13 */ public Map<Long, T> getMap() { return map; } /** * 设置map * * @param map * map中记录id与在list中的未知 * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:39:04 */ public void setMap(Map<Long, T> map) { this.map = map; } /** * 获取对象列表 * * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:39:22 */ public List<T> getList() { return list; } /** * 注入对象列表 * * @param list * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:39:33 */ public void setList(List<T> list) { this.list = list; } /** * 添加或更新对象。并根据key更新entitylist缓存 * * @param entity * @param key * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:40:01 */ public EntityList<T> addEntity(T entity, String key) { addEntity(entity); return cached.listCache.upDate(this, parseSpel(key)); } /** * 添加或更新对象。 * * @param entity * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:42:06 */ public EntityList<T> addEntity(T entity) { setEntity(entity); return this; } /** * 初始化entitylist,并更新缓存 * * @param key * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:42:28 */ public EntityList<T> removeAll(String key) { this.list = Lists.newArrayList(); this.map = Maps.newHashMap(); return cached.listCache.upDate(this, parseSpel(key)); } /** * 从entitylist中去除对象,并更具key更新entitylist缓存 * * @param t * @param key * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:42:49 */ public EntityList<T> remove(T t, String key) { list.remove(map.get(t.getId())); map.remove(t.getId()); return cached.listCache.upDate(this, parseSpel(key)); } /** * 根据key更新entitylist * * @param key * @return * @version 1.0 * @since Service 1.0 * @date 2014年3月19日 上午9:43:25 */ public EntityList<T> updateCache(String key) { return cached.listCache.upDate(this, parseSpel(key)); }}
0 0
- 缓存查询列表并提供更新处理方案
- js缓存更新方案
- js缓存更新方案
- 谷歌发布第二代TPU,并提供了免费试用方案
- 导出List列表中的数据到Excel文件,并提供下载
- 将附件以table列表的形式展示,并提供下载功能
- jar下载地址大全,老紫竹将持续更新并提供本地下载
- 连接MySQL并提供查询,删除,修改和添加的java程序
- 从数据库读取文件并提供下载
- 动态生成.txt文件并提供下载
- 使用fileupload上传文件,并提供下载
- java输出EXCEL并提供下载 源码
- php使用 ZipArchive 压缩文件并提供下载
- 爬取携程网机票价格并提供搜索功能
- CentOS6安装dovecot并提供sasl功能
- hibernate 更新后查询缓存问题。
- window下DNS查询以及更新缓存
- ADO.net将数据导出到Excel并提供下载
- 2014-3-21
- QQ旋风4.4,高清视频无须等待
- APP按A~Z排序,并且过滤显示(有图有真相~~~)
- Apache体系
- 传国宝玺 第四部 港岛邪云 第五十八章 启尸招魂
- 缓存查询列表并提供更新处理方案
- iOS开发基础控件--UIButton
- __bridge,__bridge_retained和__bridge_transfer三个转换关键字 - iOS开发
- Zip压缩
- java中synchronized用法
- Jtable的应用:model,添加行,删除行
- 固定cell.imageView.image的大小
- implicit
- Android 10位颜色值,8位颜色值和6位颜色值的区别