jOOQ 枚举带注释的forcedType

问题描述 投票:0回答:1

目前我在gradle jooq配置中定义了枚举forcedType,但我想通过注释自动设置它。

jooq {
  version.set(Versions.jooq)
  edition.set(OSS)

  configurations {
    create("main") {
      jooqConfiguration.apply {
        logging = Logging.INFO
        generator.apply {
          name = "org.jooq.codegen.KotlinGenerator"
          database.apply {
            name = "com.example.generator.StandalonePostgreSQLDatabase"
            inputSchema = "public"
            excludes = "flyway_schema_history"
            forcedTypes.addAll(
              listOf(
                ForcedType().apply {
                  isEnumConverter = true
                  includeTypes = "day_of_week"
                  userType = "com.example.api.enums.DayOfWeek"
                }
              )
            )
          }
          generate.apply {
            isDeprecated = false
            isRecords = true
            isImmutablePojos = true
            isFluentSetters = true
          }
          target.apply {
            packageName = "com.example.api"
            directory = "build/generated/jooq"
          }
          strategy.name = "com.example.common.JPrefixGeneratorStrategy"
        }
      }
    }
  }
}

当枚举类被@DatabaseEnum注释时,我想将它们添加为forcedType。有什么可行的办法吗?

@Retention(AnnotationRetention.RUNTIME)
annotation class DatabaseEnum(val includeType: String)

@DatabaseEnum(includeType = "day_of_week")
enum class DayOfWeek {
  MONDAY,
  TUESDAY,
  WEDNESDAY,
  THURSDAY,
  FRIDAY,
  SATURDAY,
  SUNDAY
}
kotlin jooq
1个回答
0
投票

有一个待处理的功能请求正是针对此:

从 jOOQ 3.18(可能是 3.19)开始,这还不能开箱即用。

你显然可以自己实现。为此,您需要:

  • 在生成代码时扫描类路径(即需要预编译带注释的类型)
  • 使用某种编程代码生成配置,或实现您自己的 gradle 插件。
© www.soinside.com 2019 - 2024. All rights reserved.