Search in sources :

Example 26 with Order

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();
}
Also used : SortConstraint(org.apache.tapestry5.grid.SortConstraint) Criteria(org.hibernate.Criteria)

Aggregations

Test (org.testng.annotations.Test)10 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)6 Messages (org.apache.tapestry5.commons.Messages)6 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)3 ToDoItem (org.apache.tapestry5.integration.app1.data.ToDoItem)3 Method (java.lang.reflect.Method)2 EventContext (org.apache.tapestry5.EventContext)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 Location (org.apache.tapestry5.commons.Location)2 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)2 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)2 Link (org.apache.tapestry5.http.Link)2 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)2 ObjectStreamException (java.io.ObjectStreamException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1