Search code examples
jooqjooq-codegen-maven

Adding a prefix or suffix to the names of POJOs generated with jooq maven plugin


I have the maven plugin set up so it generates jooq classes including POJOs from a Postgres database. My config looks like this:

<generator>
    <generate>
        <pojos>true</pojos>
        <fluentSetters>true</fluentSetters>
    </generate>
    <database>
        <includes>.*</includes>
        <inputSchema>public</inputSchema>
    </database>
    <target>
        <packageName>xxx.yyy</packageName>
        <directory>target/generated-sources/jooq</directory>
    </target>
</generator>

I'm happy with all the generated code, except I would like to add a prefix of suffix to the class name of the POJOs, e.g. Db... - it should be the same for all the POJOs.

I found some information how to do it programmatically, but so for I just have the maven plugin. I understand it's probably related to what's documented here https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-generator/ but I can't figure it out.


Solution

  • Use a generator strategy, either:

    In the latter case, it could be as simple as:

    <configuration>
      <generator>
        <strategy>
          <matchers>
            <tables>
              <table>
                <expression>.*</expression>
                <pojoClass>
                  <transform>PASCAL</transform>
                  <expression>PREFIX_$0_SUFFIX</expression>
                </pojoClass>
              </table>
            </tables>
          </matchers>
        </strategy>
      </generator>
    </configuration>