简体   繁体   中英

JOOQ multi-field custom type converter

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM