Getting Started jOOQ

Maven Central JavaDoc

Setting up the environment

Add the Dependency to your build.

for Maven:

Java 8

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-jooq</artifactId>
    <version>3.13.2</version>
</dependency>

Java 6, 7

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-jooq</artifactId>
    <version>3.13.2</version>
    <classifier>jdk16</classifier>
</dependency>

Java 9

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-jooq</artifactId>
    <version>3.13.2</version>
    <classifier>jdk9ea</classifier>
</dependency>

There are 2 mapping strategies available in jOOQ.

because fetchInto has to go through the Record creation, its use will mainly be when your query does not map to a generated object - i.e. a subset of fields or joins -.

SFM as a RecordMapperProvider

Sfm can be plugged into the fetchInto mapping.

All you need to do is

configuration.set(new SfmRecordMapperProvider()));

when instantiating your DSL. You will then be able to use fetchInto with a cost very close to fetching the record - see the performance section - and the flexibility that SFM offers.

SFM on the ResultSet

Because the RecordMapperProvider works on the record that we don’t need we are not as performant as working directly with the ResultSet. Fortunately, jOOQ allows you to fetch the ResultSet directly avoiding the cost of the transition from ResultSet to Record.

JdbcMapper mapper = JdbcMapperFactory.newInstance().newMapper(MyObject.class);

ResultQuery<MyRecord> query = dsl.select().from(TABLE);
try (ResultSet rs = query.fetchResultSet()) {
    mapper.stream(rs).forEach(System.out::println);
}

That will allow you to get the query generation power of jOOQ and the close to pure Jdbc performance of SimpleFlatMapper.

Joins

The join aggregation is only available when using SFM on the result set as the RecordMapper interface expect one object per row.