-
- All Superinterfaces:
Scope
- All Known Subinterfaces:
BindContext,RenderContext
public interface Context<C extends Context<C>> extends Scope
A context type that is used for rendering SQL or for binding.- Author:
- Lukas Eder
- See Also:
BindContext,RenderContext
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description @NotNull BindContextbindValue(Object value, Field<?> field)Bind a value using a specific type.@Nullable Booleancast()Deprecated.- [#3703] - 3.5.0 - Do not use this any longer@NotNull RenderContext.CastModecastMode()The currently applied cast mode for bind values.CcastMode(RenderContext.CastMode mode)Set the new cast mode forcastMode().CcastModeIf(RenderContext.CastMode mode, boolean condition)Set the new cast mode forcastMode(), if a condition is true.CcastModeSome(SQLDialect... dialects)Deprecated.- [#3703] - 3.5.0 - Do not use this any longerbooleandeclareAliases()Whether the current context is rendering a SQL alias declarations indeclareTables()ordeclareFields()sections.CdeclareAliases(boolean declareTables)Whether the current context is rendering a SQL alias declarations indeclareTables()ordeclareFields()sections.booleandeclareCTE()Whether the current context is rendering a common table expression (e.g.CdeclareCTE(boolean declareCTE)Set the new context value fordeclareCTE().booleandeclareFields()Whether the current context is rendering a SQL field declaration (e.g.CdeclareFields(boolean declareFields)Set the new context value fordeclareFields().booleandeclareTables()Whether the current context is rendering a SQL table declaration (e.g.CdeclareTables(boolean declareTables)Set the new context value fordeclareTables().booleandeclareWindows()Whether the current context is rendering a SQL window declaration (e.g.CdeclareWindows(boolean declareWindows)Set the new context value fordeclareWindows().Cend(Clause clause)booleanformat()The value ofSettings.isRenderFormatted().Cformat(boolean format)Override the value ofSettings.isRenderFormatted().CformatIndentEnd()Stop indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()is set totrue.CformatIndentEnd(int indent)Stop indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()is set totrue.CformatIndentLockEnd()Deprecated.- [#10317] - 3.14.0 - Do not reuse this method.CformatIndentLockStart()Deprecated.- [#10317] - 3.14.0 - Do not reuse this method.CformatIndentStart()Start indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()is set totrue.CformatIndentStart(int indent)Start indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()is set totrue.CformatNewLine()Render a new line character (only ifSettings.isRenderFormatted()is set totrue).CformatNewLineAfterPrintMargin()Render a new line character (only ifSettings.isRenderFormatted()is set totrue, and theformatPrintMargin(int)has been exceeded).CformatPrintMargin(int margin)Set a print margin that will be applied to formatted SQL, ifSettings.isRenderFormatted()is set totrue.CformatSeparator()Render a new line character (only ifSettings.isRenderFormatted()is set totrue), or a whitespace separator character otherwise.Ckeyword(String keyword)Deprecated.- 3.10.0 - [#4990] - UseDSL.keyword(String)instead.Cliteral(String literal)Deprecated.- 3.10.0 - [#4990] - Use any ofDSL.name(String),DSL.quotedName(String)orDSL.unquotedName(String)instead.@NotNull StringnextAlias()Return a new alias that is unique for the scope of one query.intnextIndex()Get the next bind index.@NotNull ParamTypeparamType()Specify, how bind values should be rendered.CparamType(ParamType paramType)Set the new context value forparamType().CparamTypeIf(ParamType paramType, boolean condition)Set the new context value forparamType(), if a condition is true.@NotNull StringpeekAlias()Peek the next alias that will be generated bynextAlias().intpeekIndex()Peek the next bind index.booleanqualify()Whether query parts should render qualified names or not.Cqualify(boolean qualify)Set the new context value forqualify().booleanqualifyCatalog()Whether query parts should render qualified names or not.CqualifyCatalog(boolean qualifyCatalog)Set the new context value forqualifyCatalog().booleanqualifySchema()Whether query parts should render qualified names or not.CqualifySchema(boolean qualifySchema)Set the new context value forqualifySchema().booleanquote()WhetherNameparts (andliteral(String)) should be quoted.Cquote(boolean quote)Set the new context value forquote().@NotNull Stringrender()Render the context's underlying SQL statement.@NotNull Stringrender(QueryPart part)Render a query part in a new context derived from this one.CscopeEnd()End a previous SELECT scope.CscopeMarkEnd(QueryPart part)Mark the end of a scoped query part.CscopeMarkStart(QueryPart part)Mark the beginning of a scoped query part.CscopeRegister(QueryPart part)Register a "special" query part in the scope, reusing the object from a higher scope, if available.CscopeRegister(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.CscopeStart()Start a new SELECT scope.booleanseparatorRequired()Whether some sort of separator is required before rendering the nextQueryPart.CseparatorRequired(boolean separatorRequired)Specify that a separator will be required before the nextvisit(QueryPart)call, but leave the decision whether to generate aformatSeparator()or just a whitespace to that nextQueryPart.Csql(char sql)Append some SQL to the context's containedStringBuilder.Csql(double sql)Append some SQL to the context's containedStringBuilder.Csql(float sql)Append some SQL to the context's containedStringBuilder.Csql(int sql)Append some SQL to the context's containedStringBuilder.Csql(long sql)Append some SQL to the context's containedStringBuilder.Csql(String sql)Append some SQL to the context's containedStringBuilder.Csql(String sql, boolean literal)Append some SQL to the context's containedStringBuilder.Cstart(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!@Nullable PreparedStatementstatement()Retrieve the context's underlyingPreparedStatementif available, ornullif this traversal does not operate on aPreparedStatement.booleanstringLiteral()whether the current context is rendering a string literal.CstringLiteral(boolean stringLiteral)Set the new context value forstringLiteral().booleansubquery()Whether the current context is rendering a sub-query (nested query).Csubquery(boolean subquery)Set the new context value forsubquery().intsubqueryLevel()Which level of subqueries we're currently in, starting with 0 for the top level query.Cvisit(QueryPart part)Visit aQueryPartin the currentContext.
-
-
-
Method Detail
-
visit
@NotNull C visit(QueryPart part) throws DataAccessException
Visit aQueryPartin the currentContext.This method is called by certain
QueryPartimplementations to recursively visit componentQueryParts.- Parameters:
part- The componentQueryPart- Throws:
DataAccessException- If something went wrong while visiting the componentQueryPart, e.g. when binding a variable
-
start
@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!
-
declareFields
boolean declareFields()
Whether the current context is rendering a SQL field declaration (e.g. aFieldin theSELECTclause of the query).
-
declareFields
@NotNull C declareFields(boolean declareFields)
Set the new context value fordeclareFields().
-
declareTables
boolean declareTables()
Whether the current context is rendering a SQL table declaration (e.g. aTablein theFROMorJOINclause of the query).
-
declareTables
@NotNull C declareTables(boolean declareTables)
Set the new context value fordeclareTables().
-
declareAliases
boolean declareAliases()
Whether the current context is rendering a SQL alias declarations indeclareTables()ordeclareFields()sections.
-
declareAliases
@NotNull C declareAliases(boolean declareTables)
Whether the current context is rendering a SQL alias declarations indeclareTables()ordeclareFields()sections.
-
declareWindows
boolean declareWindows()
Whether the current context is rendering a SQL window declaration (e.g. aWindowDefinitionin theWINDOWclause of the query).
-
declareWindows
@NotNull C declareWindows(boolean declareWindows)
Set the new context value fordeclareWindows().
-
declareCTE
boolean declareCTE()
Whether the current context is rendering a common table expression (e.g. aCommonTableExpressionin theWITHclause of the query).
-
declareCTE
@NotNull C declareCTE(boolean declareCTE)
Set the new context value fordeclareCTE().
-
subquery
boolean subquery()
Whether the current context is rendering a sub-query (nested query).
-
subquery
@NotNull C subquery(boolean subquery)
Set the new context value forsubquery().
-
subqueryLevel
int subqueryLevel()
Which level of subqueries we're currently in, starting with 0 for the top level query.
-
scopeStart
@NotNull C scopeStart()
Start a new SELECT scope.
-
scopeMarkStart
@NotNull C scopeMarkStart(QueryPart part)
Mark the beginning of a scoped query part.
-
scopeRegister
@NotNull C scopeRegister(QueryPart part)
Register a "special" query part in the scope, reusing the object from a higher scope, if available.
-
scopeRegister
@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.
-
scopeEnd
@NotNull C scopeEnd()
End a previous SELECT scope.
-
stringLiteral
boolean stringLiteral()
whether the current context is rendering a string literal.
-
stringLiteral
@NotNull C stringLiteral(boolean stringLiteral)
Set the new context value forstringLiteral().
-
nextIndex
int nextIndex()
Get the next bind index. This increments an internal counter. This is relevant for two use-cases:- When binding variables to a
PreparedStatement. Client code must assure that callingnextIndex()is followed by setting a bind value tostatement() - When rendering unnamed bind variables with
paramType()being toNAMED
- When binding variables to a
-
peekIndex
int peekIndex()
Peek the next bind index. This won't increment the internal counter, unlikenextIndex().
-
statement
@Nullable @Nullable PreparedStatement statement()
Retrieve the context's underlyingPreparedStatementif available, ornullif this traversal does not operate on aPreparedStatement.
-
bindValue
@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
@NotNull @NotNull String peekAlias()
Peek the next alias that will be generated bynextAlias().
-
nextAlias
@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
@NotNull @NotNull String render()
Render the context's underlying SQL statement.
-
render
@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
@NotNull @Deprecated C keyword(String keyword)
Deprecated.- 3.10.0 - [#4990] - UseDSL.keyword(String)instead.Append a SQL keyword to the context's containedStringBuilder.Use this to have your SQL keyword rendered in
RenderKeywordCase.
-
sql
@NotNull C sql(String sql)
Append some SQL to the context's containedStringBuilder.
-
sql
@NotNull C sql(String sql, boolean literal)
Append some SQL to the context's containedStringBuilder.Set
literal = trueto indicate that theRenderContextshall not format the argument SQL.
-
sql
@NotNull C sql(char sql)
Append some SQL to the context's containedStringBuilder.
-
sql
@NotNull C sql(int sql)
Append some SQL to the context's containedStringBuilder.
-
sql
@NotNull C sql(long sql)
Append some SQL to the context's containedStringBuilder.
-
sql
@NotNull C sql(float sql)
Append some SQL to the context's containedStringBuilder.
-
sql
@NotNull C sql(double sql)
Append some SQL to the context's containedStringBuilder.
-
format
@NotNull C format(boolean format)
Override the value ofSettings.isRenderFormatted().
-
format
boolean format()
The value ofSettings.isRenderFormatted().
-
formatNewLine
@NotNull C formatNewLine()
Render a new line character (only ifSettings.isRenderFormatted()is set totrue).
-
formatNewLineAfterPrintMargin
@NotNull C formatNewLineAfterPrintMargin()
Render a new line character (only ifSettings.isRenderFormatted()is set totrue, and theformatPrintMargin(int)has been exceeded).
-
formatSeparator
@NotNull C formatSeparator()
Render a new line character (only ifSettings.isRenderFormatted()is set totrue), or a whitespace separator character otherwise.
-
separatorRequired
@NotNull C separatorRequired(boolean separatorRequired)
Specify that a separator will be required before the nextvisit(QueryPart)call, but leave the decision whether to generate aformatSeparator()or just a whitespace to that nextQueryPart.
-
separatorRequired
boolean separatorRequired()
Whether some sort of separator is required before rendering the nextQueryPart.
-
formatIndentStart
@NotNull C formatIndentStart()
Start indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()is set totrue.This is the same as calling
formatIndentStart(int)with a parameter of2
-
formatIndentStart
@NotNull C formatIndentStart(int indent)
Start indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()is set totrue.
-
formatIndentLockStart
@Deprecated @NotNull C formatIndentLockStart()
Deprecated.- [#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, ifSettings.isRenderFormatted()is set totrue.
-
formatIndentEnd
@NotNull C formatIndentEnd()
Stop indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()is set totrue.This is the same as calling
formatIndentEnd(int)with a parameter of2
-
formatIndentEnd
@NotNull C formatIndentEnd(int indent)
Stop indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()is set totrue.
-
formatIndentLockEnd
@Deprecated @NotNull C formatIndentLockEnd()
Deprecated.- [#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, ifSettings.isRenderFormatted()is set totrue.
-
formatPrintMargin
@NotNull C formatPrintMargin(int margin)
Set a print margin that will be applied to formatted SQL, ifSettings.isRenderFormatted()is set totrue.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:-
Field.in(Field...)and related expressions
-
-
literal
@NotNull @Deprecated C literal(String literal)
Deprecated.- 3.10.0 - [#4990] - Use any ofDSL.name(String),DSL.quotedName(String)orDSL.unquotedName(String)instead.Append some literal to the context's containedStringBuilder.
-
quote
boolean quote()
WhetherNameparts (andliteral(String)) should be quoted.
-
qualify
boolean qualify()
Whether query parts should render qualified names or not.
-
qualify
@NotNull C qualify(boolean qualify)
Set the new context value forqualify().This is the same as
qualifySchema(boolean).
-
qualifySchema
boolean qualifySchema()
Whether query parts should render qualified names or not.This is the same as
qualifySchema().
-
qualifySchema
@NotNull C qualifySchema(boolean qualifySchema)
Set the new context value forqualifySchema().
-
qualifyCatalog
boolean qualifyCatalog()
Whether query parts should render qualified names or not.The catalog can only be qualified when
qualifySchema()istrueas well.
-
qualifyCatalog
@NotNull C qualifyCatalog(boolean qualifyCatalog)
Set the new context value forqualifyCatalog().The catalog can only be qualified when
qualifySchema()istrueas well.
-
paramType
@NotNull @NotNull ParamType paramType()
Specify, how bind values should be rendered.- As
ParamType.INDEXEDparameters:
?, ?, ? - As
ParamType.NAMEDparameters:
:1, :2, :custom_name - As
ParamType.INLINEDparameters:
1, 'A', null
- As
-
paramType
@NotNull C paramType(ParamType paramType)
Set the new context value forparamType().
-
paramTypeIf
@NotNull C paramTypeIf(ParamType paramType, boolean condition)
Set the new context value forparamType(), if a condition is true.
-
castMode
@NotNull @NotNull RenderContext.CastMode castMode()
The currently applied cast mode for bind values.
-
castMode
@NotNull C castMode(RenderContext.CastMode mode)
Set the new cast mode forcastMode().
-
castModeIf
@NotNull C castModeIf(RenderContext.CastMode mode, boolean condition)
Set the new cast mode forcastMode(), if a condition is true.
-
cast
@Nullable @Deprecated @Nullable Boolean cast()
Deprecated.- [#3703] - 3.5.0 - Do not use this any longerWhether casting must be applied. The result follows this logic:CastMode result ALWAYStrueNEVERfalseSOMEtrueorfalsedepending on the dialectDEFAULTnull
-
castModeSome
@NotNull @Deprecated C castModeSome(SQLDialect... dialects)
Deprecated.- [#3703] - 3.5.0 - Do not use this any longerSet the new cast mode toRenderContext.CastMode.SOMEfor a list of dialects.
-
-