Querying and ordering results of a database in grails using transient fields
- by Azder
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)
}
}