JOOQ: how do I add an interface to a generated Record Class

前端 未结 1 1919
無奈伤痛
無奈伤痛 2021-02-14 08:10

I am generating a set of JOOQ records from a schema using JOOQ 3.6.4 with Java 8.

Some of the tables are reference data that are similarly structured, let\'s say they ha

1条回答
  •  清歌不尽
    2021-02-14 09:00

    This can be done using

    • Generator strategies
    • Matcher strategies (which are built-in, XML-based generator strategies)

    Generator strategy

    With a generator strategy, you'll implement the following code:

    public class MyStrategy extends DefaultGeneratorStrategy {
        @Override
        public List getJavaClassImplements(Definition definition, Mode mode) {
            if (mode == Mode.RECORD && definition.getQualifiedName().matches("some regex")) {
                return Arrays.asList(MyCustomInterface.class.getName());
            }
        }
    }
    

    The above can then be hooked into your code generator configuration as such:

    
      
        com.example.MyStrategy
      
    
    

    Matcher strategy

    With a matcher strategy, you'll essentially write:

    
      
        
          
            A_REGEX_MATCHING_ALL_RELEVANT_TABLEScom.example.MyCustomInterface

    As you can see, matcher strategies are easier to configure than generator strategy, for simple use-cases like yours.

    0 讨论(0)
提交回复
热议问题