- All Known Implementing Classes:
SqlTemplateImpl
public interface SqlTemplate
SqlTemplate relies on preview features of the Java platform:
SqlTemplaterefers to one or more preview APIs:StringTemplate.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A template processor for generating SQL queries. While this interface can be used directly, developers are encouraged
to leverage the higher-level abstractions provided by the framework, as they are likely more useful and convenient
for most use cases.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA listener for batch events within a SQL query context.static interfaceManages the binding of variables in a SQL query.static final recordRepresents a named parameter that can be used in a SQL query.static interfaceRepresents a parameter that can be used in a SQL query.static final recordRepresents a positional parameter that can be used in a SQL query.static interfaceA listener for record events within a SQL query context. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SqlTemplateThe default SQL template that is optimized for JPA.static final SqlTemplateThe default SQL template that is optimized for prepared statements. -
Method Summary
Modifier and TypeMethodDescriptionReturns the column name resolver that is used by this template.Create a new bind variables instance that can be used to add bind variables to a batch.dialect()Returns the SQL dialect that is used by this template.booleanReturnstrueif collection parameters must be expanded as multiple (positional) parameters,falseotherwise.Returns the foreign key resolver that is used by this template.booleanReturnstrueif the template only support positional parameters,falseotherwise.process(StringTemplatePREVIEW template) Processes the specifiedtemplateand returns the resulting SQL and parameters.booleanReturnstrueif the template supports tables represented as records,falseotherwise.Returns the table alias resolver that is used by this template.Returns the table name resolver that is used by this template.withColumnNameResolver(ColumnNameResolver resolver) Returns a new SQL template with the specified column name resolver.withDialect(SqlDialect dialect) Returns a new SQL template with the specified SQL dialect.withForeignKeyResolver(ForeignKeyResolver resolver) Returns a new SQL template with the specified foreign key resolver.withSupportRecords(boolean supportRecords) Returns a new SQL template with support for records enabled or disabled.withTableAliasResolver(TableAliasResolver resolver) Returns a new SQL template with the specified table alias resolver.withTableNameResolver(TableNameResolver resolver) Returns a new SQL template with the specified table name resolver.
-
Field Details
-
PS
The default SQL template that is optimized for prepared statements. -
JPA
The default SQL template that is optimized for JPA.
-
-
Method Details
-
createBindVars
BindVars createBindVars()Create a new bind variables instance that can be used to add bind variables to a batch.- Returns:
- a new bind variables instance.
-
positionalOnly
boolean positionalOnly()Returnstrueif the template only support positional parameters,falseotherwise.- Returns:
trueif the template only support positional parameters,falseotherwise.
-
expandCollection
boolean expandCollection()Returnstrueif collection parameters must be expanded as multiple (positional) parameters,falseotherwise.- Returns:
trueif the template expands collection parameters,falseotherwise.
-
withSupportRecords
Returns a new SQL template with support for records enabled or disabled.- Parameters:
supportRecords-trueif the template should support records,falseotherwise.- Returns:
- a new SQL template.
-
supportRecords
boolean supportRecords()Returnstrueif the template supports tables represented as records,falseotherwise.- Returns:
trueif the template supports records,falseotherwise.
-
withTableNameResolver
Returns a new SQL template with the specified table name resolver.- Parameters:
resolver- the table name resolver.- Returns:
- a new SQL template.
-
tableNameResolver
TableNameResolver tableNameResolver()Returns the table name resolver that is used by this template.- Returns:
- the table name resolver that is used by this template.
-
withTableAliasResolver
Returns a new SQL template with the specified table alias resolver.- Parameters:
resolver- the table alias resolver.- Returns:
- a new SQL template.
-
tableAliasResolver
TableAliasResolver tableAliasResolver()Returns the table alias resolver that is used by this template.- Returns:
- the table alias resolver that is used by this template.
-
withColumnNameResolver
Returns a new SQL template with the specified column name resolver.- Parameters:
resolver- the column name resolver.- Returns:
- a new SQL template.
-
columnNameResolver
ColumnNameResolver columnNameResolver()Returns the column name resolver that is used by this template.- Returns:
- the column name resolver that is used by this template.
-
withForeignKeyResolver
Returns a new SQL template with the specified foreign key resolver.- Parameters:
resolver- the foreign key resolver.- Returns:
- a new SQL template.
-
foreignKeyResolver
ForeignKeyResolver foreignKeyResolver()Returns the foreign key resolver that is used by this template.- Returns:
- the foreign key resolver that is used by this template.
-
withDialect
Returns a new SQL template with the specified SQL dialect.- Parameters:
dialect- the SQL dialect to use.- Returns:
- a new SQL template.
-
dialect
SqlDialect dialect()Returns the SQL dialect that is used by this template.- Returns:
- the SQL dialect that is used by this template.
- Since:
- 1.2
-
process
Processes the specifiedtemplateand returns the resulting SQL and parameters.- Parameters:
template- the string template to process.- Returns:
- the resulting SQL and parameters.
- Throws:
SqlTemplateException- if an error occurs while processing the input.
-
SqlTemplatewhen preview features are enabled.