A Brief Overview over the Most Common jOOQ Types
For new users working with jOOQ for the first time, the number of types in the jOOQ API can be overwhelming. The SQL language doesn’t have many such “visible” types, although if you think about SQL the way jOOQ does, then they’re there just the same, but hidden from users via an English style syntax. … Continue reading A Brief Overview over the Most Common jOOQ Types →
A Brief Overview over the Most Common jOOQ Types
Posted on September 6, 2022November 13, 2024 by lukaseder
This overview will list the most important jOOQ types in a cheat sheet form.
Configuration types
The Configuration is the single most important configuration type, which contains references to all other types of configuration, Settings, custom SPI implementations, JDBC or R2DBC Connection, etc. SPIs include:
- The
ConnectionProviderthat defines the semantics ofConnectionProvider.acquire()) andConnectionProvider.release(Connection)) for all queries executed in the context of thisConfiguration.
- A set of
ExecuteListenerProviderthat implementQueryexecution lifecycle management.
- The
RecordMapperProviderthat defines and implements the behaviour ofRecord.into(Class)),ResultQuery.fetchInto(Class)),Cursor.fetchInto(Class)), and various related methods.
And many more, which you can see from the Configuration Javadoc
It is made available from every Scope type in the API, see below for details
Scopes
The Scope types are various types that are created “in the scope” of a Configuration, and as such can provide access to all of the Configuration‘s contained objects and SPIs. This design allows for extremely flexible, programmatic dependency injection throughout the internals of jOOQ. Some of the most important Scope types include:
Context: Used for a single traversal of aQueryPartexpression tree to produce a SQL string and / or a list of bind variables.
DSLContext: TheDSLAPI that createsQueryinstances in the context of aConfiguration. It shares the wrappedConfiguration‘s lifecycle.
ExecuteContext: Used for a single execution of aQuery, containing JDBC resources and other execution relevant objects. Can be accessed by theExecuteListenerSPI.
For other types, refer to the Scope Javadoc.
Settings
Settings are mostly scalar flags that specify detailed behaviour in jOOQ. Some select examples include:
Settings.executeLogging: To turn on/off the built in execute logging in jOOQ
Settings.fetchSize: To specify the default JDBCfetchSizeon the createdStatementandPreparedStatement
Settings.statementType: Whether to executeStatementorPreparedStatementto run your queries.
As of jOOQ 3.17, there are over 160 such settings, so we can’t list them all here. For more details, refer to the Settings Javadoc.
DSL types
The DSL API is the most important API to work with jOOQ. It comes in 2 flavours.
The static DSL
The static DSL contains entry points to every type of QueryPart construction DSLs, including:
Querytypes
Fieldtypes
Conditiontypes
Tabletypes
… and a lot more. All of these types are constructed statically, and as such, they do not have any Configuration attached.
The “context” DSL
The “context” DSL, represented by the DSLContext type, only offers constructing QueryPart types that profit from being created “in the context” of a Configuration. This is mainly just including:
Querytypes
A Query that has been constructed from the DSLContext type can be executed directly by using Query.execute()) or ResultQuery.fetch()), or many other execution methods, including asynchronous or reactive ones.
Step types
Throughout the DSL API, you will see so-called “Step” types, i.e. types with a “Step” suffix, such as e.g. SelectFromStep, which is the “Step” that gives access to the Select DSL’s FROM clause.
You should never reference these types directly, nor see them in your own code. They are intermediate DSL artifacts
QueryPart types
QueryPart is the common base type of the entire jOOQ expression tree, or model API. Every type that you construct with the DSL API will extend QueryPart, for example:
[...]
---
*[Original source](https://blog.jooq.org/a-brief-overview-over-the-most-common-jooq-types/)*