Discussion:
DetachedCriteria - Case-Insensitive order?
Phil DeJarnett
2012-05-23 20:42:31 UTC
Permalink
I've been trying to figure out how to implement a non-database specific case-insensitive order using DetachedCriteria. I've found that the order(param, dir).ignoreCase() trick was broken in Grails 2.0.

In place of that, it looks like Graeme added the ability to use this very awkward syntax in normal Criteria:

order(new org.hibernate.criterion.Order(param, dir=='asc').ignoreCase())

But this doesn't work in DetachedCriteria, as this form of the method doesn't exist. (More specifically, it looks like DetachedCriteria uses some kind of internal representation for ordering, which doesn't have any way to track a case option.)

Is there any practical way to handle case-insensitive ordering with DetachedCriteria?

It seems like this is a relatively common need, it's surprising it's so awkward to get it working.

Thanks,
--
Phil DeJarnett
OverZealous Creations, LLC
http://www.overzealous.com/
talldave
2012-06-05 23:44:27 UTC
Permalink
we're in the process of upgrading our app to grails 2.0, so just discovered
this. pretty smelly.

i can't help with figuring it out for detached/where criterias, but the
below syntax can be a bit nicer:

original code:

order( "name", "asc" ).ignoreCase()

becomes:

import org.hibernate.criterion.Order

order( Order.asc("name").ignoreCase() )


if i figure out how to do it with detached criterias will post here, but in
the meantime something more than "won't fix" on the JIRA would be nice. :)

--
View this message in context: http://grails.1312388.n4.nabble.com/DetachedCriteria-Case-Insensitive-order-tp4628901p4629618.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Phil DeJarnett
2012-06-06 03:29:58 UTC
Permalink
Post by talldave
order( Order.asc("name").ignoreCase() )
FYI: That format only works if the sort order is always ascending. Otherwise, you still have to use the constructor or a ternary operator, which is still ugly:

order(new Order(param, dir=='asc').ignoreCase())
order((dir=='asc' ? Order.asc(param) : Order.desc(param)).ignoreCase())

Or, if you are 100% certain that the direction is either `asc` or `desc`, this works:

order( Order."$dir"(param).ignoreCase())

Not really viable if you rely on user input for the direction.

Looking at the source, though, I am pretty sure there's no way to get case-insensitive sort into DetachedCriteria.

The biggest issue is that this feels like dropping down to pure Hibernate unnecessarily.

- Phil
Graeme Rocher
2012-06-06 12:30:47 UTC
Permalink
Please raise a feature request in JIRA and we can add this

Cheers
Post by Phil DeJarnett
I've been trying to figure out how to implement a non-database specific
case-insensitive order using DetachedCriteria.  I've found that the
order(param, dir).ignoreCase() trick was broken in Grails 2.0.
In place of that, it looks like Graeme added the ability to use this very
    order(new org.hibernate.criterion.Order(param, dir=='asc').ignoreCase())
But this doesn't work in DetachedCriteria, as this form of the method
doesn't exist.  (More specifically, it looks like DetachedCriteria uses some
kind of internal representation for ordering, which doesn't have any way to
track a case option.)
Is there any practical way to handle case-insensitive ordering with DetachedCriteria?
It seems like this is a relatively common need, it's surprising it's so
awkward to get it working.
Thanks,
--
Phil DeJarnett
OverZealous Creations, LLC
http://www.overzealous.com/
--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Phil DeJarnett
2012-06-06 20:47:59 UTC
Permalink
Done!

http://jira.grails.org/browse/GRAILS-9171
Post by Graeme Rocher
Please raise a feature request in JIRA and we can add this
Cheers
Post by Phil DeJarnett
I've been trying to figure out how to implement a non-database specific
case-insensitive order using DetachedCriteria. I've found that the
order(param, dir).ignoreCase() trick was broken in Grails 2.0.
In place of that, it looks like Graeme added the ability to use this very
order(new org.hibernate.criterion.Order(param, dir=='asc').ignoreCase())
But this doesn't work in DetachedCriteria, as this form of the method
doesn't exist. (More specifically, it looks like DetachedCriteria uses some
kind of internal representation for ordering, which doesn't have any way to
track a case option.)
Is there any practical way to handle case-insensitive ordering with DetachedCriteria?
It seems like this is a relatively common need, it's surprising it's so
awkward to get it working.
Thanks,
--
Phil DeJarnett
OverZealous Creations, LLC
http://www.overzealous.com/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...