Search code examples
databasedynamicjooqcatalog

Dynamically change catalog name in jOOQ


My database instance name is different between multiple environments - how can the catalog name in jOOQ be assigned dynamically?

There doesn't seem to dynamically assign the catalog name for the generated class extends CatalogImpl.

private MyDatabase() {
    super("DatabaseInstanceName");
}

Using jOOQ trial 3.8.3. Currently using SQLSERVER and H2 dialects. Thanks.


Solution

  • Code generation support for Catalog (which corresponds to SQL Server's database) was added to jOOQ in version 3.8 (issue #2032). Thus far, it is not yet possible to apply any mapping between catalogs. This feature is on the roadmap (probably for version 3.9):

    Until then, you can turn off the rendering of catalog names in generated SQL by specifying Settings.renderCatalog. More information about jOOQ's Settings can be found here: http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings