-
Couldn't load subscription status.
- Fork 8
Functions
gert-wijns edited this page Feb 11, 2016
·
7 revisions
Functions
Functions are used in the TypeSafeQueryBuilder as TypeSafeValue builders.
The available functions can be accessed through the hqlFunction() method on a query.
There is not much more to say about this, so here are some examples:
Person person = query.from(Person.class);
PersonDto dto = query.select(PersonDto.class);
1) dto.setPersonAge(query.hqlFunction().max(person.getAge()).select());
yields => "select max(hobj1.age) as personAge from Person hobj1"
2) dto.setThePersonsName(query.hqlFunction().coalesce(person.getName()).or("Bert").select());
yields => "select coalesce(hobj1.name,?) as thePersonsName from Person hobj1" with params ["Bert"]
3) query.whereString(query.hqlFunction().upper(person.getName())).eq("TOM");
yields => "from Person hobj1 where upper(hobj1.name) = ?" with params ["TOM"]It is also possible to create the TypeSafeValue instances yourself if your function is not available in the library. See What if I really really need custom hql? for more information about that.