學習Jive(Jdon版)分頁處理遇到了一些困惑,請指教

oldbig615發表於2005-08-07
主要在com.jivesoftware.forum.database.DbForum這個類裡

1.我對這裡塊(block)搞不明白,按他這裡說的,

int blockID = startIndex / THREAD_BLOCK_SIZE; //1251行
int blockStart = blockID * THREAD_BLOCK_SIZE;
根據THREAD_BLOCK_SIZE得到blockStart
假如我的顯示的內容跨兩個塊該怎麼辦?
這裡THREAD_BLOCK_SIZE=200,如果我要顯示從180到240的該怎麼顯示,返回兩個塊(block)嗎?

2.在DbForum.java 的getThreadBlock(String query, int startIndex)方法中,當快取中不存在時,他從資料庫裡取。
con = ConnectionManager.getConnection();
stmt = con.createStatement();
// Set the maxium number of rows to end at the end of this block.
ConnectionManager.setMaxRows(stmt, THREAD_BLOCK_SIZE * (blockID+1));
ResultSet rs = stmt.executeQuery(query);
// Grab THREAD_BLOCK_ROWS rows at a time.
ConnectionManager.setFetchSize(rs, THREAD_BLOCK_SIZE);
// Many JDBC drivers don't implement scrollable cursors the real
// way, but instead load all results into memory. Looping through
// the results ourselves is more efficient.
for (int i=0; i<blockStart; i++) {
rs.next();
}
上面這個迴圈讓我有點困惑,如果blockStart很大,成千上萬,這個使用rs.next()的效率會不會很差?有什麼更好的辦法?

相關文章