posts - 31,  comments - 31,  trackbacks - 0

          程序功能:
          使用ibatis+spring將oracle數據庫中的tfile表中的數據抽取到db2數據庫的tfile表,這兩個表的結構相同。

          測試環境:
          celeron M 1.4/512M/mysql 5.0數據庫
          代碼:

          public static void main(String[] args) {
                  
          // TODO Auto-generated method stub
                  ClassPathResource resource = new ClassPathResource(
                          
          "applicationContext.xml");
                  BeanFactory factory 
          = new XmlBeanFactory(resource);
                  TFileDAO tFileDao 
          = (TFileDAO) factory.getBean("tfile");

                  TFileDAO test2FileDao 
          = (TFileDAO) factory.getBean("test2tfile");
                  
          //獲取全部數據
                  List list = tFileDao.getAll();
                  
          //開啟事務
                  DataSourceTransactionManager txm = (DataSourceTransactionManager) factory
                          .getBean(
          "test2transactionManager");
                  DefaultTransactionDefinition def 
          = new DefaultTransactionDefinition();
                  def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
                  TransactionStatus status 
          = txm.getTransaction(def);
                  
          try {
                      test2FileDao.getSqlMapClient().startBatch();
                      
          for (int i = 0, count = list.size(); i < count; i++{
                      
          //插入數據
                          test2FileDao.insert((TFile) list.get(i));
                      }

                      test2FileDao.getSqlMapClient().executeBatch();// 這兩句有問題,請見Spring+ibatis心得2!
                  }
           catch (Exception e) {
                      txm.rollback(status);
                      System.out.println(e);
                  }

                  txm.commit(status);
                  System.out.println(list.size());
              }
          1、保證使用長事務,不要在每個插入都事務提交,這樣性能可以有很大幅度的提升
          2、使用 test2FileDao.getSqlMapClient().startBatch();
                        test2FileDao.getSqlMapClient().executeBatch();
                       可以發起jdbc對批量數據插入的優化與自動代碼壓縮功能。

                結語:這次使用ibatis在同樣的硬件、數據庫、數據條數的環境下測試,在不起用batch,所有數據庫,數據池特性均使用默認設置情況下使用19秒,并且使用一次性將數據讀入內存的方式,效果優于hibernate,所以真信優化后的程序應該比hibernate效率更高。但是從程序編寫方面來講,hibernate省去了過多的代碼,可以讓程序員更輕松些。
          posted on 2007-04-26 19:54 小平 閱讀(3204) 評論(1)  編輯  收藏


          FeedBack:
          # re: ibatis +spring批量操作心得
          2009-12-17 21:47 | 團派家園
          3.0出來了嗎。  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          framework

          j2me

          java

          linux

          web

          其他

          友情鏈接

          素材

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 台南市| 邳州市| 西平县| 大田县| 犍为县| 科技| 含山县| 梨树县| 石首市| 岱山县| 富顺县| 新建县| 伊春市| 西宁市| 浦县| 兴安盟| 芦山县| 桓台县| 沿河| 应城市| 承德县| 南丹县| 彭水| 兰西县| 汉寿县| 延边| 津南区| 白城市| 沂源县| 安仁县| 惠水县| 新和县| 屏东县| 疏勒县| 天峻县| 县级市| 广元市| 商水县| 崇仁县| 望奎县| 兰坪|