Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

Matcher strategies

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Using custom matcher strategies

In the previous section, we have seen how to override generator strategies programmatically. In this chapter, we'll see how such strategies can be configured in the XML or Maven code generator configuration. Instead of specifying a strategy name, you can also specify a <matchers/> element as explained in the following subsections.

The generic structure of such matchers looks as follows:

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <!-- These properties can be added directly to the generator element: -->
  <generator>
    <strategy>
      <matchers>

        <tables>
          <table>

            <!-- Match unqualified or qualified table names. If left empty, this matcher applies to all tables. -->
            <expression>MY_TABLE</expression>

            <!-- These elements influence the naming of a generated org.jooq.Table object. -->
            <tableClass> a MatcherRule specification </tableClass>
            <tableIdentifier> a MatcherRule specification </tableIdentifier>
            <tableExtends>com.example.MyOptionalTableBaseType</tableExtends>
            <tableImplements>com.example.MyOptionalCustomInterface</tableImplements>
          </table>
        </tables>
      </matchers>
    </strategy>
  </generator>
</configuration>

See the configuration XSD, standalone code generation, and maven code generation for more details.

new org.jooq.meta.jaxb.Configuration()

  // These properties can be added directly to the generator element:
  .withGenerator(new Generator()
    .withStrategy(new Strategy()
      .withMatchers(new Matchers()
        .withTables(
          new MatchersTableType()

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            .withExpression("MY_TABLE")

            // These elements influence the naming of a generated org.jooq.Table object.
            .withTableClass(MatcherRule. a MatcherRule specification )
            .withTableIdentifier(MatcherRule. a MatcherRule specification )
            .withTableExtends("com.example.MyOptionalTableBaseType")
            .withTableImplements("com.example.MyOptionalCustomInterface")
        )
      )
    )
  )

See the configuration XSD and programmatic code generation for more details.

import org.jooq.meta.jaxb.*


configuration {

  // These properties can be added directly to the generator element:
  generator {
    strategy {
      matchers {
        tables {
          table {

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            expression = "MY_TABLE"

            // These elements influence the naming of a generated org.jooq.Table object.
            tableClass = MatcherRule. a MatcherRule specification 
            tableIdentifier = MatcherRule. a MatcherRule specification 
            tableExtends = "com.example.MyOptionalTableBaseType"
            tableImplements = "com.example.MyOptionalCustomInterface"
          }
        }
      }
    }
  }
}

See the configuration XSD and gradle code generation for more details.

configuration {

  // These properties can be added directly to the generator element:
  generator {
    strategy {
      matchers {
        tables {
          table {

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            expression = "MY_TABLE"

            // These elements influence the naming of a generated org.jooq.Table object.
            tableClass = " a MatcherRule specification "
            tableIdentifier = " a MatcherRule specification "
            tableExtends = "com.example.MyOptionalTableBaseType"
            tableImplements = "com.example.MyOptionalCustomInterface"
          }
        }
      }
    }
  }
}

See the configuration XSD and gradle code generation for more details.

generationTool {

  // These properties can be added directly to the generator element:
  generator {
    strategy {
      matchers {
        tables {
          table {

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            expression = "MY_TABLE"

            // These elements influence the naming of a generated org.jooq.Table object.
            tableClass = " a MatcherRule specification "
            tableIdentifier = " a MatcherRule specification "
            tableExtends = "com.example.MyOptionalTableBaseType"
            tableImplements = "com.example.MyOptionalCustomInterface"
          }
        }
      }
    }
  }
}

See the configuration XSD and gradle code generation for more details.

As always, when regular expressions are used, they are regular expressions with default flags.

A matcher configuration element can be any of these things:

  • A regular expression matching an identifier
  • A org.jooq.meta.jaxb.MatcherRule specification (see MatcherRule)
  • A constant value
All regular expressions that match object identifiers try to match identifiers first by unqualified name (org.jooq.meta.Definition.getName()), then by qualified name (org.jooq.meta.Definition.getQualifiedName()).
When using any recordExtends, tableExtends, etc. setting, you must make sure to correctly implement the internal jOOQ APIs, which are not documented here for they are internal. In particular, if you're extending org.jooq.impl.TableImpl, for example, your custom base class may break between minor versions of jOOQ, as new constructors are added.

The following sections explain the above more in detail:

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo