2

I am using the jooq codgen gradle plugin to change the naming convention for generated tables to include Table at the end of the class name. However, I am not sure how to distinguish a table from a schema in the generator.

My naming override is:

@Override
public String getJavaClassName(Definition definition, Mode mode) {
    String result = super.getJavaClassName(definition, mode);
    if (mode == Mode.DEFAULT) {
        result += "Table";
    }
    return result;
}

Is there a way to determine If the current object extends TableImpl or maybe I need to take a different approach?

Toaster
  • 1,911
  • 2
  • 23
  • 43

1 Answers1

2

Just use instanceof checks on your definition, like this:

@Override
public String getJavaClassName(Definition definition, Mode mode) {
    String result = super.getJavaClassName(definition, mode);
    if (mode == Mode.DEFAULT && definition instanceof TableDefinition) {
        result += "Table";
    }
    return result;
}
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • To clarify, you need to implement a custom `GeneratorStrategy` in one Maven module and use it in another. This is because JOOQ's `generate` goal runs before the Java compiler runs in the same project. – Gili Jun 13 '22 at 23:52