return getTransactionTemplateRetrying(getMaxRetries()).execute(new TransactionCallback<Pair<List<RiskRun>, Paging>>() {
@Override
public Pair<List<RiskRun>, Paging> doInTransaction(final TransactionStatus status) {
//
final PagingRequest pagingRequest = request.getPagingRequest();
List<RiskRun> results = Collections.emptyList();
Paging paging;
if (!pagingRequest.equals(PagingRequest.NONE)) {
if (pagingRequest.equals(PagingRequest.ALL)) {
criteria.addOrder(Order.asc("valuationTime"));
results = getHibernateTemplate().findByCriteria(
criteria,
pagingRequest.getFirstItem(),
pagingRequest.getPagingSize());
//
paging = Paging.of(pagingRequest, results);
} else {
criteria.setProjection(Projections.rowCount());
final Long totalCount = (Long) getHibernateTemplate().findByCriteria(criteria).get(0);
paging = Paging.of(pagingRequest, totalCount.intValue());
//
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
criteria.addOrder(Order.asc("valuationTime"));
results = getHibernateTemplate().findByCriteria(
criteria,
pagingRequest.getFirstItem(),
pagingRequest.getPagingSize());
}
} else {
paging = Paging.of(PagingRequest.NONE, 0);
}
return Pair.of(results, paging);