简体   繁体   English

JOOQ多场定制型转换器

[英]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. 存储为3个单独的数据库字段。 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. 然后获取记录并从相应的记录字段创建PersonName类型。

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. 我们的想法是定义一些多列自定义字段PERSON_NAME ,它将在查询执行期间由jooq扩展为三个“真实”字段,并打包到结果中的一个PersonName对象。

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. 看起来可以用org.jooq.impl.AbstractField做这样的事情,但我想知道,可能已经有这种情况的解决方案了。

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: 借助jOOQ 3.6的开箱即用功能,您可以将这些列存储在以下位置:

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

And then select them as such: 然后选择它们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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