public interface Scope
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:
ExecuteContext
: A scope that covers a single execution of a
Query
Context
: A scope that covers a single traversal of a
QueryPart
expression tree to produce a SQL string and / or a list of
bind variables.VisitContext
: A scope that that covers a single traversal of a
QueryPart
expression tree (just like Context
), in the
presence of at least one VisitListener
.RecordContext
: A scope that covers a single record operation,
such as UpdatableRecord.store()
.TransactionContext
: A scope that covers the execution (or
nesting) of a single transaction.
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 |
---|---|
Configuration |
configuration()
The configuration of the current scope.
|
Map<Object,Object> |
data()
Get all custom data from this
Scope . |
Object |
data(Object key)
Get some custom data from this
Scope . |
Object |
data(Object key,
Object value)
Set some custom data to this
Scope . |
SQLDialect |
dialect()
The
SQLDialect wrapped by this context. |
DSLContext |
dsl()
Wrap the
configuration() in a DSLContext , providing
access to the configuration-contextual DSL to construct executable
queries. |
SQLDialect |
family()
The
SQLDialect.family() wrapped by this context. |
Settings |
settings()
The settings wrapped by this context.
|
Configuration configuration()
DSLContext dsl()
configuration()
in a DSLContext
, providing
access to the configuration-contextual DSL to construct executable
queries.Settings settings()
This method is a convenient way of accessing
configuration().settings()
.
SQLDialect dialect()
SQLDialect
wrapped by this context.
This method is a convenient way of accessing
configuration().dialect()
.
SQLDialect family()
SQLDialect.family()
wrapped by this context.
This method is a convenient way of accessing
configuration().dialect().family()
.
Map<Object,Object> data()
Scope
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given Scope
.
null
Object data(Object key)
Scope
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given Scope
key
- A key to identify the custom datanull
if no such data is contained
in this Scope
Object data(Object key, Object value)
Scope
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given Scope
.
key
- A key to identify the custom datavalue
- The custom datanull
if no data
was previously set for the given keyCopyright © 2019. All rights reserved.