grails分页查询回调获取总数方法,谁有研究请指导(源码)
weilJava
2015-05-06
PagedResultList 这个类里的方法,是怎么拼装sql的,如果存在group by的情况是如何处理的,
这个grails底层是将hibernate封装了一下,谁懂hibernate应该也懂的吧,请指教 public int getTotalCount() { if (totalCount == Integer.MIN_VALUE) { totalCount = (Integer)hibernateTemplate.execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException, SQLException { CriteriaImpl impl = (CriteriaImpl) criteria; Criteria totalCriteria = session.createCriteria(impl.getEntityOrClassName()); hibernateTemplate.applySettings(totalCriteria); Iterator iterator = impl.iterateExpressionEntries(); while (iterator.hasNext()) { CriteriaImpl.CriterionEntry entry = (CriteriaImpl.CriterionEntry) iterator.next(); totalCriteria.add(entry.getCriterion()); } Iterator subcriteriaIterator = impl.iterateSubcriteria(); while (subcriteriaIterator.hasNext()) { CriteriaImpl.Subcriteria sub = (CriteriaImpl.Subcriteria) subcriteriaIterator.next(); totalCriteria.createAlias(sub.getPath(), sub.getAlias(), sub.getJoinType(), sub.getWithClause()); } totalCriteria.setProjection(impl.getProjection()); totalCriteria.setProjection(Projections.rowCount()); return ((Number)totalCriteria.uniqueResult()).intValue(); } }); } return totalCount; } |