要集成Dynamic cache 跟 ibatis的cache 主要就是要写CacheControllerimport java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibatis.sqlmap.engine.cache.CacheController;
import com.ibatis.sqlmap.engine.cache.CacheModel;
import com.ibm.websphere.cache.DistributedMap;
public class DynamicCacheController implements CacheController {
//对应dynamic cache的 jndi
private String cacheInstance = "cacheInstance";
/**
* @return the cacheManager
*/
public DistributedMap getCacheManager() {
return cacheManager;
}
/**
* @param cacheManager the cacheManager to set
*/
public void setCacheManager(DistributedMap cacheManager) {
this.cacheManager = cacheManager;
}
/** The DynamicCache CacheManager. */
private DistributedMap cacheManager;
/**
* Flush a cache model.
* @param cacheModel - the model to flush.
*/
public void flush(CacheModel cacheModel) {
cacheManager.clear();
}
/**
* Get an object from a cache model.
* @param cacheModel - the model.
* @param key - the key to the object.
* @return the object if in the cache, or null(?).
*/
public Object getObject(CacheModel cacheModel, Object key) {
Object result = cacheManager.get(key);
return result;
}
/**
* Put an object into a cache model.
* @param cacheModel - the model to add the object to.
* @param key - the key to the object.
* @param object - the object to add.
*/
public void putObject(CacheModel cacheModel, Object key, Object object) {
cacheManager.put(key,object);
}
/**
* Remove an object from a cache model.
* @param cacheModel - the model to remove the object from.
* @param key - the key to the object.
* @return the removed object(?).
*/
public Object removeObject(CacheModel cacheModel, Object key) {
Object result = this.getObject(cacheModel, key);
cacheManager.remove(key);
return result;
}
/**
* Configure a cache controller. Initialize the DynamicCache Manager as a singleton.
* @param props - the properties object continaing configuration information.
*/
public void setProperties(Properties props) {
try {
cacheManager = (DistributedMap) new InitialContext().lookup(cacheInstance);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Shut down the DynamicCache CacheManager.
*/
public void finalize() {
if (cacheManager != null) {
cacheManager.clear();
}
}
}
使用的配置文件如下配置你自己的CacheModel 指定type是我们自己写的cacheController,这里就是DynamicCacheController,在配置cachemodel时有两点注意的地方它有两个属性,一个是readonly,表示这个cacheInstance是不是只读的,还有一个属性是serialize,如果设为false 表示这是一个session level的cache,反之true表示这个一个application level的cache,每次都会返回一个instance,但是此时所有存入cache的东西都必须是serializable的,这就带来了一个问题了,如果设为true的话,我们就不能用lazy load了,因为lazy load的 proxy是不能序列化的。 所以一般在使用时要权衡一下利弊。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="TestCache">
<!-- Alias for the classes -->
<typeAlias alias="tableColumnCache" type="com.******.TableTestDTO" />
<typeAlias alias="MapCacheController" type="com.**********.DynamicCacheTestController"/>
<!-- readOnly表示这个Cache Instance是只读的,serialize=true表示这个cache 是application level的,负责只是session level的-->
<cacheModel id="tableTestCacheModel" type="MapCacheController" readOnly="true" serialize="false">
<flushInterval hours="24"/>
<property name="CacheSize" value="100"/>
</cacheModel>
<!-- cacheModel="product-cache" resultMap="productCache" -->
<statement id="loadTableColumnCache" cacheModel="tableTestCacheModel" resultMap="listTableColumnCache">
</statement>
</sqlMap>
分享到:
相关推荐
WebSphere在Myeclipse中的整合,Myeclipse下增加WebSphere的支持
NULL 博文链接:https://baomw.iteye.com/blog/831945
WebSphere与Weblogic集成产品比较.pdf
* 灵活的集成方式:WebSphere MQ 支持多种集成方式,包括点对点式、发布/订阅式等,满足企业的不同集成需求。 * 强大的安全机制:WebSphere MQ 具有强大的安全机制,包括身份验证、授权和加密等,确保消息传递的安全...
webSphere指南webSphere指南webSphere指南webSphere指南webSphere指南
IBM Websphere与IBM HttpServer的集成
Lotus Domino与IBM WebSphere的集成开发
WebSphere Application Server v7.0的价值-服务集成总线 WebSphere Application Server v7.0:IBM® Rational® Application Developer V7.5 WebSphere Application Server v7.0 附加值增强 WebSphere ...
超详细的websphere was 安装说明文档适用8.5,内附参数设置:aix、jvm、was等参数设置
websphere设计
WebSphere
集成 WebSphere Portal 和 Tivoli Access Manager 之后,在安全问题之外的很多价值。决定是否集成 Tivoli Access Manager 到 WebSphere Portal 部署中不应当只看成 Access Manager 让 WebSphere Portal 更安全,也不...
WebSphere Application Server v7.0的价值-服务集成总线简介以及使用情况。
was相关资料: Websphere安装步骤 websphere安装后配置说明 Websphere实用手册 WebSphere+v6.1配置文档
截图说明 步骤很详细 (仅仅是集成,没有代码同步)
火龙果软件工程技术中心 本文内容包括:简介为什么进行软件...扩展了Eclipse的价值与WebSphereStudio和Eclipse无缝集成的世界级SCM从WebSphereStudio和Eclipse访问IBMRationalClearCase从WebSphereStudio和Eclipse访问I
WebSphere Application Server v7.0的价值-服务集成总线 WebSphere Application Server v7.0:IBM® Rational® Application Developer V7.5 WebSphere Application Server v7.0 附加值增强 WebSphere ...
websphere commerce的使用即websphere commerce图解.在网上扒了半天才找到的稀品啊!IBM创建商品店铺(websphere commerce).pdf 一些其他的相关资料: ...
IBM Websphere MQ是IBM公司开发的一款消息队列中间件,旨在提供一个可靠的异步通信机制,实现不同应用程序之间的数据交换和集成。下面是该教程的知识点总结: 中间件的概念和优点 中间件是一种特殊的软件系统,它...
第一部分 Websphere MQ原理和体系结构 11 第一章Websphere MQ原理 11 目标 11 1.1中间件 11 1.1.1中间件的优点 11 1.1.2中间件的分类 12 1.2三种通信技术的比较 13 1.3 WebSphere MQ的原理 15 1.4 WebSphere MQ的...