Package org.jdbi.v3.core.statement
Interface TemplateEngine
- All Known Subinterfaces:
TemplateEngine.Parsing
- All Known Implementing Classes:
DefinedAttributeTemplateEngine
,FreemarkerEngine
,StringSubstitutorTemplateEngine
,StringTemplateEngine
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Renders an SQL statement from a template.
Note for implementors: define a suitable public constructor for SqlObject's
UseTemplateEngine
annotation, and/or create your own custom annotation in case your TemplateEngine
has configuration parameters! Suitable constructors are the no-arg constructor, one that takes a Class
, and one that takes both a Class
and a Method
.- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final TemplateEngine
Convenience constant that returns the input template. -
Method Summary
Modifier and TypeMethodDescriptiondefault Optional<Function<StatementContext,
String>> parse
(String template, ConfigRegistry config) Parse a SQL template and return a parsed representation ready to apply to a statement.render
(String template, StatementContext ctx) Renders an SQL statement from the given template, using the statement context as needed.
-
Field Details
-
NOP
Convenience constant that returns the input template.
-
-
Method Details
-
render
Renders an SQL statement from the given template, using the statement context as needed.- Parameters:
template
- The SQL to rewritectx
- The statement context for the statement being executed- Returns:
- something which can provide the actual SQL to prepare a statement from and which can bind the correct arguments to that prepared statement
-
parse
@Beta default Optional<Function<StatementContext,String>> parse(String template, ConfigRegistry config) Parse a SQL template and return a parsed representation ready to apply to a statement. This allows the parsed representation to be cached and reused.- Parameters:
template
- the sql template to parseconfig
- the Jdbi configuration at prepare time- Returns:
- a parsed representation, if available
-