Skip to content

Commit d2d8651

Browse files
committed
Some documentation for rendering strategies
1 parent a0f26a3 commit d2d8651

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/main/java/org/mybatis/dynamic/sql/render/RenderingStrategy.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,83 @@
1919

2020
import org.mybatis.dynamic.sql.BindableColumn;
2121

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+
*/
2236
public abstract class RenderingStrategy {
2337
public static final String DEFAULT_PARAMETER_PREFIX = "parameters"; //$NON-NLS-1$
2438

2539
public String formatParameterMapKey(AtomicInteger sequence) {
2640
return "p" + sequence.getAndIncrement(); //$NON-NLS-1$
2741
}
2842

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+
*/
2961
public abstract String getFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName);
3062

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+
*/
3179
public abstract String getFormattedJdbcPlaceholder(String prefix, String parameterName);
3280

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+
*/
3399
public String getMultiRowFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName) {
34100
return getFormattedJdbcPlaceholder(column, prefix, parameterName);
35101
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy