Querying and ordering results of a database in grails using transient fields
Posted
by Azder
on Stack Overflow
See other posts from Stack Overflow
or by Azder
Published on 2010-03-12T15:55:56Z
Indexed on
2010/03/12
15:57 UTC
Read the original article
Hit count: 306
I'm trying to display paged data out of a grails domain object. For example: I have a domain object Employee with the properties firstName and lastName which are transient, and when invoking their setter/getter methods they encrypt/decrypt the data. The data is saved in the database in encrypted binary format, thus not sortable by those fields. And yet again, not sortable by transient ones either, as noted in: http://www.grails.org/GSP+Tag+-+sortableColumn .
So now I'm trying to find a way to use the transients in a way similar to:
Employee.withCriteria( max: 10, offset: 30 ){
order 'lastName', 'asc'
order 'firstName', 'asc'
}
The class is:
class Employee {
byte[] encryptedFirstName
byte[] encryptedLastName
static transients = [
'firstName',
'lastName'
]
String getFirstName(){
decrypt("encryptedFirstName")
}
void setFirstName(String item){
encrypt("encryptedFirstName",item)
}
String getLastName(){
decrypt("encryptedLastName")
}
void setLastName(String item){
encrypt("encryptedLastName",item)
}
}
© Stack Overflow or respective owner