-
- 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 BindContextbindValue(Object value, Field<?> field)Bind a value using a specific type.Booleancast()Deprecated.- [#3703] - 3.5.0 - Do not use this any longerRenderContext.CastModecastMode()The currently applied cast mode for bind values.CcastMode(RenderContext.CastMode mode)Set the new cast mode forcastMode().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()Stop indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()is set totrue.CformatIndentLockStart()Start indenting subsequent SQL at the same level as the current line, ifSettings.isRenderFormatted()is set totrue.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.StringnextAlias()Return a new alias that is unique for the scope of one query.intnextIndex()Get the next bind index.ParamTypeparamType()Specify, how bind values should be rendered.CparamType(ParamType paramType)Set the new context value forparamType().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().Stringrender()Render the context's underlying SQL statement.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.CscopeStart()Start a new SELECT scope.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!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
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
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
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
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. aWindowDefinitionin theWINDOWclause 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. aCommonTableExpressionin theWITHclause 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 underlyingPreparedStatementif available, ornullif 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 = trueto indicate that theRenderContextshall 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()
WhetherNameparts (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()istrueas well.
-
qualifyCatalog
C qualifyCatalog(boolean qualifyCatalog)
Set the new context value forqualifyCatalog().The catalog can only be qualified when
qualifySchema()istrueas well.
-
paramType
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
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 ALWAYStrueNEVERfalseSOMEtrueorfalsedepending on the dialectDEFAULTnull
-
castModeSome
@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.
-
-