Package org.jdbi.v3.commonstext
Class StringSubstitutorTemplateEngine
- java.lang.Object
-
- org.jdbi.v3.commonstext.StringSubstitutorTemplateEngine
-
- All Implemented Interfaces:
TemplateEngine
public class StringSubstitutorTemplateEngine extends java.lang.Object implements TemplateEngine
Register an instance of this class (SqlStatements.setTemplateEngine(org.jdbi.v3.core.statement.TemplateEngine)) to use an Apache Commons TextStringSubstitutoras aTemplateEngine. This lets you use any pair of strings as variable delimiters, enabling the use of syntax likeselect * from ${foo},select * from <foo>
,select * from %foo%
, etc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jdbi.v3.core.statement.TemplateEngine
TemplateEngine.Parsing
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Consumer<org.apache.commons.text.StringSubstitutor>customizer(package private) static charDEFAULT_ESCAPE(package private) static java.lang.StringDEFAULT_PREFIX(package private) static java.lang.StringDEFAULT_SUFFIX-
Fields inherited from interface org.jdbi.v3.core.statement.TemplateEngine
NOP
-
-
Constructor Summary
Constructors Constructor Description StringSubstitutorTemplateEngine()Default isStringSubstitutorTemplateEngine(java.util.function.Consumer<org.apache.commons.text.StringSubstitutor> customizer)Customize the givenStringSubstitutorinstance to set your preferred prefix, suffix, escape character, and perhaps other configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringSubstitutorTemplateEnginebetween(char prefix, char suffix)static StringSubstitutorTemplateEnginebetween(char prefix, char suffix, char escape)static StringSubstitutorTemplateEnginebetween(java.lang.String prefix, java.lang.String suffix)static StringSubstitutorTemplateEnginebetween(java.lang.String prefix, java.lang.String suffix, char escape)java.lang.Stringrender(java.lang.String template, StatementContext ctx)Renders an SQL statement from the given template, using the statement context as needed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jdbi.v3.core.statement.TemplateEngine
parse
-
-
-
-
Field Detail
-
DEFAULT_PREFIX
static final java.lang.String DEFAULT_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_SUFFIX
static final java.lang.String DEFAULT_SUFFIX
- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE
static final char DEFAULT_ESCAPE
- See Also:
- Constant Field Values
-
customizer
private final java.util.function.Consumer<org.apache.commons.text.StringSubstitutor> customizer
-
-
Constructor Detail
-
StringSubstitutorTemplateEngine
public StringSubstitutorTemplateEngine()
Default is${foo}syntax.
-
StringSubstitutorTemplateEngine
public StringSubstitutorTemplateEngine(java.util.function.Consumer<org.apache.commons.text.StringSubstitutor> customizer)
Customize the givenStringSubstitutorinstance to set your preferred prefix, suffix, escape character, and perhaps other configuration. The instance is created by Jdbi, and is not shared nor re-used. Your customizer function however will be re-used for all instances.
-
-
Method Detail
-
render
public java.lang.String render(java.lang.String template, StatementContext ctx)Description copied from interface:TemplateEngineRenders an SQL statement from the given template, using the statement context as needed.- Specified by:
renderin interfaceTemplateEngine- 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
-
between
public static StringSubstitutorTemplateEngine between(char prefix, char suffix)
-
between
public static StringSubstitutorTemplateEngine between(java.lang.String prefix, java.lang.String suffix)
-
between
public static StringSubstitutorTemplateEngine between(char prefix, char suffix, char escape)
-
between
public static StringSubstitutorTemplateEngine between(java.lang.String prefix, java.lang.String suffix, char escape)
-
-