*
* @param detachedCriteria
* @return
*/
protected int findCriteriaRowCount(final Criteria criteria) {
CriteriaImpl impl = (CriteriaImpl) criteria;
// 先把Projection、ResultTransformer、OrderBy取出来,清空三者后再执行Count操作
Projection projection = impl.getProjection();
ResultTransformer transformer = impl.getResultTransformer();
// 将orderBy对象中的排序字段存入数组中
List<?> orderEntries = (List<?>) accessor.getValue(criteria);
// 将排序字段设置为空
accessor.setValue(Collections.emptyList(), criteria);
// 执行Count查询
int count = ((Number) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
// 将取出的参数设回bean
impl.setProjection(projection);
if (projection == null && transformer == null) {
impl.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
} else if (transformer != null) {
impl.setResultTransformer(transformer);
}
accessor.setValue(orderEntries, impl);
return count;
}