java.lang.Object
io.github.mmm.property.criteria.CriteriaFormatter
- All Implemented Interfaces:
CriteriaVisitor
A formatter to format
CriteriaExpression
s to database specific notation (e.g. SQL) as
string
to a given Appendable
(see out()
). See of*
methods to create instances. For specific
database dialects simply create a subclass of this CriteriaFormatter
.- Since:
- 1.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.github.mmm.base.io.AppendableWriter
Appendable
where toappend
the SQL. -
Constructor Summary
ConstructorsModifierConstructorDescriptionThe constructor using inlineCriteriaParameters
.protected
CriteriaFormatter
(CriteriaParameters parameters, io.github.mmm.base.io.AppendableWriter out) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
convertLikePattern
(String glob) static boolean
isUseBrackets
(CriteriaExpression<?> expression, CriteriaExpression<?> parent) static CriteriaFormatter
of
(CriteriaParameters parameters, io.github.mmm.base.io.AppendableWriter appendable) static CriteriaFormatter
of
(CriteriaParameters parameters, Appendable appendable) static CriteriaFormatter
static CriteriaFormatter
ofIndexedParameters
(io.github.mmm.base.io.AppendableWriter appendable) static CriteriaFormatter
ofIndexedParameters
(Appendable appendable) static CriteriaFormatter
ofNamedParameters
(io.github.mmm.base.io.AppendableWriter appendable, boolean merge) static CriteriaFormatter
ofNamedParameters
(Appendable appendable) static CriteriaFormatter
ofNamedParameters
(Appendable appendable, boolean merge) void
Writes the givenalias
.onExpression
(CriteriaExpression<?> expression, CriteriaExpression<?> parent) void
onLiteral
(Literal<?> literal, int i, CriteriaExpression<?> parent) void
onOperator
(CriteriaOperator operator) void
onOrdering
(CriteriaOrdering ordering) void
onProjectionProperty
(ProjectionProperty<?> arg, int i, CriteriaExpression<?> parent) void
onPropertyPath
(io.github.mmm.value.PropertyPath<?> property, int i, CriteriaExpression<?> parent) void
onUndefinedArg
(io.github.mmm.value.CriteriaObject<?> arg, int i, CriteriaExpression<?> parent) io.github.mmm.base.io.AppendableWriter
out()
void
setLikeSyntaxSource
(LikePatternSyntax likeSyntaxSource) void
setLikeSyntaxTarget
(LikePatternSyntax likeSyntaxTarget) toString()
protected void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.github.mmm.property.criteria.CriteriaVisitor
onArg, onExpression
-
Field Details
-
out
protected final io.github.mmm.base.io.AppendableWriter outAppendable
where toappend
the SQL.
-
-
Constructor Details
-
CriteriaFormatter
public CriteriaFormatter()The constructor using inlineCriteriaParameters
.
ATTENTION: Only use this for testing or debugging (e.g. intoString()
) to avoid SQL-injection security vulnerabilities. -
CriteriaFormatter
protected CriteriaFormatter(CriteriaParameters parameters, io.github.mmm.base.io.AppendableWriter out) The constructor.- Parameters:
parameters
- theCriteriaParameters
ornull
for default (inline). ATTENTION: Usenull
only for testing or debugging (e.g. intoString()
) to avoid SQL-injection security vulnerabilities.out
- theAppendable
towrite
to.
-
-
Method Details
-
getLikeSyntaxSource
- Returns:
- likeSyntaxSource
-
setLikeSyntaxSource
- Parameters:
likeSyntaxSource
- new value ofgetLikeSyntaxSource()
.
-
getLikeSyntaxTarget
- Returns:
- likeSyntaxTarget
-
setLikeSyntaxTarget
- Parameters:
likeSyntaxTarget
- new value ofgetLikeSyntaxTarget()
.
-
write
- Parameters:
text
- the database syntax to append.
-
out
public io.github.mmm.base.io.AppendableWriter out()- Returns:
- the
AppendableWriter
wrapping theAppendable
to write to.
-
getParameters
- Returns:
- the
CriteriaParameters
.
-
onExpression
public CriteriaFormatter onExpression(CriteriaExpression<?> expression, CriteriaExpression<?> parent) - Specified by:
onExpression
in interfaceCriteriaVisitor
- Parameters:
expression
- theCriteriaExpression
to visit.parent
- the parentCriteriaExpression
ornull
ifexpression
is the rootCriteriaExpression
.- Returns:
- this visitor itself for fluent API calls.
-
isUseBrackets
- Parameters:
expression
- theCriteriaExpression
to consider enclosing in brackets.parent
- the parentCriteriaExpression
usingexpression
asargument
.- Returns:
true
ifexpression
needs to be enclosed in brackets,false
otherwise.
-
onOperator
- Specified by:
onOperator
in interfaceCriteriaVisitor
- Parameters:
operator
- theCriteriaOperator
to visit.
-
onPropertyPath
public void onPropertyPath(io.github.mmm.value.PropertyPath<?> property, int i, CriteriaExpression<?> parent) - Specified by:
onPropertyPath
in interfaceCriteriaVisitor
- Parameters:
property
- thePropertyPath
to visit.i
- theindex
ofarg
in thearguments
.parent
- the parentCriteriaExpression
to owning the givenPropertyPath
.- See Also:
-
onProjectionProperty
- Specified by:
onProjectionProperty
in interfaceCriteriaVisitor
- Parameters:
arg
- theProjectionProperty
.i
- theindex
ofarg
in thearguments
.parent
- the parentCriteriaExpression
owning the givenarg
.
-
onAlias
Writes the givenalias
. Override towrite
"AS " as prefix if required or desired.- Parameters:
alias
- the alias towrite
.
-
onLiteral
- Specified by:
onLiteral
in interfaceCriteriaVisitor
- Parameters:
literal
- theLiteral
to visit.i
- theindex
ofarg
in thearguments
.parent
- the parentCriteriaExpression
to owning the givenLiteral
.- See Also:
-
convertLikePattern
- Parameters:
glob
- the literal value for a LIKE expression assumed in glob-syntax.- Returns:
- the given
glob
String
converted to LIKE pattern.
-
onUndefinedArg
public void onUndefinedArg(io.github.mmm.value.CriteriaObject<?> arg, int i, CriteriaExpression<?> parent) - Specified by:
onUndefinedArg
in interfaceCriteriaVisitor
- Parameters:
arg
- the undefined arg (if noLiteral
,PropertyPath
orCriteriaExpression
).i
- theindex
ofarg
in thearguments
.parent
- the parentCriteriaExpression
owning the givenarg
.- See Also:
-
onOrdering
- Parameters:
ordering
- theCriteriaOrdering
to format to append.
-
toString
-
of
- Parameters:
parameters
- theCriteriaParameters
.appendable
- theAppendable
where to write the database syntax to.- Returns:
- the new
CriteriaFormatter
.
-
of
public static CriteriaFormatter of(CriteriaParameters parameters, io.github.mmm.base.io.AppendableWriter appendable) - Parameters:
parameters
- theCriteriaParameters
.appendable
- theAppendableWriter
where to write the database syntax to.- Returns:
- the new
CriteriaFormatter
.
-
ofIndexedParameters
- Returns:
- the new
CriteriaFormatter
usingindexed parameters
.
-
ofIndexedParameters
- Parameters:
appendable
- theAppendable
where to write the database syntax to.- Returns:
- the new
CriteriaFormatter
usingindexed parameters
.
-
ofIndexedParameters
public static CriteriaFormatter ofIndexedParameters(io.github.mmm.base.io.AppendableWriter appendable) - Parameters:
appendable
- theAppendableWriter
where to write the database syntax to.- Returns:
- the new
CriteriaFormatter
usingindexed parameters
.
-
ofNamedParameters
- Parameters:
appendable
- theAppendable
where to write the database syntax to.- Returns:
- the new
CriteriaFormatter
usingnamed parameters
.
-
ofNamedParameters
- Parameters:
appendable
- theAppendable
where to write the database syntax to.merge
- themerge flag
.- Returns:
- the new
CriteriaFormatter
usingnamed parameters
.
-
ofNamedParameters
public static CriteriaFormatter ofNamedParameters(io.github.mmm.base.io.AppendableWriter appendable, boolean merge) - Parameters:
appendable
- theAppendableWriter
where to write the database syntax to.merge
- themerge flag
.- Returns:
- the new
CriteriaFormatter
usingnamed parameters
.
-