Query and organize database results in a grail using transition fields

I am trying to display paged data from a grails domain object. For example: I have an Employee domain object with the firstName and lastName properties, which are temporary, and when calling the setter / getter methods, they encrypt / decrypt the data. Data is stored in the database in an encrypted binary format, so it is not sorted by these fields. And yet again, non-sortable transients, as stated in: http://www.grails.org/GSP+Tag+-+sortableColumn .

So now I'm trying to find a way to use transients in a way similar to:

Employee.withCriteria( max: 10, offset: 30 ){
    order 'lastName', 'asc'
    order 'firstName', 'asc'
} 

Grade:

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)       
}

}

+3
1

- , GORM/hibernate. SQL , .

:

  • .
  • (, "select * from employee order by AES_DECRYPT(lastName, key)" ). , .
  • - , . : lastName. , .
+2

Source: https://habr.com/ru/post/1736684/


All Articles