public interface Context<C extends Context<C>>
BindContext
,
RenderContext
Modifier and Type | Method and Description |
---|---|
BindContext |
bindValue(Object value,
Field<?> field)
Bind a value using a specific type.
|
Boolean |
cast()
Whether casting must be applied.
|
RenderContext.CastMode |
castMode()
The currently applied cast mode for bind values.
|
C |
castMode(RenderContext.CastMode mode)
Set the new cast mode for
castMode() . |
C |
castModeSome(SQLDialect... dialects)
Set the new cast mode to
RenderContext.CastMode.SOME for a list of dialects. |
Configuration |
configuration()
The configuration wrapped by this context.
|
Map<Object,Object> |
data()
Get all custom data from this
Context . |
Object |
data(Object key)
Get some custom data from this
Context . |
Object |
data(Object key,
Object value)
Set some custom data to this
Context . |
boolean |
declareCTE()
Whether the current context is rendering a common table expression (e.g.
|
C |
declareCTE(boolean declareCTE)
Set the new context value for
declareCTE() |
boolean |
declareFields()
Whether the current context is rendering a SQL field declaration (e.g. a
Field in the SELECT clause of the query). |
C |
declareFields(boolean declareFields)
Set the new context value for
declareFields() |
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). |
C |
declareTables(boolean declareTables)
Set the new context value for
declareTables() |
boolean |
declareWindows()
Whether the current context is rendering a SQL window declaration (e.g. a
WindowDefinition in the WINDOW clause of the query). |
C |
declareWindows(boolean declareWindows)
Set the new context value for
declareWindows() |
C |
end(Clause clause) |
boolean |
format()
The value of
Settings.isRenderFormatted() . |
C |
format(boolean format)
Override the value of
Settings.isRenderFormatted() . |
C |
formatIndentEnd()
Stop indenting subsequent SQL by one level (two characters), if
Settings.isRenderFormatted() is set to true . |
C |
formatIndentEnd(int indent)
Stop indenting subsequent SQL by a number of characters, if
Settings.isRenderFormatted() is set to true . |
C |
formatIndentLockEnd()
Stop indenting subsequent SQL at the same level as the current line, if
Settings.isRenderFormatted() is set to true . |
C |
formatIndentLockStart()
Start indenting subsequent SQL at the same level as the current line, if
Settings.isRenderFormatted() is set to true . |
C |
formatIndentStart()
Start indenting subsequent SQL by one level (two characters), if
Settings.isRenderFormatted() is set to true . |
C |
formatIndentStart(int indent)
Start indenting subsequent SQL by a number of characters, if
Settings.isRenderFormatted() is set to true . |
C |
formatNewLine()
Render a new line character (only if
Settings.isRenderFormatted()
is set to true ). |
C |
formatNewLineAfterPrintMargin()
Render a new line character (only if
Settings.isRenderFormatted()
is set to true , and the formatPrintMargin(int) has
been exceeded). |
C |
formatPrintMargin(int margin)
Set a print margin that will be applied to formatted SQL, if
Settings.isRenderFormatted() is set to true . |
C |
formatSeparator()
Render a new line character (only if
Settings.isRenderFormatted()
is set to true ), or a whitespace separator character
otherwise. |
C |
keyword(String keyword)
Append a SQL keyword to the context's contained
StringBuilder . |
C |
literal(String literal)
Append some (quoted) literal to the context's contained
StringBuilder . |
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 for
paramType() . |
String |
peekAlias()
Peek the next alias that will be generated by
nextAlias() . |
int |
peekIndex()
Peek the next bind index.
|
boolean |
qualify()
Whether query parts should render qualified names or not.
|
C |
qualify(boolean qualify)
Sett the new context value for
qualify() . |
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 |
sql(char sql)
Append some SQL to the context's contained
StringBuilder . |
C |
sql(int sql)
Append some SQL to the context's contained
StringBuilder . |
C |
sql(String sql)
Append some SQL to the context's contained
StringBuilder . |
C |
sql(String sql,
boolean literal)
Append some SQL to the context's contained
StringBuilder . |
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 underlying
PreparedStatement if available,
or null if this traversal does not operate on a
PreparedStatement . |
boolean |
subquery()
Whether the current context is rendering a sub-query (nested query)
|
C |
subquery(boolean subquery)
Set the new context value for
subquery() |
C |
visit(QueryPart part)
Visit a
QueryPart in the current Context . |
Configuration configuration()
Map<Object,Object> data()
Context
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given RenderContext
or
BindContext
.
Unlike Configuration.data()
, these data's lifecycle only
matches that of a render or bind context.
null
Object data(Object key)
Context
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given RenderContext
or
BindContext
.
Unlike Configuration.data()
, these data's lifecycle only
matches that of a render or bind context.
key
- A key to identify the custom datanull
if no such data is contained
in this ExecuteContext
ExecuteListener
Object data(Object key, Object value)
Context
.
This is custom data that was previously set to the context using
data(Object, Object)
. Use custom data if you want to pass data
to QueryPart
objects for a given RenderContext
or
BindContext
.
Unlike Configuration.data()
, these data's lifecycle only
matches that of a render or bind context.
key
- A key to identify the custom datavalue
- The custom datanull
if no data
was previously set for the given keyExecuteListener
C visit(QueryPart part) throws DataAccessException
QueryPart
in the current Context
.
This method is called by certain QueryPart
implementations
to recursively visit component QueryPart
s.
part
- The component QueryPart
DataAccessException
- If something went wrong while visiting the
component QueryPart
, e.g. when binding a
variableC start(Clause clause)
boolean declareFields()
Field
in the SELECT
clause of the query).C declareFields(boolean declareFields)
declareFields()
boolean declareTables()
Table
in the FROM
or JOIN
clause of the
query).C declareTables(boolean declareTables)
declareTables()
boolean declareWindows()
WindowDefinition
in the WINDOW
clause of the query).C declareWindows(boolean declareWindows)
declareWindows()
boolean declareCTE()
CommonTableExpression
in the WITH
clause of the
query).C declareCTE(boolean declareCTE)
declareCTE()
boolean subquery()
C subquery(boolean subquery)
subquery()
int nextIndex()
PreparedStatement
. Client code
must assure that calling nextIndex()
is followed by setting a
bind value to BindContext.statement()
RenderContext.paramType()
being to NAMED
int peekIndex()
nextIndex()
PreparedStatement statement()
PreparedStatement
if available,
or null
if this traversal does not operate on a
PreparedStatement
.BindContext bindValue(Object value, Field<?> field) throws DataAccessException
DataAccessException
- If something went wrong while binding a
variableString peekAlias()
nextAlias()
.String nextAlias()
String render()
String render(QueryPart part)
C keyword(String keyword)
StringBuilder
.
Use this to have your SQL keyword rendered in RenderKeywordStyle
(upper or lower case)
C sql(String sql)
StringBuilder
.C sql(String sql, boolean literal)
StringBuilder
.
Set literal = true
to indicate that the
RenderContext
shall not format the argument SQL.
C sql(char sql)
StringBuilder
.C sql(int sql)
StringBuilder
.C format(boolean format)
Settings.isRenderFormatted()
.boolean format()
Settings.isRenderFormatted()
.C formatNewLine()
Settings.isRenderFormatted()
is set to true
).C formatNewLineAfterPrintMargin()
Settings.isRenderFormatted()
is set to true
, and the formatPrintMargin(int)
has
been exceeded).C formatSeparator()
Settings.isRenderFormatted()
is set to true
), or a whitespace separator character
otherwise.C formatIndentStart()
Settings.isRenderFormatted()
is set to true
.
This is the same as calling formatIndentStart(int)
with a
parameter of 2
C formatIndentStart(int indent)
Settings.isRenderFormatted()
is set to true
.C formatIndentLockStart()
Settings.isRenderFormatted()
is set to true
.C formatIndentEnd()
Settings.isRenderFormatted()
is set to true
.
This is the same as calling formatIndentEnd(int)
with a
parameter of 2
C formatIndentEnd(int indent)
Settings.isRenderFormatted()
is set to true
.C formatIndentLockEnd()
Settings.isRenderFormatted()
is set to true
.C formatPrintMargin(int margin)
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
:
Field.in(Field...)
and related expressionsC literal(String literal)
StringBuilder
.boolean qualify()
ParamType paramType()
ParamType.INDEXED
parameters: ?, ?, ?
ParamType.NAMED
parameters: :1, :2, :custom_name
ParamType.INLINED
parameters: 1, 'A', null
C paramType(ParamType paramType)
paramType()
.RenderContext.CastMode castMode()
C castMode(RenderContext.CastMode mode)
castMode()
.Boolean cast()
CastMode | result |
---|---|
ALWAYS |
true |
NEVER |
false |
SOME |
true or false depending on the dialect |
DEFAULT |
null |
C castModeSome(SQLDialect... dialects)
RenderContext.CastMode.SOME
for a list of dialects.Copyright © 2015. All Rights Reserved.