How build a JOOQ custom generator?

守給你的承諾、 提交于 2019-12-20 07:34:13

问题


I have a specific Postgre schema that gathers all tables that defines types, like Status(name, description) where values could be OPEN, Open item status, CLOSED, Closed item status, etc.

We need to fetch all these tables and generate enums based on them to later use it within our app. So, these enums should look like:

enum Status {
    OPEN("Open item status"),
    CLOSED("Closed item status")
    ...
}

We decided to use JOOQ which looks pretty interesting, but we cannot find documentation/examples to create a custom generator that use default java generator behavior plus a custom enum generation extension.

Basing on this post generate enum class from table with JOOQ, it brought some ideas but still not clear what to do to achieve what the answer states.

Update: in order to have my custom generator to being picked by jooq-codegen-maven plugin I created a separate project and added its jar as a dependency of my parent project. I created a class MyGenerator and made it extend from JavaGenerator. In order to have this org.jooq.codegen.JavaGenerator I had to add below maven dependency (not coming in spring-boot-starter-jooq):

<dependency>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen-maven</artifactId>
    <version>3.11.2</version>
</dependency>

Once done this and inherited from JavaGenerator, according to the post answer I should hook into generate(SchemaDefinition) method, however this is not protected scope, so I think I'm missing something here.

Do you know or can you provide an example describing how to write this kind of code generator for enums? I need JOOQ to generate code as usual for a specific schema, but besides it I need to query another specific "enum" schema that only contains those "enum" tables.

来源:https://stackoverflow.com/questions/52171377/how-build-a-jooq-custom-generator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!