数据库大数据量处理方法启用游标查询
1,可以防止数据库一下返回过大,超时(超过数据库限制),效果类似分页查询
2,需要开启事务---分批查询的缘故
@Transactional
@Override
public List
List
List
List
List
Long segmentId = hRequest.getSegmentId();
Long lastId = hRequest.getLatestId();
Long begin = hRequest.getBegin();
Long limit = hRequest.getLimit();
Integer taskType = hRequest.getTaskType();
String taskId = hRequest.getTaskId();
Cursor
try{
QueryWrapper
if(null != matchingIds && matchingIds.size()>0){
query.in("m",matchingIds);
}
if(null !=segmentId){
query.eq("s",segmentId);
}
if(null != begin && null != limit){
query.gt("id",begin);
query.last("limit "+limit);
}
if(null !=taskType){
query.eq("t",taskType);
}
if(null !=taskId){
query.eq("t_id",taskId);
}
MyExport myExport = new MyExport();
domainList = HHMapper.listData(query,myExport);
Iterator
int num=0;
while (iter.hasNext()){
// HH tmp =iter.next();
rebuildBo(resultDto, iter.next());
// result.add(tmp);
num++;
}
if(num == 0){
log.info("没有对应条件的查询结果:sid:{},mid:{}",sId,mIds);
}else{
log.info("getHNoPage数据库查询结果数:{}",num);
}
result =null;
}catch (Exception e){
log.error("根据mId查询HH失败,条件:{},异常:{}",mIds,e.getMessage(),e);
}finally {
if (null != domainList) {
try {
domainList.close();
} catch (Exception e) {
log.error("根据matchIngId查询HH游标关闭失败:{}",e.getMessage(), e);
}
}
}
return resultDto;
}
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
public class MyExport implements ResultHandler {
@Override
public void handleResult(ResultContext resultContext) {
Object resultObject = resultContext.getResultObject();
System.out.println(resultObject.toString());
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)