当前位置:七道奇文章资讯编程技术Java编程
日期:2011-03-22 16:13:00  来源:本站整理

iBatis操纵OSCache作缓存与java.io.FileNotFoundException非常[Java编程]

赞助商链接



  本文“iBatis操纵OSCache作缓存与java.io.FileNotFoundException非常[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

这种非常只会发生在 Windows 平台上,可以说是 iBatis 的一个 Bug,大约 iBatis 的开辟测试人员都对比热衷于 Unix 族系的平台,而忽视了 Windows 下的兼容性测试.

呈现 FileNotFoundException 非常的情形是这样的:Windows7 + iBatis2.3.0.677 + OSCache2.4.1.

iBatis 中配置利用 OSCache 缓存,在映射文件 Product.xml 中有以下声明片断:

1.<cacheModel type="OSCACHE" id="productCache">
2.<flushOnExecute statement="Product.insert"/>
3.<flushOnExecute statement="Product.delete"/>
4.</cacheModel>
5.
6.<select id="getById" cacheModel="productCache" parameterClass="int" resultClass="Product">
7.select id, name,description as desc1  from test_product where id = #value#
8.</select>

OSCache 的 oscache.properties 中指明用磁盘文件缓存数据,注意以下几个配置:

01.#不缓存到内存
02.cache.memory=false
03.
04.#缓存长期化实现类,磁盘长期化监听器
05.cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
06.
07.#缓存磁盘途径,今后注意察看该目录生成的内容
08.cache.path=e:\\OSCache\\cache
09.
10.#挑选一种缓存算法,还可选 FIFOCache、UnlimitedCache
11.cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache

Java 测试代码:

1.public static void main(String[] args) throws Exception{
2.Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
3.SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
4.System.out.println(sqlMapClient.queryForObject("Product.getById",5));
5.
6.//背面一样的查询将不再查询数据库,而是直接利用前面履行放在缓存中的内容
7.System.out.println(sqlMapClient.queryForObject("Product.getById",5));
8.}

履行上面那段代码,你将会得到非常:

2009-8-19 10:45:52 com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache persistStore
严重: [oscache] Exception persisting 1991729862|2162672802|5|Product.getById|62996507|         select id, name,description as desc1  from test_product where id = ?     |executeQueryForObject
com.opensymphony.oscache.base.persistence.CachePersistenceException: Unable to write 'e:\OSCache\cache\application\1991729862|2162672802|5|Product_31getById|62996507|_49_50_51_52_53_54_55_56_57select_64id,_68name,description_85as_88desc1_94_95from_100test_105product_113where_119id_122=_124_125_126_127_128_129_130|executeQueryForObject.cache' in the cache.Exception: java.io.FileNotFoundException, Message: e:\OSCache\cache\application\1991729862|2162672802|5|Product_31getById|62996507|_49_50_51_52_53_54_55_56_57select_64id,_68name,description_85as_88desc1_94_95from_100test_105product_113where_119id_122=_124_125_126_127_128_129_130|executeQueryForObject.cache (文件名、目录名或卷标语法不精确.)
at com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener.store(AbstractDiskPersistenceListener.java:376)
at com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener.store(AbstractDiskPersistenceListener.java:238)
at com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.persistStore(AbstractConcurrentReadCache.java:1113)
at com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.put(AbstractConcurrentReadCache.java:1623)
at com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.put(AbstractConcurrentReadCache.java:864)
at com.opensymphony.oscache.base.Cache.putInCache(Cache.java:637)
at com.opensymphony.oscache.base.Cache.putInCache(Cache.java:614)
at com.opensymphony.oscache.general.GeneralCacheAdministrator.putInCache(GeneralCacheAdministrator.java:270)
at com.ibatis.sqlmap.engine.cache.oscache.OSCacheController.putObject(OSCacheController.java:70)
at com.ibatis.sqlmap.engine.cache.CacheModel.putObject(CacheModel.java:318)
at com.ibatis.sqlmap.engine.mapping.statement.CachingStatement.executeQueryForObject(CachingStatement.java:80)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:83)
at com.unmi.TestClient.main(TestClient.java:25)


  以上是“iBatis操纵OSCache作缓存与java.io.FileNotFoundException非常[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • 介绍作为iBatis帮忙工具的iBator的操纵办法
  • 操纵iBatis的自动化代码生成工具Abator
  • iBatis操纵OSCache作缓存与java.io.FileNotFoundException非常
  • 用JSF+Spring+IBatis搭建一个简单框架
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .