读书人

Hibernate的VO在HQL话语中的应用

发布时间: 2012-08-02 11:35:25 作者: rapoo

Hibernate的VO在HQL语句中的应用

HQL语句为:

select new com.xxx.vo.TAdminDefineReportVo(a.defineReportId,a.reportTmpId,

????? c.reportName,a.admin,a.reportType,a.description,

????? a.status,a.createTime,a.autoSend,a.emails,b.userName)

from TAdminDefineReport a,TReportTemplate c,TAdminInfo b

where a.reportTmpId = c.reportTmpId

and a.admin = b.administrorId

and a.admin = ?? $queryClause$

order by? a.reportTmpId desc,a.createTime desc

?

DaoImpl类:

?public Pagination getAdminRepByAdmId(int admId,String queryName,String reportType,String startTime,String endTime){
??try{
???String hql = this.getHql("repTmp.hql10");
???
???StringBuilder sb = new StringBuilder();
???if(("".equals(queryName)||queryName==null)&&("-1".equals(reportType)||reportType==null)
?????&&("".equals(startTime)||startTime==null)&&("".equals(endTime)||endTime==null)){
????hql = hql.replace("$queryClause$", "");
???}
???if(!"".equals(queryName) && queryName != null){
????sb.append(" and b.reportName like '%" + queryName + "%'");
???}
???if(!"-1".equals(reportType)&&!"".equals(reportType)){
????sb.append(" and a.reportType = '" + reportType + "'");
???}
???if(!"".equals(startTime) && startTime != null){
????sb.append(" and a.createTime >= '" + startTime + "'");
???}
???if(!"".equals(endTime) && endTime != null){
????sb.append(" and a.createTime <= '" + endTime + "'");
???}
???hql = hql.replace("$queryClause$", sb.toString());
???
???return this.searchPaginated(hql,admId);
??}catch(Exception e){
???logger.error(e.getMessage());
???throw new PersistenceException(e.getMessage());
??}
?}

读书人网 >开源软件

热点推荐