Development versions: | Unsupported versions: 2.6

jOOQ exposes a lot of interfaces and hides most implementation facts from client code. The reasons for this are:

  • Interface-driven design. This allows for modelling queries in a fluent API most efficiently
  • Reduction of complexity for client code.
  • API guarantee. You only depend on the exposed interfaces, not concrete (potentially dialect-specific) implementations.

The org.jooq.impl.Factory class is the main class from where you will create all jOOQ objects. The Factory serves two types of purposes:

The static Factory API

With jOOQ 2.0, static factory methods have been introduced in order to make client code look more like SQL. Ideally, when working with jOOQ, you will simply static import all methods from the Factory class:

import static org.jooq.impl.Factory.*;

Note, that when working with Eclipse, you could also add the Factory to your favourites. This will allow to access functions even more fluently:

concat(trim(FIRST_NAME), trim(LAST_NAME));
// ... which is in fact the same as:
Factory.concat(Factory.trim(FIRST_NAME), Factory.trim(LAST_NAME));

The Factory as a Configuration object

As any Configuration object, a Factory can be supplied with these objects:

  • org.jooq.SQLDialect : The dialect of your database. This may be any of the currently supported database types (see SQL Dialect for more details)
  • java.sql.Connection : An optional JDBC Connection that will be re-used for the whole lifecycle of your Factory (see Connection vs. DataSource for more details)
  • java.sql.DataSource : An optional JDBC DataSource that will be re-used for the whole lifecycle of your Factory. If you prefer using DataSources over Connections, jOOQ will internally fetch new Connections from your DataSource, conveniently closing them again after query execution. This is particularly useful in J2EE or Spring contexts (see Connection vs. DataSource for more details)
  • org.jooq.conf.Settings : An optional runtime configuration (see Custom Settings for more details)

As a Configuration object, a Factory can construct statements, for later execution. An example is given here:

// The Factory is "configured" with a Connection and a SQLDialect
Factory create = new Factory(connection, dialect);

// This select statement contains an internal reference to the Factory:
Select<?> select = create.selectOne();

// Using the internally referenced Factory, the select statement can now be executed:
Result<?> result = select.fetch();
The jOOQ Logo