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

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

          導航

          公告

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

          常用鏈接

          留言簿(5)

          隨筆分類(55)

          隨筆檔案(55)

          相冊

          Java

          其他技術

          生活

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          自強不息


          用心 - 珍惜時間,勇于創造
          主站蜘蛛池模板: 武功县| 延庆县| 海伦市| 怀远县| 喀喇| 二连浩特市| 阳曲县| 唐海县| 行唐县| 四平市| 维西| 沾益县| 荣昌县| 冷水江市| 万源市| 长汀县| 丹东市| 金昌市| 潢川县| 红桥区| 资中县| 读书| 长葛市| 福海县| 依安县| 双流县| 巍山| 静乐县| 开封市| 九寨沟县| 婺源县| 荔浦县| 若尔盖县| 阳城县| 弋阳县| 靖安县| 凤阳县| 鞍山市| 合作市| 陕西省| 丹棱县|