为防止一次性读取数据过多而内存不足,因此后台每次取出100数据统计,经过多次取;
从而完成统计!
例子如下:service方法
public class QueryClientStatisticsService
{
protected ClientStatisticsDao clientStatisticsDao = new ClientStatisticsDaoImp();
public void initConfig(ClientStatisticsDo clientStatisticsDo)
{
try
{
//总记录数
int AllCouts = clientStatisticsDao.queryClientStatisticsCounts(clientStatisticsDo);
//每次获取100条数据
int perCounts = 100;
//需要取nums次
int nums = (AllCouts % perCounts) == 0 ? (AllCouts / perCounts)
: (AllCouts / perCounts) + 1;
//记录开始位置
int start ;
//记录结束位置
int end ;
//分次数取数据
String[] statact;
String[] founctions;
//存放nums查询累加的客户端功能点
Map<String, Integer> map = new HashMap<String, Integer>();
for (int i = 1; i <= nums; i++)
{
start = (i - 1) * perCounts + 1;
end = i * perCounts;
clientStatisticsDao.queryClientStatistics(clientStatisticsDo,
start,
end);
//每次取数据时,list存放客户端功能点编号和次数
List<String> list = clientStatisticsDo.getList();
for (int j = 0; j < list.size(); j++)
{
//遍历每条记录
statact = list.get(j).split(";");
for (int k = 0; k < statact.length; k++)
{
founctions = statact[k].split(":");
//对map初始化
if (null == map.get(founctions[0]))
{
map.put(founctions[0], 0);
}
map.put(founctions[0], map.get(founctions[0])
+ Integer.parseInt(founctions[1]));
}
}
}
//将map的内容封装到域对象中
this.transform(clientStatisticsDo, map);
}
catch (BMSException e)
{
DebugLogFactory.error(this.getClass(), "other error:", e);
throw new GeneralBMEException(String.valueOf(e.getExceptionCode()));
}
}
说明:统计的字段样式:0000:5;0001:23;
2.分页sql语句(需要排序,建立索引):
SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM ECONF_CLIENT_STATACT t where substr(t.datetime,1,10) between :beginTime AND :endTime order by t.datetime ) A WHERE ROWNUM <=:end ) WHERE RN >=:start