jOOQ

jOOQ

jOOQ generates Java code from your database and lets you build type safe SQL queries through its fluent API.

NOTE: This module depends on jdbc module.

exports

  • DSLContext

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-jooq</artifactId>
 <version>1.6.6</version>
</dependency>

usage

{
  use(new Jdbc());
  use(new jOOQ());

  get("/jooq", req -> {

    try (DSLContext ctx = require(DSLContext.class)) {
      return ctx.transactionResult(conf -> {
        DSLContext trx = DSL.using(conf);
        return trx.selectFrom(TABLE)
            .where(ID.eq(1))
            .fetchOne(NAME);
      });
    }
  });

}

multiple db connections

{
  use(new Jdbc("db.main"));
  use(new jOOQ("db.main"));

  use(new Jdbc("db.audit"));
  use(new jOOQ("db.audit"));

  get("/main", req -> {

    try (DSLContext ctx = require("db.main", DSLContext.class)) {
      ...
    }
  });

  get("/audit", req -> {

    try (DSLContext ctx = require("db.audit", DSLContext.class)) {
      ...
    }
  });

}

advanced configuration

This module setup a Configuration object with a DataSource from jdbc module and the DefaultTransactionProvider. More advanced configuration is provided via #doWith(BiConsumer):

{
  use(new Jdbc());
  use(new jOOQ().doWith(conf -> {

    conf.set(...);
  });

}

code generation

Unfortunately, this module doesn’t provide any built-in facility for code generation. If you need help to setup the code generator please checkout the jOOQ documentation for more information.