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

善左ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
調(diào)用次序如下SqlMapClientImpl.queryForPaginatedList->SqlMapSessionImpl.queryForPaginatedList
->SqlMapExecutorDelegate.queryForPaginatedList->GeneralStatement.executeQueryForList
->GeneralStatment.executeQueryWithCallback->GeneralStatment.executeQueryWithCallback
->SqlExecutor.executeQuery->SqlExecutor.handleMultipleResults()
iBATIS分頁處理的函數(shù)如下
- private void handleResults(RequestScope request, ResultSet rs, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {
- try {
- request.setResultSet(rs);
- ResultMap resultMap = request.getResultMap();
- if (resultMap != null) {
- // Skip Results
- if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) {
- if (skipResults > 0) {
- rs.absolute(skipResults);
- }
- } else {
- for (int i = 0; i < skipResults; i++) {
- if (!rs.next()) {
- return;
- }
- }
- }
- // Get Results
- int resultsFetched = 0;
- while ((maxResults == SqlExecutor.NO_MAXIMUM_RESULTS || resultsFetched < maxResults) && rs.next()) {
- Object[] columnValues = resultMap.resolveSubMap(request, rs).getResults(request, rs);
- callback.handleResultObject(request, columnValues, rs);
- resultsFetched++;
- }
- }
- } finally {
- request.setResultSet(null);
- }
- }
返回的PaginatedList實際上是PaginatedDataList類的對象,每次翻頁的時候最后都會調(diào)用
- private List getList(int idx, int localPageSize) throws SQLException {
- return sqlMapExecutor.queryForList(statementName, parameterObject, (idx) * pageSize, localPageSize);
- }
這個方法,可見iBATIS的分頁機(jī)制要看JDBC Driver如何實現(xiàn)以及是否支持rs.absolute(skipResults)。
這種實現(xiàn)肯定不如數(shù)據(jù)庫自己支持的分頁方式來的快,一旦碰到數(shù)據(jù)量大的表,有停滯的可能。
iBATIS分頁的源碼分析就到這里,希望你能對iBATIS分頁的根本有所了解。
【編輯推薦】
- iBATIS發(fā)展方向的四方面淺析
- iBATIS快速創(chuàng)建應(yīng)用淺析
- iBATIS配置淺析
- iBATIS測試類的詳細(xì)寫法
- iBATIS使用之高級查詢技術(shù)詳解
分享名稱:iBATIS分頁源碼真相探討
標(biāo)題來源:http://www.fisionsoft.com.cn/article/cohhoeg.html


咨詢
建站咨詢
