-
- 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 BindContext
bindValue(Object value, Field<?> field)
Bind a value using a specific type.@Nullable Boolean
cast()
Deprecated.- [#3703] - 3.5.0 - Do not use this any longer@NotNull RenderContext.CastMode
castMode()
The currently applied cast mode for bind values.C
castMode(RenderContext.CastMode mode)
Set the new cast mode forcastMode()
.C
castModeIf(RenderContext.CastMode mode, boolean condition)
Set the new cast mode forcastMode()
, if a condition is true.C
castModeSome(SQLDialect... dialects)
Deprecated.- [#3703] - 3.5.0 - Do not use this any longerboolean
declareAliases()
Whether the current context is rendering a SQL alias declarations indeclareTables()
ordeclareFields()
sections.C
declareAliases(boolean declareTables)
Whether the current context is rendering a SQL alias declarations indeclareTables()
ordeclareFields()
sections.boolean
declareCTE()
Whether the current context is rendering a common table expression (e.g.C
declareCTE(boolean declareCTE)
Set the new context value fordeclareCTE()
.boolean
declareFields()
Whether the current context is rendering a SQL field declaration (e.g.C
declareFields(boolean declareFields)
Set the new context value fordeclareFields()
.boolean
declareTables()
Whether the current context is rendering a SQL table declaration (e.g.C
declareTables(boolean declareTables)
Set the new context value fordeclareTables()
.boolean
declareWindows()
Whether the current context is rendering a SQL window declaration (e.g.C
declareWindows(boolean declareWindows)
Set the new context value fordeclareWindows()
.C
end(Clause clause)
boolean
format()
The value ofSettings.isRenderFormatted()
.C
format(boolean format)
Override the value ofSettings.isRenderFormatted()
.C
formatIndentEnd()
Stop indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()
is set totrue
.C
formatIndentEnd(int indent)
Stop indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()
is set totrue
.C
formatIndentLockEnd()
Deprecated.- [#10317] - 3.14.0 - Do not reuse this method.C
formatIndentLockStart()
Deprecated.- [#10317] - 3.14.0 - Do not reuse this method.C
formatIndentStart()
Start indenting subsequent SQL by one level (two characters), ifSettings.isRenderFormatted()
is set totrue
.C
formatIndentStart(int indent)
Start indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()
is set totrue
.C
formatNewLine()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
).C
formatNewLineAfterPrintMargin()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
, and theformatPrintMargin(int)
has been exceeded).C
formatPrintMargin(int margin)
Set a print margin that will be applied to formatted SQL, ifSettings.isRenderFormatted()
is set totrue
.C
formatSeparator()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
), or a whitespace separator character otherwise.C
keyword(String keyword)
Deprecated.- 3.10.0 - [#4990] - UseDSL.keyword(String)
instead.C
literal(String literal)
Deprecated.- 3.10.0 - [#4990] - Use any ofDSL.name(String)
,DSL.quotedName(String)
orDSL.unquotedName(String)
instead.@NotNull String
nextAlias()
Return a new alias that is unique for the scope of one query.int
nextIndex()
Get the next bind index.@NotNull ParamType
paramType()
Specify, how bind values should be rendered.C
paramType(ParamType paramType)
Set the new context value forparamType()
.C
paramTypeIf(ParamType paramType, boolean condition)
Set the new context value forparamType()
, if a condition is true.@NotNull String
peekAlias()
Peek the next alias that will be generated bynextAlias()
.int
peekIndex()
Peek the next bind index.boolean
qualify()
Whether query parts should render qualified names or not.C
qualify(boolean qualify)
Set the new context value forqualify()
.boolean
qualifyCatalog()
Whether query parts should render qualified names or not.C
qualifyCatalog(boolean qualifyCatalog)
Set the new context value forqualifyCatalog()
.boolean
qualifySchema()
Whether query parts should render qualified names or not.C
qualifySchema(boolean qualifySchema)
Set the new context value forqualifySchema()
.boolean
quote()
WhetherName
parts (andliteral(String)
) should be quoted.C
quote(boolean quote)
Set the new context value forquote()
.@NotNull String
render()
Render the context's underlying SQL statement.@NotNull String
render(QueryPart part)
Render a query part in a new context derived from this one.C
scopeEnd()
End a previous SELECT scope.C
scopeMarkEnd(QueryPart part)
Mark the end of a scoped query part.C
scopeMarkStart(QueryPart part)
Mark the beginning of a scoped query part.C
scopeRegister(QueryPart part)
Register a "special" query part in the scope, reusing the object from a higher scope, if available.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.C
scopeStart()
Start a new SELECT scope.boolean
separatorRequired()
Whether some sort of separator is required before rendering the nextQueryPart
.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
.C
sql(char sql)
Append some SQL to the context's containedStringBuilder
.C
sql(double sql)
Append some SQL to the context's containedStringBuilder
.C
sql(float sql)
Append some SQL to the context's containedStringBuilder
.C
sql(int sql)
Append some SQL to the context's containedStringBuilder
.C
sql(long sql)
Append some SQL to the context's containedStringBuilder
.C
sql(String sql)
Append some SQL to the context's containedStringBuilder
.C
sql(String sql, boolean literal)
Append some SQL to the context's containedStringBuilder
.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!@Nullable PreparedStatement
statement()
Retrieve the context's underlyingPreparedStatement
if available, ornull
if this traversal does not operate on aPreparedStatement
.boolean
stringLiteral()
whether the current context is rendering a string literal.C
stringLiteral(boolean stringLiteral)
Set the new context value forstringLiteral()
.boolean
subquery()
Whether the current context is rendering a sub-query (nested query).C
subquery(boolean subquery)
Set the new context value forsubquery()
.int
subqueryLevel()
Which level of subqueries we're currently in, starting with 0 for the top level query.C
visit(QueryPart part)
Visit aQueryPart
in the currentContext
.
-
-
-
Method Detail
-
visit
@NotNull C visit(QueryPart part) throws DataAccessException
Visit aQueryPart
in the currentContext
.This method is called by certain
QueryPart
implementations to recursively visit componentQueryPart
s.- 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. aField
in theSELECT
clause 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. aTable
in theFROM
orJOIN
clause 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. aWindowDefinition
in theWINDOW
clause 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. aCommonTableExpression
in theWITH
clause 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 underlyingPreparedStatement
if available, ornull
if 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 = true
to indicate that theRenderContext
shall 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()
WhetherName
parts (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()
istrue
as well.
-
qualifyCatalog
@NotNull C qualifyCatalog(boolean qualifyCatalog)
Set the new context value forqualifyCatalog()
.The catalog can only be qualified when
qualifySchema()
istrue
as well.
-
paramType
@NotNull @NotNull ParamType paramType()
Specify, how bind values should be rendered.- As
ParamType.INDEXED
parameters:
?, ?, ?
- As
ParamType.NAMED
parameters:
:1, :2, :custom_name
- As
ParamType.INLINED
parameters:
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 ALWAYS
true
NEVER
false
SOME
true
orfalse
depending on the dialectDEFAULT
null
-
castModeSome
@NotNull @Deprecated C castModeSome(SQLDialect... dialects)
Deprecated.- [#3703] - 3.5.0 - Do not use this any longerSet the new cast mode toRenderContext.CastMode.SOME
for a list of dialects.
-
-