JOOQ的自动生成类中字段的SQLDataType的用途是什么 [英] What's the usage of field's SQLDataType in JOOQ's auto generated classes

查看:173
本文介绍了JOOQ的自动生成类中字段的SQLDataType的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过JOOQ代码gen生成JOOQ类时,对于每个字段,都会有一个与之关联的SQLDataType,如下所示.

When generating JOOQ classes via JOOQ code gen, for each field, there will be a SQLDataType associated with it like below.

public final TableField<EventsRecord, LocalDateTime> CREATED_AT = createField(DSL.name("CREATED_AT"), SQLDataType.LOCALDATETIME(6).nullable(false), this, "");

在每个生成的字段中使用SQLDataType的用途或目的是什么?由于我们已经有一个返回类型,并且客户端代码很可能会使用此类型来进行编译检查.

What's the usage or purpose to have SQLDataType with each generated field? Since we already have a return type and client code is likely to use the this type to do the compile check.

为什么我们仍然需要知道生成的类/字段中的实际SQLDataType?

Why we still need to know the actual SQLDataType in generated class/fields?

推荐答案

对于客户端类型,您可能是指LocalDateTime类型,即在整个jOOQ API中都可以找到的<T>类型.当然,这是您所关心的类型,但是jOOQ在内部将关心org.jooq.DataType.您的示例已经给出了两个想法,为什么这可能有用:

By client type, you probably mean the LocalDateTime type, i.e. the <T> type that you will find throughout the jOOQ API. Sure, that's the type you care about, but jOOQ, internally, will care about the org.jooq.DataType instead. Your example already gives away two ideas why this may be useful:

  • LOCALDATETIME(6)上有6个小数位数的精度,该精度被使用(除其他外):
    • CAST表达式.尝试DSL.cast(inline("2000-01-01 00:00:00"), EVENTS.CREATED_AT)
    • DDL语句中.尝试 DSLContext.meta(EVENTS) .您应该会看到带有适当数据类型的CREATE TABLE语句
    • 在乐观锁定功能中,以正确的精度创建修改时间戳.
    • There's a precision of 6 fractional digits on LOCALDATETIME(6), which is used (among other things):
      • In CAST expressions. Try DSL.cast(inline("2000-01-01 00:00:00"), EVENTS.CREATED_AT),
      • In DDL statements. Try DSLContext.meta(EVENTS). You should see a CREATE TABLE statement with the appropriate data type
      • In the optimistic locking feature, to create modification timestamps with the right precision.
      • 在DDL语句中,请参见上文
      • 隐式联接功能,用于确定是生成INNER JOIN还是LEFT JOIN
      • In DDL statements, see above
      • In the implicit join feature, to decide whether to produce an INNER JOIN or a LEFT JOIN
      • 自定义数据类型绑定
      • 字符集
      • 整理
      • 转换器
      • 默认值
      • 是否是身份

      如果您的运行时元模型没有可用的信息,那将是一个遗憾.

      It would be a shame if your runtime meta model didn't have this information available.

      这篇关于JOOQ的自动生成类中字段的SQLDataType的用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆