偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iBATIS分頁(yè)源碼真相探討

開發(fā) 后端
iBATIS分頁(yè)源碼真相是什么?iBATIS是如何實(shí)現(xiàn)分頁(yè)的呢?那么本文將會(huì)給你介紹在實(shí)際工作中的一點(diǎn)體會(huì)。

iBATIS分頁(yè)源碼真相的探討,首先我們?cè)趇BATIS中有一個(gè)很吸引人的方法,queryForPaginatedList(java.lang.String id, int pageSize),可以返回 PaginatedList的對(duì)象,實(shí)現(xiàn)翻頁(yè),剛才測(cè)試了一下PaginatedList,在1-2w行數(shù)據(jù)的時(shí)候還可以工作,但是在一個(gè)30w行的表里翻頁(yè),一次select用了363.031second忍不住看了一下源,發(fā)現(xiàn)iBATIS的分頁(yè)依賴于數(shù)據(jù)庫(kù)的JDBC Driver.

調(diào)用次序如下SqlMapClientImpl.queryForPaginatedList->SqlMapSessionImpl.queryForPaginatedList

->SqlMapExecutorDelegate.queryForPaginatedList->GeneralStatement.executeQueryForList

->GeneralStatment.executeQueryWithCallback->GeneralStatment.executeQueryWithCallback

->SqlExecutor.executeQuery->SqlExecutor.handleMultipleResults()

iBATIS分頁(yè)處理的函數(shù)如下

  1. private void handleResults(RequestScope request, ResultSet rs, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {  
  2.     try {  
  3.       request.setResultSet(rs);  
  4.       ResultMap resultMap = request.getResultMap();  
  5.       if (resultMap != null) {  
  6.         // Skip Results  
  7.         if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) {  
  8.           if (skipResults > 0) {   
  9.  
  10.  
  11.             rs.absolute(skipResults);  
  12.           }  
  13.         } else {  
  14.           for (int i = 0; i < skipResults; i++) {  
  15.             if (!rs.next()) {  
  16.               return;  
  17.             }  
  18.           }  
  19.         }   
  20.  
  21.  
  22.         // Get Results  
  23.         int resultsFetched = 0;  
  24.         while ((maxResults == SqlExecutor.NO_MAXIMUM_RESULTS || resultsFetched < maxResults) && rs.next()) {  
  25.           Object[] columnValues = resultMap.resolveSubMap(request, rs).getResults(request, rs);  
  26.           callback.handleResultObject(request, columnValues, rs);  
  27.           resultsFetched++;  
  28.         }  
  29.       }  
  30.     } finally {  
  31.       request.setResultSet(null);  
  32.     }  
  33.   } 

返回的PaginatedList實(shí)際上是PaginatedDataList類的對(duì)象,每次翻頁(yè)的時(shí)候最后都會(huì)調(diào)用

  1. private List getList(int idx, int localPageSize) throws SQLException {   
  2.    return sqlMapExecutor.queryForList(statementName, parameterObject, (idx) * pageSize, localPageSize);  
  3.  } 

這個(gè)方法,可見iBATIS的分頁(yè)機(jī)制要看JDBC Driver如何實(shí)現(xiàn)以及是否支持rs.absolute(skipResults)。

這種實(shí)現(xiàn)肯定不如數(shù)據(jù)庫(kù)自己支持的分頁(yè)方式來(lái)的快,一旦碰到數(shù)據(jù)量大的表,有停滯的可能。

iBATIS分頁(yè)的源碼分析就到這里,希望你能對(duì)iBATIS分頁(yè)的根本有所了解。

【編輯推薦】

  1. iBATIS發(fā)展方向的四方面淺析
  2. iBATIS快速創(chuàng)建應(yīng)用淺析
  3. iBATIS配置淺析
  4. iBATIS測(cè)試類的詳細(xì)寫法
  5. iBATIS使用之高級(jí)查詢技術(shù)詳解
責(zé)任編輯:仲衡 來(lái)源: Java天堂
相關(guān)推薦

2009-07-20 16:18:54

iBatis分頁(yè)Hibernate式的

2009-07-21 09:55:45

iBATIS分頁(yè)

2009-07-22 11:11:39

iBATIS分頁(yè)實(shí)例ObjectDataS

2011-05-03 09:40:58

iBatis

2010-05-06 14:01:12

Oracle分頁(yè)存儲(chǔ)過

2010-04-30 08:47:22

Oracle分頁(yè)存儲(chǔ)

2009-12-03 09:49:59

PHP分頁(yè)導(dǎo)航函數(shù)

2009-06-16 10:51:14

Java源碼

2009-07-15 15:47:49

iBATIS是什么

2009-07-21 11:12:00

iBATIS配置

2009-07-16 09:56:32

什么是iBATIS

2019-11-25 16:05:20

MybatisPageHelpeJava

2012-04-25 10:14:40

JavaStruts

2009-07-22 10:42:59

iBATIS Cach

2009-07-15 17:58:07

iBATIS 動(dòng)態(tài)映射

2009-07-16 10:23:30

iBATIS工作原理

2009-07-24 17:20:59

iBatis配置

2009-07-15 11:43:13

<iterate>標(biāo)簽

2009-07-16 11:21:19

ibatis主鍵自動(dòng)生成

2009-09-21 16:56:14

Hibernateibatis
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)