狂奔 lion

          自強不息

          延遲加載技術及其在iBATIS中的實現

          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
          的源碼獲取更多的細節.

           @2008 楊一. 版權所有. 保留所有權利

          posted on 2007-12-09 19:17 楊一 閱讀(2058) 評論(0)  編輯  收藏 所屬分類: Java EE

          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          公告

          本人在blogjava上發表的文章及隨筆除特別聲明外均為原創或翻譯,作品受知識產權法保護并被授權遵從 知識分享協議:署名-非商業性使用-相同方式共享 歡迎轉載,請在轉載時注明作者姓名(楊一)及出處(www.aygfsteel.com/yangyi)
          /////////////////////////////////////////
          我的訪問者

          常用鏈接

          留言簿(5)

          隨筆分類(55)

          隨筆檔案(55)

          相冊

          Java

          其他技術

          生活

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          自強不息


          用心 - 珍惜時間,勇于創造
          主站蜘蛛池模板: 怀远县| 济宁市| 绵竹市| 山东省| 蕲春县| 达拉特旗| 九龙城区| 竹山县| 黎城县| 嘉祥县| 兴安县| 柳河县| 龙南县| 腾冲县| 大邑县| 庆阳市| 临泽县| 久治县| 石屏县| 扶绥县| 南城县| 上虞市| 南投市| 广河县| 潮州市| 南安市| 青河县| 金川县| 双辽市| 麻江县| 呼玛县| 平南县| 深泽县| 县级市| 怀柔区| 石城县| 新蔡县| 潮州市| 湘乡市| 清丰县| 奉节县|