The scope of the various objects contained in this type (e.g.
configuration(), settings(), etc.) are implementation
dependent and will be specified by the concrete subtype of
Scope. Examples of such scope types are:
BindingScope: A scope used for a single Binding
operation.Context: Used for a single traversal of a QueryPart
expression tree to produce a SQL string and / or a list of bind
variables.ConverterContext: A scope that covers a single
ContextConverter#from(Object, ConverterContext) or
ContextConverter#to(Object, ConverterContext) call.DSLContext: The DSL API that creates Query
instances in the context of a Configuration. It shares the wrapped
Configuration's lifecycle.ExecuteContext: Used for a single execution of a Query,
containing JDBC resources and other execution relevant objects. Can be
accessed by the ExecuteListener SPI.ExecuteScope: A scope that is used for operations that are
ExecuteContext aware, but may have a more narrow scope, such as e.g.
BindingScope.GeneratorContext: A scope that is used for client side computed
column expression generation.ParseContext: Used for a single parse call. Can be accessed by
the ParseListener SPI.RecordContext: Used a single record operation, such as
UpdatableRecord#store(). Can be accessed by the
RecordListener SPI.TransactionContext: A scope that covers the execution (or
nesting) of a single transaction. Can be accessed by the
TransactionListener SPI.VisitContext: A scope that that covers a single traversal of a
QueryPart expression tree (just like Context). Can be
accessed by the VisitListener SPI.
One of Scope's most interesting features for client code
implementing any SPI is the data() map, which provides access to a
Map where client code can register user-defined values for the entire
lifetime of a scope. For instance, in an ExecuteListener
implementation that measures time for fetching data, it is perfectly possible
to store timestamps in that map:
class FetchTimeMeasuringListener extends DefaultExecuteListener {
@Override
public void fetchStart(ExecuteContext ctx) {
// Put any arbitrary object in this map:
ctx.data("org.jooq.example.fetch-start-time", System.nanoTime());
}
@Override
public void fetchEnd(ExecuteContext ctx) {
// Retrieve that object again in a later step:
Long startTime = (Long) ctx.data("org.jooq.example.fetch-start-time");
System.out.println("Time taken: " + (System.nanoTime() - startTime) / 1000 / 1000.0 + " ms");
}
}
| Modifier and Type | Method and Description |
|---|---|
| public @NotNull Configuration | |
| public @NotNull Instant | |
| public @NotNull Map | |
| public @Nullable Object | |
| public @Nullable Object | |
| public @NotNull SQLDialect | |
| public @NotNull DSLContext | dsl()
Wrap the |
| public @NotNull SQLDialect | |
| public @NotNull Settings |
| configuration | back to summary |
|---|---|
| public @NotNull Configuration configuration() The configuration of the current scope.
| |
| creationTime | back to summary |
|---|---|
| public @NotNull Instant creationTime() The time, according to
| |
| data | back to summary |
|---|---|
| public @NotNull Map Get all custom data from this
This is custom data that was previously set to the context using
| |
| data | back to summary |
|---|---|
| public @Nullable Object data(Object key) Get some custom data from this
This is custom data that was previously set to the context using
| |
| data | back to summary |
|---|---|
| public @Nullable Object data(Object key, Object value) Set some custom data to this
This is custom data that was previously set to the context using
| |
| dialect | back to summary |
|---|---|
| public @NotNull SQLDialect dialect() The
This method is a convenient way of accessing
| |
| dsl | back to summary |
|---|---|
| public @NotNull DSLContext dsl() Wrap the
| |
| family | back to summary |
|---|---|
| public @NotNull SQLDialect family() The
This method is a convenient way of accessing
| |
| settings | back to summary |
|---|---|
| public @NotNull Settings settings() The settings wrapped by this context.
This method is a convenient way of accessing
| |