|
19 | 19 |
|
20 | 20 | import org.mybatis.dynamic.sql.BindableColumn;
|
21 | 21 |
|
| 22 | +/** |
| 23 | + * A rendering strategy is used to generate a platform specific binding. |
| 24 | + * <p> |
| 25 | + * Rendering strategies are used during the rendering phase of statement generation. |
| 26 | + * All generated SQL statements include the generated statement itself, and a map of parameters that |
| 27 | + * should be bound to the statement at execution time. For example, a generated select statement may |
| 28 | + * look like this when rendered for MyBatis: |
| 29 | + * <p> |
| 30 | + * <code>select foo from bar where id = #{parameters.p1,jdbcType=INTEGER}</code> |
| 31 | + * <p> |
| 32 | + * In this case, the binding is <code>#{parameters.p1,jdbcType=INTEGER}</code>. MyBatis knows how to interpret this |
| 33 | + * binding - it will look for a value in the <code>parameters.p1</code> property of the parameter object |
| 34 | + * passed to the statement and bind it as a prepared statement parameter when executing the statement. |
| 35 | + */ |
22 | 36 | public abstract class RenderingStrategy {
|
23 | 37 | public static final String DEFAULT_PARAMETER_PREFIX = "parameters"; //$NON-NLS-1$
|
24 | 38 |
|
25 | 39 | public String formatParameterMapKey(AtomicInteger sequence) {
|
26 | 40 | return "p" + sequence.getAndIncrement(); //$NON-NLS-1$
|
27 | 41 | }
|
28 | 42 |
|
| 43 | + /** |
| 44 | + * This method generates a binding for a parameter to a placeholder in a generated SQL statement. |
| 45 | + * <p> |
| 46 | + * This binding is appropriate when there can be a mapping between a parameter and a known target column, |
| 47 | + * In MyBatis, the binding can specify type information based on the column. The bindings are specific |
| 48 | + * to the target framework. |
| 49 | + * <p> |
| 50 | + * For MyBatis, a binding looks like this: "#{prefix.parameterName,jdbcType=xxx,typeHandler=xxx,javaType=xxx}" |
| 51 | + * <p> |
| 52 | + * For Spring, a binding looks like this: ":parameterName" |
| 53 | + * |
| 54 | + * @param column column definition used for generating type details in a MyBatis binding. Ignored for Spring. |
| 55 | + * @param prefix parameter prefix used for locating the parameters in a SQL provider object. Typically, will be |
| 56 | + * {@link RenderingStrategy#DEFAULT_PARAMETER_PREFIX}. This is ignored for Spring. |
| 57 | + * @param parameterName name of the parameter. Typically generated by calling |
| 58 | + * {@link RenderingStrategy#formatParameterMapKey(AtomicInteger)} |
| 59 | + * @return the generated binding |
| 60 | + */ |
29 | 61 | public abstract String getFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName);
|
30 | 62 |
|
| 63 | + /** |
| 64 | + * This method generates a binding for a parameter to a placeholder in a generated SQL statement. |
| 65 | + * <p> |
| 66 | + * This binding is appropriate when the parameter is bound to placeholder that is not a known column (such as |
| 67 | + * a limit or offset parameter). The bindings are specific to the target framework. |
| 68 | + * <p> |
| 69 | + * For MyBatis, a binding looks like this: "#{prefix.parameterName}" |
| 70 | + * <p> |
| 71 | + * For Spring, a binding looks like this: ":parameterName" |
| 72 | + * |
| 73 | + * @param prefix parameter prefix used for locating the parameters in a SQL provider object. Typically, will be |
| 74 | + * {@link RenderingStrategy#DEFAULT_PARAMETER_PREFIX}. This is ignored for Spring. |
| 75 | + * @param parameterName name of the parameter. Typically generated by calling |
| 76 | + * {@link RenderingStrategy#formatParameterMapKey(AtomicInteger)} |
| 77 | + * @return the generated binding |
| 78 | + */ |
31 | 79 | public abstract String getFormattedJdbcPlaceholder(String prefix, String parameterName);
|
32 | 80 |
|
| 81 | + /** |
| 82 | + * This method generates a binding for a parameter to a placeholder in a generated multirow insert statement. |
| 83 | + * <p> |
| 84 | + * This binding is specifically for use with a multirow insert. The Spring implementation changes the binding |
| 85 | + * to match values expected for a multirow insert statement. For MyBatis, the binding is the same |
| 86 | + * as {@link RenderingStrategy#getFormattedJdbcPlaceholder(BindableColumn, String, String)}. |
| 87 | + * <p> |
| 88 | + * For MyBatis, a binding looks like this: "#{prefix.parameterName,jdbcType=xxx,typeHandler=xxx,javaType=xxx}" |
| 89 | + * <p> |
| 90 | + * For Spring, a binding looks like this: ":prefix.parameterName" |
| 91 | + * |
| 92 | + * @param column column definition used for generating type details in a MyBatis binding. Ignored for Spring. |
| 93 | + * @param prefix parameter prefix used for locating the parameters in a SQL provider object. Typically, will be |
| 94 | + * {@link RenderingStrategy#DEFAULT_PARAMETER_PREFIX}. This is ignored for Spring. |
| 95 | + * @param parameterName name of the parameter. Typically generated by calling |
| 96 | + * {@link RenderingStrategy#formatParameterMapKey(AtomicInteger)} |
| 97 | + * @return the generated binding |
| 98 | + */ |
33 | 99 | public String getMultiRowFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName) {
|
34 | 100 | return getFormattedJdbcPlaceholder(column, prefix, parameterName);
|
35 | 101 | }
|
|
0 commit comments