Interface TemplateEngine

All Known Subinterfaces:
TemplateEngine.Parsing
All Known Implementing Classes:
DefinedAttributeTemplateEngine, FreemarkerEngine, NoTemplateEngine, 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.

@FunctionalInterface public interface TemplateEngine
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

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TemplateEngine
    Convenience constant that returns the input template.
  • Method Summary

    Modifier and Type
    Method
    Description
    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

      static final TemplateEngine NOP
      Convenience constant that returns the input template.
  • Method Details

    • render

      String render(String template, StatementContext ctx)
      Renders an SQL statement from the given template, using the statement context as needed.
      Parameters:
      template - The SQL to rewrite
      ctx - 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 parse
      config - the Jdbi configuration at prepare time
      Returns:
      a parsed representation, if available