Module org.jooq
Package org.jooq

Interface Scope

All Known Subinterfaces:
BindContext, BindingGetResultSetContext<U>, BindingGetSQLInputContext<U>, BindingGetStatementContext<U>, BindingRegisterContext<U>, BindingScope, BindingSetSQLOutputContext<U>, BindingSetStatementContext<U>, BindingSQLContext<U>, CacheContext, CloseableDSLContext, Context<C>, DSLContext, ExecuteContext, ExecuteScope, GeneratorContext<R,X,T>, Meta, Migration, MigrationContext, ParseContext, 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 of Scope. Examples of such scope types are:

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");
     }
 }
 
Author:
Lukas Eder
  • Method Details

    • creationTime

      @NotNull @NotNull Instant creationTime()
      The time, according to Configuration.clock(), when this Scope was created.
    • configuration

      @NotNull @NotNull Configuration configuration()
      The configuration of the current scope.
    • dsl

      @NotNull @NotNull DSLContext dsl()
      Wrap the configuration() in a DSLContext, 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()
      The SQLDialect wrapped by this context.

      This method is a convenient way of accessing configuration().dialect().

    • family

      @NotNull @NotNull SQLDialect family()
      The SQLDialect.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 this 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.

      Returns:
      The custom data. This is never null
    • data

      @Nullable @Nullable Object data(Object key)
      Get some custom data from this 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

      Parameters:
      key - A key to identify the custom data
      Returns:
      The custom data or null if no such data is contained in this Scope
    • data

      @Nullable @Nullable Object data(Object key, Object value)
      Set some custom data to this 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.

      Parameters:
      key - A key to identify the custom data
      value - The custom data
      Returns:
      The previously set custom data or null if no data was previously set for the given key