2

我正在使用 jOOQ 3.15 并且遇到奇怪的生成器行为 Codegen 如果您使用自定义数据类型的转换器,则会为 Records 生成几乎没有不同的复制构造函数。我正在尝试与我们的实体实现 org.joda.money.Money 集成

一些示例实体

create type pg_money as (
  amount numeric,
  currency varchar
);

create table test_money(
  id uuid primary key,
  money pg_money not null
);

我们的自定义转换器:

class PostgresMoneyConverter : Converter<PgMoneyRecord, Money> {
  override fun from(t: PgMoneyRecord): Money {
    return Money.of(CurrencyUnit.of(t.currency), t.amount)
  }

  override fun to(u: Money): PgMoneyRecord {
    return PgMoneyRecord(u.amount, u.currencyUnit.code)
  }

  override fun fromType(): Class<PgMoneyRecord> {
    return PgMoneyRecord::class.java
  }

  override fun toType(): Class<Money> {
    return Money::class.java
  }
}

在TestMoneyRecord.kt中生成的构造函数:

constructor(value: by.ivasiuk.testmoney.model.tables.pojos.TestMoney?): this() {
  if (value != null) {
    this.id = value.id
    this.money = value.money?.let { Money(it) }
  }
}

问题出在Money(it)中,因为 Money 没有这样的构造函数,只有 BigMoney 作为参数。有趣的是,如果我使用任何基本数据类型,即使它不是原始数据类型, codegen 只会放置this.money = value.money而不使用任何复制构造函数

我在 3.16 中看到了一些自定义构造函数生成的计划。3.15 中是否有任何解决方案根本不生成构造函数或强制它也使用this.money = value.money

4

0 回答 0