JOOQ multi-field custom type converter

734 views Asked by At

We have some custom types that reflected to multiple db fields. For example

PersonName{
  String salutation, 
  String firstName, 
  String lastName
}

stored as 3 separate db fields. And it's boring to always write

db.select(PERSON.FIRST_NAME, PERSON.LAST_NAME, PERSON.SALUTATION, ... some other fields)

then fetch the record and create PersonName type from the appropriate record fields.

The idea is to define some multi-column custom field PERSON_NAME, which will be expanded by jooq into three "real" fields during the query execution, and packed to the one PersonName object in the result.

Looks like it's possible to do something like this with org.jooq.impl.AbstractField, but I'm wondering, may be there is a solution for such case already.

1

There are 1 answers

0
Lukas Eder On BEST ANSWER

There are pending feature requests to support this kind of functionality:

With out-of-the-box functionality of jOOQ 3.6, you could store those columns somewhere as:

Field<?>[] personName = {
    PERSON.SALUTATION,
    PERSON.FIRST_NAME,
    PERSON.LAST_NAME
};

And then select them as such:

db.select(personName)
  .select(... some other fields);