Skip to content
Advertisement

JOOQ add prefix to pojo class name

I am generating the pojo classes with jooq codegen, I am trying to create them with a prefix, but I cannot understand how to do it. I am using this configuration to generate them

Configuration configuration = new Configuration()
    .withJdbc(
        new Jdbc()
            .withDriver("org.mariadb.jdbc.Driver")
            .withUrl("jdbc:mariadb://**:3306/**")
            .withUser("**")
            .withPassword("**")
    )
    .withGenerator(
        new Generator()
            .withGenerate(
                new Generate()
                    .withPojos(true)
                    .withPojosEqualsAndHashCode(true)
                    .withPojosToString(true)
                    .withDaos(true)
            )
            .withDatabase(
                new Database()
                    .withName("org.jooq.meta.mariadb.MariaDBDatabase")
                    .withIncludes(".*")
                    .withExcludes("")
                    .withInputSchema("name-db")
            )
            .withTarget(
                new Target()
                    .withPackageName("model.pack")
                    .withDirectory("model/")
            )
        );

GenerationTool.generate(configuration);

From what I understand I have to create a class that extends “DefaultGeneratorStrategy” with the override on the “getJavaClassName” method

Advertisement

Answer

From the way you phrased this last part:

From what I understand I have to create a class that extends “DefaultGeneratorStrategy” with the override on the “getJavaClassName” method

I take that you’ve already found how to do this, i.e. using a generator strategy, and would like to reach out for someone else to implement it for you, specifically?

Instead, let me offer a simpler approach than the above programmatic strategy, using a configurative one, if this is really only about a class name prefix. Use the matcher strategies:

new Configuration()
  .withGenerator(new Generator()
    .withStrategy(new Strategy()
      .withMatchers(new Matchers()
        .withTables(
          new MatchersTableType()
            .withExpression("MY_TABLE")
            .withPojoClass(new MatcherRule()
              .withTransform(MatcherTransformType.PASCAL)
              .withExpression("PREFIX_$0")
            )
        )
      )
    )
  );
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement