Class RenderingStrategy
- Direct Known Subclasses:
MyBatis3RenderingStrategy,SpringNamedParameterRenderingStrategy
Rendering strategies are used during the rendering phase of statement generation. All generated SQL statements include the generated statement itself, and a map of parameters that should be bound to the statement at execution time. For example, a generated select statement may look like this when rendered for MyBatis:
select foo from bar where id = #{parameters.p1,jdbcType=INTEGER}
In this case, the binding is #{parameters.p1,jdbcType=INTEGER}. MyBatis knows how to interpret this
binding - it will look for a value in the parameters.p1 property of the parameter object
passed to the statement and bind it as a prepared statement parameter when executing the statement.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformatParameterMapKey(AtomicInteger sequence) Generate a unique key that can be used to place a parameter value in the parameter map.Return a parameter map key intended as a parameter for a fetch first query.formatParameterMapKeyForLimit(AtomicInteger sequence) Return a parameter map key intended as a parameter for a limit query.formatParameterMapKeyForOffset(AtomicInteger sequence) Return a parameter map key intended as a parameter for a query offset.abstract StringgetFormattedJdbcPlaceholder(String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a generated SQL statement.abstract StringgetFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a generated SQL statement.getFormattedJdbcPlaceholderForPagingParameters(String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a generated SQL statement.abstract StringgetRecordBasedInsertBinding(BindableColumn<?> column, String parameterName) This method generates a binding for a parameter to a placeholder in a row based insert statement.getRecordBasedInsertBinding(BindableColumn<?> column, String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a row based insert statement.
-
Field Details
-
DEFAULT_PARAMETER_PREFIX
- See Also:
-
-
Constructor Details
-
RenderingStrategy
public RenderingStrategy()
-
-
Method Details
-
formatParameterMapKey
Generate a unique key that can be used to place a parameter value in the parameter map.- Parameters:
sequence- a sequence for calculating a unique value- Returns:
- a key used to place the parameter value in the parameter map
-
formatParameterMapKeyForFetchFirstRows
Return a parameter map key intended as a parameter for a fetch first query.By default, this parameter is treated the same as any other. This method is a hook to support MyBatis Spring Batch.
- Parameters:
sequence- a sequence for calculating a unique value- Returns:
- a key used to place the parameter value in the parameter map
-
formatParameterMapKeyForLimit
Return a parameter map key intended as a parameter for a limit query.By default, this parameter is treated the same as any other. This method is a hook to support MyBatis Spring Batch.
- Parameters:
sequence- a sequence for calculating a unique value- Returns:
- a key used to place the parameter value in the parameter map
-
formatParameterMapKeyForOffset
Return a parameter map key intended as a parameter for a query offset.By default, this parameter is treated the same as any other. This method is a hook to support MyBatis Spring Batch.
- Parameters:
sequence- a sequence for calculating a unique value- Returns:
- a key used to place the parameter value in the parameter map
-
getFormattedJdbcPlaceholder
public abstract String getFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a generated SQL statement.This binding is appropriate when there can be a mapping between a parameter and a known target column, In MyBatis, the binding can specify type information based on the column. The bindings are specific to the target framework.
For MyBatis, a binding looks like this: "#{prefix.parameterName,jdbcType=xxx,typeHandler=xxx,javaType=xxx}"
For Spring, a binding looks like this: ":parameterName"
- Parameters:
column- column definition used for generating type details in a MyBatis binding. Ignored for Spring.prefix- parameter prefix used for locating the parameters in a SQL provider object. Typically, will beDEFAULT_PARAMETER_PREFIX. This is ignored for Spring.parameterName- name of the parameter. Typically generated by callingformatParameterMapKey(AtomicInteger)- Returns:
- the generated binding
-
getFormattedJdbcPlaceholder
This method generates a binding for a parameter to a placeholder in a generated SQL statement.This binding is appropriate when the parameter is bound to placeholder that is not a known column (such as a limit or offset parameter). The bindings are specific to the target framework.
For MyBatis, a binding looks like this: "#{prefix.parameterName}"
For Spring, a binding looks like this: ":parameterName"
- Parameters:
prefix- parameter prefix used for locating the parameters in a SQL provider object. Typically, will beDEFAULT_PARAMETER_PREFIX. This is ignored for Spring.parameterName- name of the parameter. Typically generated by callingformatParameterMapKey(AtomicInteger)- Returns:
- the generated binding
-
getFormattedJdbcPlaceholderForPagingParameters
This method generates a binding for a parameter to a placeholder in a generated SQL statement.This method is used to generate bindings for limit, offset, and fetch first parameters. By default, these parameters are treated the same as any other. This method supports MyBatis Spring Batch integration where the parameter keys have predefined values and need special handling.
- Parameters:
prefix- parameter prefix used for locating the parameters in a SQL provider object. Typically, will beDEFAULT_PARAMETER_PREFIX. This is ignored for Spring.parameterName- name of the parameter. Typically generated by callingformatParameterMapKey(AtomicInteger)- Returns:
- the generated binding
-
getRecordBasedInsertBinding
public String getRecordBasedInsertBinding(BindableColumn<?> column, String prefix, String parameterName) This method generates a binding for a parameter to a placeholder in a row based insert statement.This binding is specifically for use with insert, batch insert, and multirow insert statements. These statements bind parameters to properties of a row class. The Spring implementation changes the binding to match values expected for a these insert statements. For MyBatis, the binding is the same as
getFormattedJdbcPlaceholder(BindableColumn, String, String).For MyBatis, a binding looks like this: "#{prefix.parameterName,jdbcType=xxx,typeHandler=xxx,javaType=xxx}"
For Spring, a binding looks like this: ":prefix.parameterName"
- Parameters:
column- column definition used for generating type details in a MyBatis binding. Ignored for Spring.prefix- parameter prefix used for locating the parameters in a SQL provider object. Typically, will be either "row" or "records[x]" to match the properties of the generated statement object class.parameterName- name of the parameter. Typically, this is a property in the row class associated with the insert statement.- Returns:
- the generated binding
-
getRecordBasedInsertBinding
This method generates a binding for a parameter to a placeholder in a row based insert statement.This binding is specifically for use with insert, batch insert, and multirow insert statements and the MapToRow mapping. These statements bind parameters to the row class directly.
For MyBatis, a binding looks like this: "#{parameterName,jdbcType=xxx,typeHandler=xxx,javaType=xxx}"
For Spring, a binding looks like this: ":parameterName"
- Parameters:
column- column definition used for generating type details in a MyBatis binding. Ignored for Spring.parameterName- name of the parameter. Typically, will be either "row" or "records[x]" to match the properties of the generated statement object class.- Returns:
- the generated binding
-