-
- All Known Subinterfaces:
BindContext
,BindingGetResultSetContext<U>
,BindingGetSQLInputContext<U>
,BindingGetStatementContext<U>
,BindingRegisterContext<U>
,BindingSetSQLOutputContext<U>
,BindingSetStatementContext<U>
,BindingSQLContext<U>
,CloseableDSLContext
,Context<C>
,DSLContext
,ExecuteContext
,Meta
,Migration
,MigrationContext
,RecordContext
,RenderContext
,ResourceManagingScope
,TransactionContext
,VisitContext
- All Known Implementing Classes:
DefaultCloseableDSLContext
,DefaultDSLContext
public interface Scope
Scope implementations provide access to a variety of objects that are available from a given 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 ofScope
. Examples of such scope types are:ExecuteContext
: A scope that covers a single execution of aQuery
Context
: A scope that covers a single traversal of aQueryPart
expression tree to produce a SQL string and / or a list of bind variables.VisitContext
: A scope that that covers a single traversal of aQueryPart
expression tree (just likeContext
), in the presence of at least oneVisitListener
.RecordContext
: A scope that covers a single record operation, such asUpdatableRecord.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 thedata()
map, which provides access to aMap
where client code can register user-defined values for the entire lifetime of a scope. For instance, in anExecuteListener
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"); } }
- Author:
- Lukas Eder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @NotNull Configuration
configuration()
The configuration of the current scope.@NotNull Map<Object,Object>
data()
Get all custom data from thisScope
.@Nullable Object
data(Object key)
Get some custom data from thisScope
.@Nullable Object
data(Object key, Object value)
Set some custom data to thisScope
.@NotNull SQLDialect
dialect()
TheSQLDialect
wrapped by this context.@NotNull DSLContext
dsl()
Wrap theconfiguration()
in aDSLContext
, providing access to the configuration-contextual DSL to construct executable queries.@NotNull SQLDialect
family()
TheSQLDialect.family()
wrapped by this context.@NotNull Settings
settings()
The settings wrapped by this context.
-
-
-
Method Detail
-
configuration
@NotNull @NotNull Configuration configuration()
The configuration of the current scope.
-
dsl
@NotNull @NotNull DSLContext dsl()
Wrap theconfiguration()
in aDSLContext
, providing access to the configuration-contextual DSL to construct executable queries.
-
settings
@NotNull @NotNull Settings settings()
The settings wrapped by this context.This method is a convenient way of accessing
configuration().settings()
.
-
dialect
@NotNull @NotNull SQLDialect dialect()
TheSQLDialect
wrapped by this context.This method is a convenient way of accessing
configuration().dialect()
.
-
family
@NotNull @NotNull SQLDialect family()
TheSQLDialect.family()
wrapped by this context.This method is a convenient way of accessing
configuration().family()
.
-
data
@NotNull @NotNull Map<Object,Object> data()
Get all custom data from thisScope
.This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data toQueryPart
objects for a givenScope
.- Returns:
- The custom data. This is never
null
-
data
@Nullable @Nullable Object data(Object key)
Get some custom data from thisScope
.This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data toQueryPart
objects for a givenScope
- Parameters:
key
- A key to identify the custom data- Returns:
- The custom data or
null
if no such data is contained in thisScope
-
data
@Nullable @Nullable Object data(Object key, Object value)
Set some custom data to thisScope
.This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data toQueryPart
objects for a givenScope
.- Parameters:
key
- A key to identify the custom datavalue
- The custom data- Returns:
- The previously set custom data or
null
if no data was previously set for the given key
-
-