Hello,
The jOOQ DSL API is composed of various types that can be created
independently from a SELECT statement. Your Criteria API client code
could translate to this:
Condition c = Factory.trueCondition();
if ( firstName != null )
condition = condition.and(FIRST_NAME.eq(firstName));
if ( lastName != null )
condition = condition.and(LAST_NAME.eq(lastName));
if ( license != null )
condition = condition.and(LICENSE.eq(license));
if ( birthYear > 0 )
condition = condition.and(BIRTH_YEAR.eq(birthYear));
// And then
Result<Record> res =
factory.select().from(PERSON).where(condition).fetch();
// Or even
Result<PersonRecord> res =
factory.selectFrom(PERSON).where(condition).fetch();
Hope this helps
2012/9/19 JK <
jk3...@gmail.com>:
>
>
> Hello,
>
> I am semi seriously porting a project from Hibernate to jOOQ. I would like
> to hear your ideas / comments how to port following code to jOOQ. In
> Hibernate it is easy to build criteria in steps. Hibernate internally adds
> "and" between each criteria components.
>
>
> public static List<Person> selectPerson( SessionHolder sessionHolder,
> String firstName, String lastName, String license, int birthYear, int mode )
> {
> Criteria criteria =
> sessionHolder.getSession().createCriteria(Person.class);
> if ( firstName != null )
> criteria = criteria.add(eq("firstName",firstName));
> if ( lastName != null )
> criteria = criteria.add(eq("lastName",lastName));
> if ( license != null )
> criteria = criteria.add(eq("license",license));
> if ( birthYear > 0 )
> criteria = criteria.add(eq("birthYear",birthYear));
> List<Person> personList = criteria.list();
> ... code deleted ...
> return personList;
> }
>
>
> selectPerson is used so that depending on the case one, two, ... all of the
> parameters: firstName, lastName, license, birthYear are given. Number of
> different parameter combinations (given / missing) is so high that it is not
> a solution to write a code for each solution:
>
> public static List<Person> selectPerson( Factory factory, String
> firstName, String lastName, String license, int birthYear, int mode ) {
>
> if (( firstName != null ) && ( lastName != null ) && ( license !=
> null ) && ( birthYear > 0 )) {
> Result<Record> res = factory.select().from(PERSON).where(....
> } else (( firstName != null ) && ( lastName != null ) && ( license
> != null )) {
> Result<Record> res = factory.select().from(PERSON).where(....
> } else (( firstName != null ) && ( lastName != null )) {
> Result<Record> res = factory.select().from(PERSON).where(....
> } else (( firstName != null )) {
>
> } else ...
> ... code deleted ...
> return personList;
> }
>
>
> Any ideas are welcome!
> Thank you for your help
>
> JK
>