日期:2014-05-18  浏览次数:20730 次

优化别人的代码,求助!!!!!! 解决就给分
现在要优化别人的代码,取list大小他是这么取的,现在速度很慢。代码如下:
这样取太浪费了。
问:hibernate是不是有像   count(*)   这样的函数。   应该怎么改。速度上来马上给满分。
List   list4   =   this.siSorInformDeptDao.getNotAskRecievedByDepidAndDateAndStatus(asDepid,  
InformSorType.RECIVE_INFORM,   asStart,   asEnd,   InformSorStatus.SIGNIN_INFORM_ALREADY);
  iNotAskRecievedS   =   list4.size();
*******************************************
public   List   getNotAskRecievedByDepidAndDateAndStatus(String   asDepid,   String   asType,   String   asStart,   String   asEnd,   String   asStatus)   {
//   TODO   自动生成方法体
String   strDepid     =   asDepid;
String   strType   =   asType;
String   strStatus   =   asStatus;
String   strStartDate   =   asStart;
String   strEndDate   =   asEnd;
String   strSql   =   " ";


strSql   =   "   from   SiSorInformDept   m1,SiInform   m2   where   (m1.siInform.id=m2.id   and   m1.sorDept= "
  +   strDepid   +   "   and   m1.sorType= "   +   strType   +   "   and   m1.sorStatus= "   +   strStatus   +   ")   and   (TO_CHAR(m1.sendDate, 'yyyy/MM/dd ')> = ' "   +   strStartDate
+   " '   and   "   +   "   TO_CHAR(m1.sendDate, 'yyyy/MM/dd ') <= ' "   +   strEndDate
+   " ')   and   ((TO_CHAR(m1.signinDate, 'yyyy/MM/dd ')> TO_CHAR(m2.askForDate, 'yyyy/MM/dd ')) ";
strSql   +=   "or   (m1.notarrivelSource   is   not   null   and     length(rtrim(ltrim(m1.notarrivelSource)))> 0)) ";

return   getHibernateTemplate().find(strSql);
}

}   catch   (RuntimeException   re)   {
log.error( "根据部门ID和日期期间和记录状态获得记录集合失败! ",   re);
throw   re;
}
}



------解决方案--------------------
http://www.zhuaxia.com/item/360309777


------解决方案--------------------
直接在strSql 前面加上select count(*)不就好了么?......
------解决方案--------------------
帮你顶
------解决方案--------------------
直接在strSql 前面加上select count(*)不就好了么?......

不可取 这更影响速度~