狂奔 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 楊一 閱讀(2061) 評論(0)  編輯  收藏 所屬分類: Java EE

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

          導航

          公告

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

          常用鏈接

          留言簿(5)

          隨筆分類(55)

          隨筆檔案(55)

          相冊

          Java

          其他技術

          生活

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          自強不息


          用心 - 珍惜時間,勇于創造
          主站蜘蛛池模板: 东兰县| 临城县| 上虞市| 正定县| 旬阳县| 邵东县| 珲春市| 西林县| 山西省| 诸城市| 荥经县| 灵石县| 永安市| 松原市| 龙海市| 平邑县| 屏南县| 高淳县| 阜新| 巴楚县| 昭平县| 建瓯市| 辽阳县| 琼结县| 卢氏县| 绥芬河市| 沧州市| 凤庆县| 弥渡县| 乐平市| 宽甸| 庐江县| 平昌县| 额济纳旗| 西平县| 陆丰市| 嘉义市| 石景山区| 贞丰县| 云南省| 柳林县|