Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10
The DSLContext API
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
DSLContext references a org.jooq.Configuration
, an object that configures jOOQ's behaviour when executing queries (see SQL execution for more details). Unlike the static DSL, the DSLContext allow for creating SQL statements that are already "configured" and ready for execution.
Fluent creation of a DSLContext object
The DSLContext object can be created fluently from the DSL type:
// Create it from a pre-existing configuration DSLContext create = DSL.using(configuration); // Create it from ad-hoc arguments DSLContext create = DSL.using(connection, dialect);
If you do not have a reference to a pre-existing Configuration object (e.g. created from org.jooq.impl.DefaultConfiguration
), the various overloaded DSL.using()
methods will create one for you.
Contents of a Configuration object
A Configuration 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) -
org.jooq.conf.Settings
: An optional runtime configuration (see Custom Settings for more details) -
org.jooq.ExecuteListenerProvider
: To provide execution lifecycle listeners (see ExecuteListeners for more details) -
org.jooq.ParseListenerProvider
: To provide custom parser extensions (see SQL Parser Listener for more details) -
org.jooq.RecordListenerProvider
: To provide record listeners for your CRUD operations (see CRUD SPI: RecordListener for more details) -
org.jooq.RecordMapperProvider
: To provide an alternative default record mapper implementation (see for more details) -
org.jooq.FormattingProvider
: To provide custom default data export formats (see FormattingProvider for more details) - JDBC access:
-
java.sql.Connection
: An optional JDBC Connection that will be re-used for the whole lifecycle of your Configuration (see Connection vs. DataSource for more details). For simplicity, this is the use-case referenced from this manual, most of the time. -
java.sql.DataSource
: An optional JDBC DataSource that will be re-used for the whole lifecycle of your Configuration. 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 Java EE or Spring contexts (see Connection vs. DataSource for more details) -
org.jooq.ConnectionProvider
: A custom abstraction that is used by jOOQ to "acquire" and "release" connections. jOOQ will internally "acquire" new Connections from your ConnectionProvider, conveniently "releasing" them again after query execution. (see Connection vs. DataSource for more details)
-
- R2DBC access:
-
io.r2dbc.spi.Connection
: An optional R2DBC Connection that will be re-used for the whole lifecycle of your Configuration (see Connection vs. DataSource for more details). For simplicity, this is the use-case referenced from this manual, most of the time. -
io.r2dbc.spi.ConnectionFactory
: An optional R2DBC ConnectionFactory that will be re-used for the whole lifecycle of your Configuration. If you prefer using ConnectionFactories over Connections, jOOQ will internally fetch new Connections from your ConnectionFactory, conveniently closing them again after query execution. This is particularly useful in Spring contexts (see Connection vs. DataSource for more details)
-
Usage of DSLContext
Wrapping a Configuration object, a DSLContext can construct statements, for later execution. An example is given here:
// The DSLContext is "configured" with a Connection and a SQLDialect DSLContext create = DSL.using(connection, dialect); // This select statement contains an internal reference to the DSLContext's Configuration: Select<?> select = create.selectOne(); // Using the internally referenced Configuration, the select statement can now be executed: Result<?> result = select.fetch();
Note that you do not need to keep a reference to a DSLContext. You may as well inline your local variable, and fluently execute a SQL statement as such:
// Execute a statement from a single execution chain: Result<?> result = DSL.using(connection, dialect) .select() .from(BOOK) .where(BOOK.TITLE.like("Animal%")) .fetch();
Table of contents
- 3.2.1.
- SQL Dialect
- 3.2.2.
- SQL Dialect Family
- 3.2.3.
- SQL Dialect Category
- 3.2.4.
- Connection vs. DataSource
- 3.2.5.
- Custom data
- 3.2.6.
- Custom ExecuteListeners
- 3.2.7.
- Custom Unwrappers
- 3.2.8.
- Custom Settings
- 3.2.8.1.
- Auto-attach Records
- 3.2.8.2.
- Auto-inline bind values
- 3.2.8.3.
- Backslash Escaping
- 3.2.8.4.
- Batch size
- 3.2.8.5.
- Computed column emulation
- 3.2.8.6.
- Diagnostics Connection
- 3.2.8.7.
- Diagnostics Logging
- 3.2.8.8.
- Dialect compatibility
- 3.2.8.9.
- Dollar quoted string token (new)
- 3.2.8.10.
- Execute Logging
- 3.2.8.11.
- Execute Logging SQL Exceptions
- 3.2.8.12.
- Fetch Warnings
- 3.2.8.13.
- GROUP_CONCAT Configuration
- 3.2.8.14.
- Identifier style
- 3.2.8.15.
- Implicit join type
- 3.2.8.16.
- Inline Threshold
- 3.2.8.17.
- IN-list Padding
- 3.2.8.18.
- Interpreter Configuration
- 3.2.8.19.
- JDBC Flags
- 3.2.8.20.
- Keyword style
- 3.2.8.21.
- Listener Invocation Order
- 3.2.8.22.
- Locales
- 3.2.8.23.
- Map JPA Annotations
- 3.2.8.24.
- Object qualification
- 3.2.8.25.
- Object qualification for columns
- 3.2.8.26.
- Optimistic Locking
- 3.2.8.27.
- Parameter name prefix
- 3.2.8.28.
- Parameter types
- 3.2.8.29.
- Parser Configuration
- 3.2.8.30.
- Readonly column behaviour
- 3.2.8.31.
- Reflection caching
- 3.2.8.32.
- Return all columns on store
- 3.2.8.33.
- Return computed columns on store
- 3.2.8.34.
- Return DEFAULT columns on store
- 3.2.8.35.
- Return Identity Value On Store
- 3.2.8.36.
- Runtime catalog, schema and table mapping
- 3.2.8.37.
- Scalar subqueries for stored functions
- 3.2.8.38.
- SEEK clause implementation
- 3.2.8.39.
- Statement Type
- 3.2.8.40.
- Updatable Primary Keys
- 3.2.9.
- Thread safety
previous : next |
References to this page
- SQL Dialect
- Connection vs. DataSource
- Custom data
- Custom ExecuteListeners
- Auto-attach Records
- Listener Invocation Order
- SQL Parser Listener
- SQL translator
- Serializability
- Configuration
- Security considerations
- RecordMapper
- POJOs
- RecordMapperProvider
- ConverterProvider
- Static statements vs. Prepared Statements
- Sequence execution
- FormattingProvider
- Simple CRUD
- Batch execution
- CRUD SPI: RecordListener
- Transaction management
- ExecuteListeners
- JDBC meta data
- JDBC Connection
- Mocking Connection
- Parsing Connection
- Performance considerations
- jOOQ: Implementing the DSL types
Feedback
Do you have any feedback about this page? We'd love to hear it!