-
- 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 BindContext
bindValue(Object value, Field<?> field)
Bind a value using a specific type.Boolean
cast()
Deprecated.- [#3703] - 3.5.0 - Do not use this any longerRenderContext.CastMode
castMode()
The currently applied cast mode for bind values.C
castMode(RenderContext.CastMode mode)
Set the new cast mode forcastMode()
.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()
Stop indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()
is set totrue
.C
formatIndentLockStart()
Start indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()
is set totrue
.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.String
nextAlias()
Return a new alias that is unique for the scope of one query.int
nextIndex()
Get the next bind index.ParamType
paramType()
Specify, how bind values should be rendered.C
paramType(ParamType paramType)
Set the new context value forparamType()
.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()
.String
render()
Render the context's underlying SQL statement.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.C
scopeStart()
Start a new SELECT scope.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!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
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
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
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
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
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
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
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
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
C scopeStart()
Start a new SELECT scope.
-
scopeEnd
C scopeEnd()
End a previous SELECT scope.
-
stringLiteral
boolean stringLiteral()
whether the current context is rendering a string literal.
-
stringLiteral
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 toBindContext.statement()
- When rendering unnamed bind variables with
RenderContext.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
PreparedStatement statement()
Retrieve the context's underlyingPreparedStatement
if available, ornull
if this traversal does not operate on aPreparedStatement
.
-
bindValue
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
String peekAlias()
Peek the next alias that will be generated bynextAlias()
.
-
nextAlias
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
String render()
Render the context's underlying SQL statement.
-
render
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
@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
C sql(String sql)
Append some SQL to the context's containedStringBuilder
.
-
sql
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
C sql(char sql)
Append some SQL to the context's containedStringBuilder
.
-
sql
C sql(int sql)
Append some SQL to the context's containedStringBuilder
.
-
sql
C sql(long sql)
Append some SQL to the context's containedStringBuilder
.
-
sql
C sql(float sql)
Append some SQL to the context's containedStringBuilder
.
-
sql
C sql(double sql)
Append some SQL to the context's containedStringBuilder
.
-
format
C format(boolean format)
Override the value ofSettings.isRenderFormatted()
.
-
format
boolean format()
The value ofSettings.isRenderFormatted()
.
-
formatNewLine
C formatNewLine()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
).
-
formatNewLineAfterPrintMargin
C formatNewLineAfterPrintMargin()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
, and theformatPrintMargin(int)
has been exceeded).
-
formatSeparator
C formatSeparator()
Render a new line character (only ifSettings.isRenderFormatted()
is set totrue
), or a whitespace separator character otherwise.
-
formatIndentStart
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
C formatIndentStart(int indent)
Start indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()
is set totrue
.
-
formatIndentLockStart
C formatIndentLockStart()
Start indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()
is set totrue
.
-
formatIndentEnd
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
C formatIndentEnd(int indent)
Stop indenting subsequent SQL by a number of characters, ifSettings.isRenderFormatted()
is set totrue
.
-
formatIndentLockEnd
C formatIndentLockEnd()
Stop indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()
is set totrue
.
-
formatPrintMargin
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
@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
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
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
C qualifyCatalog(boolean qualifyCatalog)
Set the new context value forqualifyCatalog()
.The catalog can only be qualified when
qualifySchema()
istrue
as well.
-
paramType
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
C paramType(ParamType paramType)
Set the new context value forparamType()
.
-
castMode
RenderContext.CastMode castMode()
The currently applied cast mode for bind values.
-
castMode
C castMode(RenderContext.CastMode mode)
Set the new cast mode forcastMode()
.
-
cast
@Deprecated 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
@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.
-
-