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