use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.
the class HibernateGridDataSource method prepare.
/**
* Prepares the results, performing a query (applying the sort results, and the provided start and end index). The
* results can later be obtained from {@link #getRowValue(int)} }.
*
* @param startIndex index, from zero, of the first item to be retrieved
* @param endIndex index, from zero, of the last item to be retrieved
* @param sortConstraints zero or more constraints used to set the order of the returned values
*/
@Override
public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {
assert sortConstraints != null;
Criteria crit = session.createCriteria(entityType);
crit.setFirstResult(startIndex).setMaxResults(endIndex - startIndex + 1);
for (SortConstraint constraint : sortConstraints) {
String propertyName = constraint.getPropertyModel().getPropertyName();
switch(constraint.getColumnSort()) {
case ASCENDING:
crit.addOrder(Order.asc(propertyName));
break;
case DESCENDING:
crit.addOrder(Order.desc(propertyName));
break;
default:
}
}
applyAdditionalConstraints(crit);
this.startIndex = startIndex;
preparedResults = crit.list();
}
Aggregations