Available in versions: Dev (3.19) | Latest (3.18) | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10 | 3.9
Programmatic generator configuration
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Configuring your code generator with Java, Groovy, etc.
In the previous sections, we have covered how to set up jOOQ's code generator using XML, either by running a standalone Java application, or by using Maven. However, it is also possible to use jOOQ's GenerationTool
programmatically. The XSD file used for the configuration (https://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd) is processed using XJC to produce Java artefacts. The below example uses those artefacts to produce the equivalent configuration of the previous PostgreSQL / Maven example:
// Use the fluent-style API to construct the code generator configuration import org.jooq.util.jaxb.*; // [...] Configuration configuration = new Configuration() .withJdbc(new Jdbc() .withDriver("org.postgresql.Driver") .withUrl("jdbc:postgresql:postgres") .withUser("postgres") .withPassword("test")) .withGenerator(new Generator() .withDatabase(new Database() .withName("org.jooq.util.postgres.PostgresDatabase") .withIncludes(".*") .withExcludes("") .withInputSchema("public")) .withTarget(new Target() .withPackageName("org.jooq.util.maven.example") .withDirectory("target/generated-sources/jooq"))); GenerationTool.generate(configuration);
For the above example, you will need all of jooq-3.10.8.jar, jooq-meta-3.10.8.jar, and jooq-codegen-3.10.8.jar, on your classpath.
Manually loading the XML file
Alternatively, you can also load parts of the configuration from an XML file using JAXB and programmatically modify other parts using the code generation API:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <configuration> <jdbc> <driver>org.h2.Driver</driver> <!-- ... --> </jdbc> </configuration>
Load the above using standard JAXB API:
import java.io.File; import javax.xml.bind.JAXB; import org.jooq.utils.jaxb.Configuration; // [...] // and then Configuration configuration = JAXB.unmarshal(new File("jooq.xml"), Configuration.class); configuration.getJdbc() .withUser("username") .withPassword("password"); GenerationTool.generate(configuration);
... and then, modify parts of your configuration programmatically, for instance the JDBC user / password:
References to this page
- Configuration and setup of the generator
- Logging
- Jdbc
- Generator
- Database name and properties
- RegexFlags
- Includes and Excludes
- Include object types
- Record Version and Timestamp Fields
- Synthetic identities
- Synthetic primary keys
- Override primary keys
- Date as timestamp
- Ignore procedure return values (deprecated)
- Unsigned types
- Catalog and schema mapping
- Catalog and schema version providers
- Custom ordering of generated code
- Matching of forced types
- Data type rewriting
- Qualified converters
- Inline converters
- Enum converters
- Data type bindings
- Table valued functions
- Annotations
- Fluent setters
- Fully Qualified Types
- Global Artefacts
- Java Time Types
- Output target configuration
- Custom generator strategies
- Matcher strategies
- MatcherRule
- Matching schemas
- Matching tables
- Matching fields
- Matching routines
- Matching sequences
- Matcher examples
- Generated Interfaces
- Generated DAOs
- Generated sequences
- Generated procedures
- Generated UDTs
- Mapping generated catalogs and schemas
- JPADatabase: Code generation from entities
- XMLDatabase: Code generation from XML files
- DDLDatabase: Code generation from SQL files
- XMLGenerator: Generating XML
- Oracle DATE data type
Feedback
Do you have any feedback about this page? We'd love to hear it!