O/R映射框架的延迟加载技术实现大体上有这么4种(参看Martin Fowler的意见):
(
http://www.martinfowler.com/eaaCatalog/lazyLoad.html)
There are four main varieties of lazy load. Lazy Initialization uses a special marker value (usually null) to indicate a field isn't loaded. Every access to the field checks the field for the marker value and if unloaded, loads it. Virtual Proxy is an object with the same interface as the real object. The first time one of its methods are called it loads the real the object and then delegates. Value Holder is an object with a getValue method. Clients call getValue to get the real object, the first call triggers the load. A ghost is the real object without any data. The first time you call a method the ghost loads the full data into its fields.
通过阅读源代码,发现iBATIS中的延迟加载是用上述方式中的虚拟代理实现的.
在动态代理的实现上, iBATIS有Java动态代理和CGLIB两种实现方案,iBATIS把用CGLIB实现的方案称为Enhanced的方案,可见CGLIB的效率会比java的动态代理效率要高.
在iBATIS首先判断是否定义了延迟加载,如果定义了,则利用Lazy的Loader来提取数据(返回一个Proxy).如没有执行对这个的任何操作,或者只是不再使用(finalize),则不做处理,否者就加载真正的对象.
可以通过阅读类
com.ibatis.sqlmap.engine.mapping.result.loader.LazyResultLoader
的源码获取更多的细节.
分享到:
相关推荐
实现ibatis手动控制加载sqlmap文件,终于不用重启应用了
ibatis实现原理解析
ibatis实现分页技术,其中的分页都已经封装好了,大家需要的话可以下载下来看下
Struts2 Spring iBATIS 架构 实现 Struts2 Spring iBATIS 架构 实现 Struts2 Spring iBATIS 架构 实现 Struts2 Spring iBATIS 架构 实现
自己写的ibatis 框架,跟ibatis功能差不多
ibatis技术总结,ibatis技术总结ibatis技术总结
ibatis学习 ibatis总结 ibatis ibatis ibatis
Ibatis和Spring整合例子,实现增删改查功能.
基于iBATIS的数据库访问技术及其web应用,封小钰,王飞,介绍了通过IBATIS访问数据库的方法,建立了通过IBATIS完成对数据库访问配置、实现数据库访问控制的系统。在数据持久层使用IBATIS作为Jav
将代码更新到src目录下;即可!对应的ibatis的版本是2.3.4;建议使用同版本测试。 如有改动,请sqlmap的xml文件格式化后保存,这样以便组件发现修改时间不同而重新加载。
iBatis技术框架介绍。ibatis2.x教程。
ibatis实现CRUD操作,它比学好hibernate更简单
ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料
iBATIS SQLMap
ibatis官方中文文档.rar包含ibatis官方中文文档及使用说明
通过修改ibatis源码实现sql分页。由于ibatis默认分页是全部查出,然后再从中取出相应的数据实现分页,效率底。所以需要扩展
学会ibatis 中sqlMap配置
Spring+Ibatis技术:很好的架构文档
实现ibatis对数据的连接,增查删改。.xml文件对sql语句的映射。基本知识基本全部覆盖
ibatis 拼接字符串