Obtaining an OrderSpecifier from a String

611 views
Skip to first unread message

Aldo Alfredo Gutiérrez Gutiérrez

unread,
Oct 26, 2012, 6:10:59 PM10/26/12
to quer...@googlegroups.com
Right now i have code similar to:

    public List<Tenant> findAllByKeyword(String keyword, String orderBy) {
        OrderSpecifier order= null;
        if (orderBy == null || "".equals(orderBy)) {
            order = qTenant.name.asc();
        } else if ("name".equals(orderBy)) {
            order = qTenant.name.asc();
        } else if ("description".equals(orderBy)) {
            order = qTenant.description.asc();
        } else {
            throw new java.lang.IllegalArgumentException("The specified order by is not supported");
        }
        ....
    }   

I mean if i have the String "name" and the QType qTenant then How can i get the OrderSpecifier: qTenant.name.asc()?

fasfsfgs

unread,
Oct 27, 2012, 11:19:20 AM10/27/12
to Querydsl on behalf of Aldo Alfredo Gutiérrez Gutiérrez
I have the same situation because of how the client (gxt) tells me what column should I order by a server paged grid. It also gives me the asc/desc qualifier.
For example, it gives me the string "name asc".

For now, for those situations, I'm still using raw HQL.

Timo Westkämper

unread,
Oct 27, 2012, 11:26:21 AM10/27/12
to Querydsl on behalf of Aldo Alfredo Gutiérrez Gutiérrez
Hi.

The following should work

new ComparablePath<Comparable>(Comparable.class, qTenant, propertyName).asc();

Br,
Timo
--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com



Reply all
Reply to author
Forward
0 new messages