jOOQ Extension for Quarkus
jOOQ generates Java code from your database and lets you build type safe SQL queries through its fluent API.
This extension allows you to develop applications that interact with the supported databases using jOOQ.
Contributors ✨
The is extension is based on the prior work by @leotu - quarkus-ext-jooq
Thanks goes to these wonderful people (emoji key):
Tim King 💻 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Configuration
After configuring quarkus BOM
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${insert.newest.quarkus.version.here}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
You can just configure the quarkus-jooq
extension by adding the following dependency:
<dependency>
<groupId>io.quarkiverse.jooq</groupId>
<artifactId>quarkus-jooq</artifactId>
<version>${latest.release.version}</version>
</dependency>
Usage
The default DSL context can then be injected with:
# default datasource
quarkus.datasource.db-kind=h2
quarkus.datasource.username=username-default
quarkus.datasource.password=username-default
quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost:19092/mem:default;DATABASE_TO_UPPER=FALSE;
quarkus.datasource.jdbc.min-size=1
quarkus.datasource.jdbc.max-size=2
# default jOOQ datasource
quarkus.jooq.dialect=H2
The default org.jooq.DSLContext
can then be injected:
@Inject
DSLContext dsl; // default
Custom Configuration
Update the configuration with a reference to a named dependency to inject:
# Using custom jOOQ configuration injection
quarkus.jooq.configuration-inject=myCustomConfiguration
Then provide the custom configuration in the apply method.
@ApplicationScoped
public class MyCustomConfigurationFactory {
private static final Logger LOGGER = Logger.getLogger(MyCustomConfigurationFactory.class);
@ApplicationScoped
@Produces
@Named("myCustomConfiguration")
public JooqCustomContext create() {
LOGGER.debug("MyCustomConfigurationFactory: create");
return new JooqCustomContext() {
@Override
public void apply(Configuration configuration) {
// Custom configuration here...
}
};
}
}
Alternatively, using a qualified class that implements io.quarkiverse.jooq.runtime.JooqCustomContext
:
# Using custom jOOQ configuration
quarkus.jooq.configuration=io.quarkiverse.jooq.MyCustomConfiguration
Then provide the custom configuration in the apply method.
public class MyCustomConfiguration implements JooqCustomContext {
@Override
public void apply(Configuration configuration) {
// Custom configuration here...
}
}
Multiple Datasources
Multiple data sources can be configured using named data sources as follows:
# named data source
quarkus.datasource.datasource1.db-kind=h2
quarkus.datasource.datasource1.username=username1
quarkus.datasource.datasource1.password=username1
quarkus.datasource.datasource1.jdbc.url=jdbc:h2:tcp://localhost:19092/mem:datasource1;DATABASE_TO_UPPER=FALSE;
quarkus.datasource.datasource1.jdbc.min-size=1
quarkus.datasource.datasource1.jdbc.max-size=2
# jOOQ configuration referencing the named data source
quarkus.jooq.dsl1.dialect=H2
quarkus.jooq.dsl1.datasource=datasource1
quarkus.jooq.dsl1.configuration=io.quarkiverse.jooq.MyCustomConfiguration1
Native Mode Support
Native compilation is supported in the standard Quarkus way using:
./mvnw package -Pnative
jOOQ Commercial Distributions
Only the Open Source version of jOOQ is supported as an automated build target at this time because of the lack of access to the pro jars at build time.
In order to build use the jOOQ commercial features the extension must be built by the license holder. This can be done by:
- Adding the commercial jOOQ jars to a private maven repository
- Configuring settings.xml with the access details, for example:
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
<profile>
<id>jooq-pro</id>
<repositories>
<repository>
<id>[REPO_ID]</id>
<name>[REPO_NAME]</name>
<url>[REPO_URL]</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>[REPO_ID]</id>
<username>[USERNAME]</username>
<password>[PASSWORD]</password>
</server>
</servers>
</settings>
- Building the extension:
cd [EXTENSION_HOME]/quarkus-jooq-pro
mvn clean install -Pjooq-pro
- Optionally release the artifacts to the private maven repository for use elsewhere and import into your project:
<dependency>
<groupId>io.quarkiverse.jooq.pro</groupId>
<artifactId>quarkus-jooq</artifactId>
<version>${quarkus-jooq-pro.version}</version>
</dependency>