if (size == 1)
totalRow = ((Number)result.get(0)).longValue(); // totalRow = (Long)result.get(0);
else if (size > 1)
totalRow = result.size();
else
return new Page(new ArrayList(0), pageNumber, pageSize, 0, 0); // totalRow = 0;
totalPage = (int) (totalRow / pageSize);
if (totalRow % pageSize != 0) {
totalPage++;
}
// --------
StringBuilder sql = new StringBuilder();
sql.append(select).append(" ").append(sqlExceptSelect);
PreparedStatement pst = conn.prepareStatement(sql.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
for (int i=0; i<paras.length; i++) {
pst.setObject(i + 1, paras[i]);
}
ResultSet rs = pst.executeQuery();
// move the cursor to the start
int offset = pageSize * (pageNumber - 1);
for (int i=0; i<offset; i++)
if (!rs.next())
break;
List list = buildModel(rs, modelClass, pageSize);
if (rs != null) rs.close();
if (pst != null) pst.close();
return new Page(list, pageNumber, pageSize, totalPage, (int)totalRow);
} catch (Exception e) {
throw new ActiveRecordException(e);
} finally {
DbKit.close(conn);
}