Module org.jooq
Package org.jooq

Interface Context<C extends Context<C>>

All Superinterfaces:
ExecuteScope, Scope
All Known Subinterfaces:
BindContext, RenderContext

public interface Context<C extends Context<C>> extends ExecuteScope
A context type that is used for rendering SQL or for binding.

This type implements Scope and thus has a lifecycle defined by the rendering or binding operation.

The Scope.data() map contents are maintained for the entirety of the rendering or binding operation, and are passed along to child Scope types, including e.g.

Author:
Lukas Eder
See Also:
  • Method Details Link icon

    • visit Link icon

      @NotNull C visit(QueryPart part) throws DataAccessException
      Visit a QueryPart in the current Context.

      This method is called by certain QueryPart implementations to recursively visit component QueryParts.

      Parameters:
      part - The component QueryPart
      Throws:
      DataAccessException - If something went wrong while visiting the component QueryPart, e.g. when binding a variable
    • visit Link icon

      @NotNull C visit(Condition part) throws DataAccessException
      Visit a Condition as an ordinary QueryPart.
      Throws:
      DataAccessException
    • visit Link icon

      @NotNull C visit(Field<?> part) throws DataAccessException
      Visit a Field as a DSL.field(Condition), if it is a Condition, or as an ordinery QueryPart, otherwise.

      [#11969] Not all RDBMS support Condition in the form of Field of type Boolean, natively. As such, we must wrap any such Condition using DSL.field(Condition) to make sure the appropriate emulations are implemented. This applies to conditions that are declared as Field, e.g. the arguments of a function like DSL.nvl(Field, Field).

      If a Condition is declared as a condition, then this doesn't apply and visit(Condition) is invoked, instead, e.g. the arguments of AggregateFilterStep.filterWhere(Condition).

      Throws:
      DataAccessException
    • visitSubquery Link icon

      @NotNull C visitSubquery(QueryPart part) throws DataAccessException
      Visit a QueryPart as a subquery in the current Context.

      This method is called by certain QueryPart implementations to recursively visit component QueryParts.

      Parameters:
      part - The component QueryPart
      Throws:
      DataAccessException - If something went wrong while visiting the component QueryPart, e.g. when binding a variable
    • start Link icon

      @NotNull C start(Clause clause)
      TODO [#2667] Properties of these methods: - A clause is always started / ended, even if it isn't rendered or if it's empty!
    • end Link icon

      @NotNull C end(Clause clause)
    • data Link icon

      @NotNull C data(Object key, Object value, Consumer<? super C> consumer)
      Set a data value for a key for the scope of a Consumer.
    • declareFields Link icon

      boolean declareFields()
      Whether the current context is rendering a SQL field declaration (e.g. a Field in the SELECT clause of the query).
    • declareFields Link icon

      @NotNull C declareFields(boolean declareFields)
      Set the new context value for declareFields().
    • declareFields Link icon

      @NotNull C declareFields(boolean declareFields, Consumer<? super C> consumer)
      Set the new context value for declareFields() for the scope of a Consumer.
    • declareTables Link icon

      boolean declareTables()
      Whether the current context is rendering a SQL table declaration (e.g. a Table in the FROM or JOIN clause of the query).
    • declareTables Link icon

      @NotNull C declareTables(boolean declareTables)
      Set the new context value for declareTables().
    • declareTables Link icon

      @NotNull C declareTables(boolean declareTables, Consumer<? super C> consumer)
      Set the new context value for declareTables() for the scope of a Consumer.
    • declareAliases Link icon

      boolean declareAliases()
      Whether the current context is rendering a SQL alias declarations in declareTables() or declareFields() sections.
    • declareAliases Link icon

      @NotNull C declareAliases(boolean declareTables)
      Whether the current context is rendering a SQL alias declarations in declareTables() or declareFields() sections.
    • declareAliases Link icon

      @NotNull C declareAliases(boolean declareTables, Consumer<? super C> consumer)
      Whether the current context is rendering a SQL alias declarations in declareTables() or declareFields() sections for the scope of a Consumer.
    • declareWindows Link icon

      boolean declareWindows()
      Whether the current context is rendering a SQL window declaration (e.g. a WindowDefinition in the WINDOW clause of the query).
    • declareWindows Link icon

      @NotNull C declareWindows(boolean declareWindows)
      Set the new context value for declareWindows().
    • declareWindows Link icon

      @NotNull C declareWindows(boolean declareWindows, Consumer<? super C> consumer)
      Set the new context value for declareWindows() for the scope of a Consumer.
    • declareParameters Link icon

      @Pro boolean declareParameters()
      Whether the current context is rendering a procedure or function parameter declaration.
    • declareParameters Link icon

      @Pro @NotNull C declareParameters(boolean declareParameters)
      Set the new context value for declareParameters().
    • declareParameters Link icon

      @Pro @NotNull C declareParameters(boolean declareParameters, Consumer<? super C> consumer)
      Set the new context value for declareParameters() for the scope of a Consumer.
    • declareCTE Link icon

      boolean declareCTE()
      Whether the current context is rendering a common table expression (e.g. a CommonTableExpression in the WITH clause of the query).
    • declareCTE Link icon

      @NotNull C declareCTE(boolean declareCTE)
      Set the new context value for declareCTE().
    • declareCTE Link icon

      @NotNull C declareCTE(boolean declareCTE, Consumer<? super C> consumer)
      Set the new context value for declareCTE() for the scope of a Consumer.
    • topLevel Link icon

      @Nullable @Nullable QueryPart topLevel()
      The top level QueryPart that is being rendered.
    • topLevel Link icon

      @NotNull C topLevel(QueryPart topLevel)
      Set the top level QueryPart that is being rendered.
    • topLevelForLanguageContext Link icon

      @Nullable @Nullable QueryPart topLevelForLanguageContext()
      The top level QueryPart that is being rendered in the current languageContext().
    • topLevelForLanguageContext Link icon

      @NotNull C topLevelForLanguageContext(QueryPart topLevelForLanguageContext)
      Set the top level QueryPart that is being rendered in the current languageContext().
    • subquery Link icon

      boolean subquery()
      Whether the current context is rendering a subquery (nested query).
    • subquery Link icon

      @NotNull C subquery(boolean subquery)
      Set the new context value for subquery().
    • subquery Link icon

      @NotNull C subquery(boolean subquery, QueryPart part)
      Set the new context value for subquery() as well as scopePart() a
    • derivedTableSubquery Link icon

      boolean derivedTableSubquery()
      Whether the current context is rendering a derived table subquery.
    • derivedTableSubquery Link icon

      @NotNull C derivedTableSubquery(boolean derivedTableSubquery)
      Set the new context value for derivedTableSubquery().
    • setOperationSubquery Link icon

      boolean setOperationSubquery()
      Whether the current context is rendering a set operation subquery.
    • setOperationSubquery Link icon

      @NotNull C setOperationSubquery(boolean setOperationSubquery)
      Set the new context value for setOperationSubquery().
    • predicandSubquery Link icon

      boolean predicandSubquery()
      Whether the current context is rendering a predicand subquery, i.e. a subquery that is an operand of a predicate.
    • predicandSubquery Link icon

      @NotNull C predicandSubquery(boolean predicandSubquery)
      Set the new context value for predicandSubquery().
    • subqueryLevel Link icon

      int subqueryLevel()
      Which level of subqueries we're currently in, starting with 0 for the top level query.
    • scopeLevel Link icon

      int scopeLevel()
      Which level of scopes we're currently in, starting with 0 for the top scope.
    • scopeStart Link icon

      @NotNull C scopeStart()
      Start a new scope.
    • scopeStart Link icon

      @NotNull C scopeStart(QueryPart part)
      Start a new scope, passing the current QueryPart as the scopePart().

      If the new scope doesn't have such a QueryPart, then scopeStart() can be called instead.

    • scopePart Link icon

      @Nullable @Nullable QueryPart scopePart()
      Return the QueryPart that defines the current scopeStart(QueryPart), if any, or null if there is no such QueryPart.
    • scopeMarkStart Link icon

      @NotNull C scopeMarkStart(QueryPart part)
      Mark the beginning of a scoped query part.
    • scopeRegister Link icon

      @NotNull C scopeRegister(QueryPart part)
      Register a "special" query part in the scope, reusing the object from a higher scope, if available.
    • scopeRegisterAndMark Link icon

      @NotNull C scopeRegisterAndMark(QueryPart part, boolean forceNew)
    • scopeRegister Link icon

      @NotNull C scopeRegister(QueryPart part, boolean forceNew)
      Register a "special" query part in the scope, allowing to force registering the object in the new scope, if a higher scope already has the object.

      [#10992] This is necessary to allow for hiding identifiers from nested scopes.

    • scopeRegister Link icon

      @NotNull C scopeRegister(QueryPart part, boolean forceNew, QueryPart mapped)
      Register a "special" query part in the scope, allowing to force registering the object in the new scope, if a higher scope already has the object, as well as providing a mapped part to map the original part to.

      [#10716] When wrapping parts of a query in a derived table, additional table mappings may be needed.

    • scopeParts Link icon

      @NotNull <Q extends QueryPart> @NotNull Iterable<Q> scopeParts(Class<? extends Q> type)
      Get all values of a type that are in the current scope or higher.
    • inScope Link icon

      boolean inScope(QueryPart part)
      Check whether a query part is registered in the current scope or higher.
    • inCurrentScope Link icon

      boolean inCurrentScope(QueryPart part)
      Check whether a query part is registered in the current scope.
    • scopeMapping Link icon

      @NotNull @NotNull QueryPart scopeMapping(QueryPart part)
      Retrieve the registered mapping for a query part in the current scope.

      If no such mapping exists, the argument QueryPart itself is returned.

    • scopeMarkEnd Link icon

      @NotNull C scopeMarkEnd(QueryPart part)
      Mark the end of a scoped query part.
    • scopeEnd Link icon

      @NotNull C scopeEnd()
      End a previous SELECT scope.
    • stringLiteral Link icon

      boolean stringLiteral()
      whether the current context is rendering a string literal.
    • stringLiteral Link icon

      @NotNull C stringLiteral(boolean stringLiteral)
      Set the new context value for stringLiteral().
    • nextIndex Link icon

      int nextIndex()
      Get the next bind index. This increments an internal counter. This is relevant for two use-cases:
    • peekIndex Link icon

      int peekIndex()
      Peek the next bind index. This won't increment the internal counter, unlike nextIndex().
    • skipUpdateCount Link icon

      @NotNull C skipUpdateCount()
      Skip an additional update count produced by this query.
    • skipUpdateCounts Link icon

      @NotNull C skipUpdateCounts(int skip)
      Skip a number of additional update counts produced by this query.
    • skipUpdateCounts Link icon

      int skipUpdateCounts()
      The number of update counts to be skipped by this query.
    • statement Link icon

      @Nullable @Nullable PreparedStatement statement()
      Retrieve the context's underlying PreparedStatement if available, or null if this traversal does not operate on a PreparedStatement.
    • bindValue Link icon

      @NotNull @NotNull BindContext bindValue(Object value, Field<?> field) throws DataAccessException
      Bind a value using a specific type. This will also increment the internal counter.
      Throws:
      DataAccessException - If something went wrong while binding a variable
    • peekAlias Link icon

      @NotNull @NotNull String peekAlias()
      Peek the next alias that will be generated by nextAlias().
    • nextAlias Link icon

      @NotNull @NotNull String nextAlias()
      Return a new alias that is unique for the scope of one query. These aliases are sometimes needed when unaliased projections are defined in subqueries, which can lead to syntax errors.
    • render Link icon

      @NotNull @NotNull String render()
      Render the context's underlying SQL statement.
    • render Link icon

      @NotNull @NotNull String render(QueryPart part)
      Render a query part in a new context derived from this one. The rendered SQL will not be appended to this context.
    • keyword Link icon

      @NotNull @Deprecated(forRemoval=true, since="3.10") C keyword(String keyword)
      Deprecated, for removal: This API element is subject to removal in a future version.
      - 3.10.0 - [#4990] - Use DSL.keyword(String) instead.
      Append a SQL keyword to the context's contained StringBuilder.

      Use this to have your SQL keyword rendered in RenderKeywordCase.

    • sql Link icon

      @NotNull C sql(String sql)
      Append some SQL to the context's contained StringBuilder.
    • sql Link icon

      @NotNull C sql(String sql, boolean literal)
      Append some SQL to the context's contained StringBuilder.

      Set literal = true to indicate that the RenderContext shall not format the argument SQL.

    • sqlIndentStart Link icon

      @NotNull C sqlIndentStart(String sql)
      Append some SQL to the context's contained StringBuilder, followed by the usual calls to formatIndentStart() and formatNewLine().
    • sqlIndentEnd Link icon

      @NotNull C sqlIndentEnd(String sql)
      Append some SQL to the context's contained StringBuilder preceded by the usual calls to formatIndentEnd() and formatNewLine().
    • sqlIndentStart Link icon

      @NotNull C sqlIndentStart()
      Append some SQL to the context's contained StringBuilder, followed by the usual calls to formatIndentStart() and formatNewLine().
    • sqlIndentEnd Link icon

      @NotNull C sqlIndentEnd()
      Append some SQL to the context's contained StringBuilder preceded by the usual calls to formatIndentEnd() and formatNewLine().
    • sql Link icon

      @NotNull C sql(char sql)
      Append some SQL to the context's contained StringBuilder.
    • sqlIndentStart Link icon

      @NotNull C sqlIndentStart(char sql)
      Append some SQL to the context's contained StringBuilder, followed by the usual calls to formatIndentStart() and formatNewLine().
    • sqlIndentEnd Link icon

      @NotNull C sqlIndentEnd(char sql)
      Append some SQL to the context's contained StringBuilder preceded by the usual calls to formatIndentEnd() and formatNewLine().
    • sql Link icon

      @NotNull C sql(int sql)
      Append some SQL to the context's contained StringBuilder.
    • sql Link icon

      @NotNull C sql(long sql)
      Append some SQL to the context's contained StringBuilder.
    • floatFormat Link icon

      DecimalFormat floatFormat()
      A formatter to produce scientific notation for Float types.
    • sql Link icon

      @NotNull C sql(float sql)
      Append some SQL to the context's contained StringBuilder.
    • doubleFormat Link icon

      DecimalFormat doubleFormat()
      A formatter to produce scientific notation for Double types.
    • sql Link icon

      @NotNull C sql(double sql)
      Append some SQL to the context's contained StringBuilder.
    • format Link icon

      @NotNull C format(boolean format)
      Override the value of Settings.isRenderFormatted().
    • format Link icon

      boolean format()
    • formatNewLine Link icon

      @NotNull C formatNewLine()
      Render a new line character (only if Settings.isRenderFormatted() is set to true).
    • formatNewLineAfterPrintMargin Link icon

      @NotNull C formatNewLineAfterPrintMargin()
      Render a new line character (only if Settings.isRenderFormatted() is set to true, and the formatPrintMargin(int) has been exceeded).
    • formatSeparator Link icon

      @NotNull C formatSeparator()
      Render a new line character (only if Settings.isRenderFormatted() is set to true), or a whitespace separator character otherwise.
    • separatorRequired Link icon

      @NotNull C separatorRequired(boolean separatorRequired)
      Specify that a separator will be required before the next visit(QueryPart) call, but leave the decision whether to generate a formatSeparator() or just a whitespace to that next QueryPart.
    • separatorRequired Link icon

      boolean separatorRequired()
      Whether some sort of separator is required before rendering the next QueryPart.
    • formatIndentStart Link icon

      @NotNull C formatIndentStart()
      Start indenting subsequent SQL by one level (two characters), if Settings.isRenderFormatted() is set to true.

      This is the same as calling formatIndentStart(int) with a parameter of 2

    • formatIndentStart Link icon

      @NotNull C formatIndentStart(int indent)
      Start indenting subsequent SQL by a number of characters, if Settings.isRenderFormatted() is set to true.
    • formatIndentLockStart Link icon

      @Deprecated(forRemoval=true, since="3.14") @NotNull C formatIndentLockStart()
      Deprecated, for removal: This API element is subject to removal in a future version.
      - [#10317] - 3.14.0 - Do not reuse this method. It will be removed without replacement.
      Start indenting subsequent SQL at the same level as the current line, if Settings.isRenderFormatted() is set to true.
    • formatIndentEnd Link icon

      @NotNull C formatIndentEnd()
      Stop indenting subsequent SQL by one level (two characters), if Settings.isRenderFormatted() is set to true.

      This is the same as calling formatIndentEnd(int) with a parameter of 2

    • formatIndentEnd Link icon

      @NotNull C formatIndentEnd(int indent)
      Stop indenting subsequent SQL by a number of characters, if Settings.isRenderFormatted() is set to true.
    • formatIndentLockEnd Link icon

      @Deprecated(forRemoval=true, since="3.14") @NotNull C formatIndentLockEnd()
      Deprecated, for removal: This API element is subject to removal in a future version.
      - [#10317] - 3.14.0 - Do not reuse this method. It will be removed without replacement.
      Stop indenting subsequent SQL at the same level as the current line, if Settings.isRenderFormatted() is set to true.
    • formatPrintMargin Link icon

      @NotNull C formatPrintMargin(int margin)
      Set a print margin that will be applied to formatted SQL, if Settings.isRenderFormatted() is set to true.

      The default print margin is 80. Setting this to zero or a negative value means that no print margin will be applied.

      The print margin is applied to any of these QueryParts:

    • literal Link icon

      @NotNull @Deprecated(forRemoval=true, since="3.10") C literal(String literal)
      Deprecated, for removal: This API element is subject to removal in a future version.
      - 3.10.0 - [#4990] - Use any of DSL.name(String), DSL.quotedName(String) or DSL.unquotedName(String) instead.
      Append some literal to the context's contained StringBuilder.
    • quote Link icon

      boolean quote()
      Whether Name parts (and literal(String)) should be quoted.
    • quote Link icon

      @NotNull C quote(boolean quote)
      Set the new context value for quote().
    • quote Link icon

      @NotNull C quote(boolean quote, Consumer<? super C> consumer)
      Set the new context value for quote() for the scope of a Consumer.
    • qualify Link icon

      boolean qualify()
      Whether query parts should render qualified names or not.
    • qualify Link icon

      @NotNull C qualify(boolean qualify)
      Set the new context value for qualify().
    • qualify Link icon

      @NotNull C qualify(boolean qualify, Consumer<? super C> consumer)
      Set the new context value for qualify() for the scope of a Consumer.
    • qualifySchema Link icon

      boolean qualifySchema()
      Whether query parts should render Schema-qualified names or not.
    • qualifySchema Link icon

      @NotNull C qualifySchema(boolean qualifySchema)
      Set the new context value for qualifySchema().
    • qualifySchema Link icon

      @NotNull C qualifySchema(boolean qualifySchema, Consumer<? super C> consumer)
      Set the new context value for qualifySchema() for the scope of a Consumer.
    • qualifyCatalog Link icon

      boolean qualifyCatalog()
      Whether query parts should render Catalog-qualified names or not.
    • qualifyCatalog Link icon

      @NotNull C qualifyCatalog(boolean qualifyCatalog)
      Set the new context value for qualifyCatalog().
    • qualifyCatalog Link icon

      @NotNull C qualifyCatalog(boolean qualifyCatalog, Consumer<? super C> consumer)
      Set the new context value for qualifyCatalog() for the scope of a Consumer.
    • paramType Link icon

      @NotNull @NotNull ParamType paramType()
      Specify, how bind values should be rendered.

    • paramType Link icon

      @NotNull C paramType(ParamType paramType)
      Set the new context value for paramType().
    • visit Link icon

      @NotNull C visit(QueryPart part, ParamType paramType)
      Visit a query part with a given value for paramType().
    • paramTypeIf Link icon

      @NotNull C paramTypeIf(ParamType paramType, boolean condition)
      Set the new context value for paramType(), if a condition is true.
    • paramType Link icon

      @NotNull C paramType(ParamType paramType, Consumer<? super C> runnable)
      Set the new context value for paramType() for the scope of a Consumer.
    • paramTypeIf Link icon

      @NotNull C paramTypeIf(ParamType paramType, boolean condition, Consumer<? super C> runnable)
      Set the new context value for paramType() for the scope of a Consumer, if a condition is true.
    • languageContext Link icon

      @NotNull @NotNull LanguageContext languageContext()
      The current language context.
    • languageContext Link icon

      @NotNull C languageContext(LanguageContext languageContext)
      Set the new language context for languageContext()
    • languageContext Link icon

      @NotNull C languageContext(LanguageContext languageContext, Consumer<? super C> consumer)
      Set the new language context for languageContext() for the scope of a Consumer.
    • languageContext Link icon

      @NotNull C languageContext(LanguageContext languageContext, QueryPart topLevelForLanguageContext, Consumer<? super C> consumer)
      Set the new language context for languageContext() for the scope of a Consumer.
    • languageContextIf Link icon

      @NotNull C languageContextIf(LanguageContext languageContext, boolean condition)
      Set the new language context for languageContext(), if a condition is true.
    • castMode Link icon

      @NotNull @NotNull RenderContext.CastMode castMode()
      The currently applied cast mode for bind values.
    • castMode Link icon

      @NotNull C castMode(RenderContext.CastMode mode)
      Set the new cast mode for castMode().
    • castMode Link icon

      @NotNull C castMode(RenderContext.CastMode mode, Consumer<? super C> consumer)
      Set the new cast mode for castMode() for the scope of a Consumer.
    • castModeIf Link icon

      @NotNull C castModeIf(RenderContext.CastMode mode, boolean condition)
      Set the new cast mode for castMode(), if a condition is true.