目前我在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
}
有一个待处理的功能请求正是针对此:
从 jOOQ 3.18(可能是 3.19)开始,这还不能开箱即用。
你显然可以自己实现。为此,您需要: