Class StringTemplateEngine
java.lang.Object
org.jdbi.v3.stringtemplate4.StringTemplateEngine
- All Implemented Interfaces:
TemplateEngine, TemplateEngine.Parsing
Rewrites a StringTemplate template, using the attributes on the
StatementContext as template parameters.
For configuration, see StringTemplates.-
Nested Class Summary
Nested classes/interfaces inherited from interface TemplateEngine
TemplateEngine.Parsing -
Field Summary
Fields inherited from interface TemplateEngine
NOP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThe engine is stateless, so all instances of the same class are interchangeable.inthashCode()parse(String sql, ConfigRegistry config) Caches compilation.render(String sql, StatementContext ctx) Non-cached render, for direct callers; the core usesparse(String, ConfigRegistry).
-
Constructor Details
-
StringTemplateEngine
public StringTemplateEngine()
-
-
Method Details
-
render
Non-cached render, for direct callers; the core usesparse(String, ConfigRegistry).- Specified by:
renderin interfaceTemplateEngine- Specified by:
renderin interfaceTemplateEngine.Parsing- Parameters:
sql- 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
Caches compilation. StringTemplate is expensive to compile, and itsSTGroupandSTare not thread-safe, so a compiled template must not be rendered by two threads at once. Compiled prototypes are pooled rather than bound to a thread, so compilation is reused across platform and virtual threads alike: a render checks a prototype out of the pool (compiling one only if the pool is empty), renders a copy, and returns the prototype. The pool holds at mostPOOL_CAPACITYprototypes; a render that finds it empty compiles its own, and a return that finds it full discards.The cached function bypasses
render(String, StatementContext). A subclass that overrides render() must also override this method so the two agree: either returnOptional.empty()to keep the core on the render() path, or return a function with the subclass's semantics.- Specified by:
parsein interfaceTemplateEngine- Specified by:
parsein interfaceTemplateEngine.Parsing- Parameters:
sql- the sql template to parseconfig- the Jdbi configuration at prepare time- Returns:
- a parsed representation, if available
-
equals
The engine is stateless, so all instances of the same class are interchangeable. Equality by class lets the core statement cache reuse compiled templates across instances, e.g. one created per statement or by each@UseStringTemplateEngineannotation. A stateful subclass must override equals and hashCode to keep differently-configured instances apart in the cache. -
hashCode
-