Giter Club home page Giter Club logo

quarkus-jooq's Introduction

jOOQ Extension for Quarkus

All Contributors

Build Maven Central License

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
Tim King

๐Ÿ’ป ๐Ÿšง
Bois Pierre-Antoine
Bois Pierre-Antoine

๐Ÿ’ป ๐Ÿšง
Ashish Ranjan
Ashish Ranjan

๐Ÿ’ป ๐Ÿšง

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>

quarkus-jooq's People

Contributors

actions-user avatar allcontributors[bot] avatar angrymango avatar dependabot[bot] avatar duvel avatar gastaldi avatar gsmet avatar maxandersen avatar nasibsa avatar oscerd avatar ranjanashish avatar sirz3chs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.