All versions: 3.11 | 3.10 | 3.9 | Development versions: 3.12

These configuration elements combine two features in one:

  1. They allow for specifying one or more catalogs (default: all catalogs) as well as one or more schemas (default: all schemas) for inclusion in the code generator. This works in a similar fashion as the includes and excludes elements, but it is applied on an earlier stage.
  2. Once all "input" catalogs and schemas are specified, they can each be associated with a matching "output" catalog or schema, in case of which the "input" will be mapped to the "output" by the code generator. For more details about this, please refer to the manual section about schema mapping.

There are two ways to operate "input" and "output" catalogs and schemas configurations: "top level" and "nested". Note that catalogs are only supported in very few databases, so usually, users will only use the "input" and "output" schema feature.

Top level configurations

This mode is preferrable for small projects or quick tutorials, where only a single catalog and a/or a single schema need to be generated. In this case, the following "top level" configuration elements can be applied:

XML configuration (standalone and Maven)

<!-- Read only a single schema (from all catalogs, but in most databases, there is only one "default catalog") -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <inputSchema>my_schema</inputSchema>
    </database>
  </generator>
</configuration>

<!-- Read only a single catalog and all its schemas -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <inputCatalog>my_catalog</inputCatalog>
    </database>
  </generator>
</configuration>

<!-- Read only a single catalog and only a single schema -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <inputCatalog>my_catalog</inputCatalog>
      <inputSchema>my_schema</inputSchema>
    </database>
  </generator>
</configuration>

Programmatic configuration

configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withInputCatalog("my_catalog")
      .withInputSchema("my_schema"))));

Gradle configuration

myConfigurationName(sourceSets.main) {
  generator {
    database {
      inputCatalog = 'my_catalog'
      inputSchema = 'my_schema'
    }
  }
}

Nested configurations

This mode is preferrable for larger projects where several catalogs and/or schemas need to be included. The following examples show different possible configurations:

XML configuration (standalone and Maven)

<!-- Read two schemas (from all catalogs, but in most databases, there is only one "default catalog") -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <schemata>
        <schema>
          <inputSchema>schema1</inputSchema>
        </schema>
        <schema>
          <inputSchema>schema2</inputSchema>
        </schema>
      </schemata>
    </database>
  </generator>
</configuration>

<!-- Read two catalogs and all their schemas -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <catalogs>
        <catalog>
          <inputCatalog>catalog1</inputCatalog>
        </catalog>
        <catalog>
          <inputCatalog>catalog2</inputCatalog>
        </catalog>
      </catlogs>
    </database>
  </generator>
</configuration>

<!-- Read two schemas from one specific catalog -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <catalogs>
        <catalog>
          <inputCatalog>catalog</inputCatalog>
          <schemata>
            <schema>
              <inputSchema>schema1</inputSchema>
            </schema>
            <schema>
              <inputSchema>schema2</inputSchema>
            </schema>
          </schemata>
        </catalog>
      </catlogs>
    </database>
  </generator>
</configuration>

Programmatic configuration

// Two schemas from any catalog
configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withSchemata(
        new Schema().withInputSchema("schema1"),
        new Schema().withInputSchema("schema2")))));

// All schemas from two catalogs
configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withCatalogs(
        new Catalog().withInputCatalog("catalog1"),
        new Catalog().withInputCatalog("catalog2")))));

// Two schemas from a specific catalog
configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withCatalogs(new Catalog()
        .withInputCatalog("catalog")
        .withSchemata(
          new Schema().withInputSchema("schema1"),
          new Schema().withInputSchema("schema2"))))));

Gradle configuration

// Two schemas from any catalog
myConfigurationName(sourceSets.main) {
  generator {
    database {
      schemata {
        schema {
          inputSchema = 'schema1'
        }
        schema {
          inputSchema = 'schema2'
        }
      }
    }
  }
}

// All schemas from two catalogs
myConfigurationName(sourceSets.main) {
  generator {
    database {
      catalogs {
        catalog {
          inputCatalog = 'catalog1'
        }
        catalog {
          inputCatalog = 'catalog2'
        }
      }
    }
  }
}

// Two schemas from a specific catalog
myConfigurationName(sourceSets.main) {
  generator {
    database {
      catalogs {
        catalog {
          inputCatalog = 'catalog'
          schemata {
            schema {
              inputSchema = 'schema1'
            }
            schema {
              inputSchema = 'schema2'
            }
          }
        }
      }
    }
  }
}

Catalog and schema mapping

Wherever you can place an inputCatalog or inputSchema element (top level or nested), you can also put a matching mapping instruction, if you wish to profit from the catalog and schema mapping feature. The following configurations are possible:

XML configuration (standalone and Maven)

<!-- Map input names to a concrete output name: -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <inputCatalog>my_input_catalog</inputCatalog>
      <outputCatalog>my_output_catalog</outputCatalog>
      <inputSchema>my_input_schema</inputSchema>
      <outputSchema>my_output_schema</outputSchema>
    </database>
  </generator>
</configuration>

<!-- Map input names to the "default" catalog or schema (i.e. no name): -->
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
  <generator>
    <database>
      <inputCatalog>my_input_catalog</inputCatalog>
      <outputCatalogToDefault>true</outputCatalogToDefault>
      <inputSchema>my_input_schema</inputSchema>
      <outputSchemaToDefault>true</outputSchemaToDefault>
    </database>
  </generator>
</configuration>

Programmatic configuration

// Map input names to a concrete output name:
configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withInputCatalog("my_input_catalog")
      .withOutputCatalog("my_output_catalog")
      .withInputSchema("my_input_schema")
      .withOutputSchema("my_output_schema"))));

// Map input names to the "default" catalog or schema (i.e. no name):
configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withInputCatalog("my_input_catalog")
      .withOutputCatalogToDefault(true)
      .withInputSchema("my_input_schema")
      .withOutputSchemaToDefault(true))));

Gradle configuration

// Map input names to a concrete output name:
myConfigurationName(sourceSets.main) {
  generator {
    database {
      inputCatalog = 'my_input_catalog'
      outputCatalog = 'my_output_catalog'
      inputSchema = 'my_input_schema'
      outputSchema = 'my_output_schema'
    }
  }
}

// Map input names to the "default" catalog or schema (i.e. no name):
myConfigurationName(sourceSets.main) {
  generator {
    database {
      inputCatalog = 'my_input_catalog'
      outputCatalogToDefault = true
      inputSchema = 'my_input_schema'
      outputSchemaToDefault = true
    }
  }
}

For more information about the catalog and schema mapping feature, please refer to the relevant section of the manual.

The jOOQ Logo