首页 > 应用开发 > IT综合 > Jive笔记4--结果集分页处理 (转)
ResultFilter filter = new ResultFilter(); filter.setStartIndex(start); //从第start条thread开始 filter.setNumResults(range); //页面大小 // Set the moderation level minimum filter.setModerationRangeMin(forum.getModerationMinThreadValue()); // More forum properties int numThreads = forum.getThreadCount(filter); int numMessages = forum.getMessageCount(filter); // Iterator of threads ForumThreadIterator threads = forum.threads(filter); //返回thread Iterator,
public ForumThreadIterator threads(ResultFilter resultFilter) { //根据传入的resultFilter构造一个查询SQL语句(*注1) String query = getThreadListSQL(resultFilter, false); //返回一个确定返回的id列表,这里缺省大小是400个,例如,我要看1~15条纪录 // threadBlock的length是400,从1~400(*注2) long [] threadBlock = getBlock(query.toString(), resultFilter.getStartIndex()); int startIndex = resultFilter.getStartIndex(); int endIndex; // If number of results is set to inifinite, set endIndex to the total // number of threads in the forum. if (resultFilter.getNumResults() == ResultFilter.NULL_INT) { endIndex = (int)getThreadCount(resultFilter); } else { endIndex = resultFilter.getNumResults() + startIndex; } //嘿嘿,理解了上面几句代码先,然后来看这个iterator return new ForumThreadBlockIterator(threadBlock, query.toString(), startIndex, endIndex, this.id, factory); }
int blockID = startIndex / BLOCK_SIZE; int blockStart = blockID * BLOCK_SIZE;
con = ConnectionManager.getConnection(); stmt = ConnectionManager.createScrollableStatement(con); // Set the maximum number of rows to end at the end of this block. ConnectionManager.setMaxRows(stmt, BLOCK_SIZE * (blockID+1)); ResultSet rs = stmt.executeQuery(query); // Grab BLOCK_SIZE rows at a time. ConnectionManager.setFetchSize(rs, BLOCK_SIZE); //一次最多取BLOCK_SIZE条,也就是400条 // Position the cursor right before the first row that we're insterested in. ConnectionManager.scrollResultSet(rs, blockStart);// 滚动游标到blockStart // Keep reading results until the result set is exhausted or // we come to the end of the block. int count = 0; while (rs.next() && count < BLOCK_SIZE) { objectList.add(rs.getLong(1)); count++; }
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-958256/ ,如需转载,请注明出处,否则将追究法律责任。