18
18
import freemarker .cache .ClassTemplateLoader ;
19
19
import freemarker .cache .TemplateLoader ;
20
20
import freemarker .template .Template ;
21
+
22
+ import java .io .IOException ;
23
+ import java .io .InputStream ;
24
+ import java .io .StringReader ;
25
+ import java .util .Properties ;
26
+
21
27
import org .apache .ibatis .executor .parameter .ParameterHandler ;
22
28
import org .apache .ibatis .mapping .BoundSql ;
23
29
import org .apache .ibatis .mapping .MappedStatement ;
27
33
import org .apache .ibatis .scripting .defaults .DefaultParameterHandler ;
28
34
import org .apache .ibatis .session .Configuration ;
29
35
30
- import java .io .IOException ;
31
- import java .io .InputStream ;
32
- import java .io .StringReader ;
33
- import java .util .Properties ;
34
-
35
36
/**
36
37
* Adds FreeMarker templates support to scripting in MyBatis.
37
38
* If you want to change or extend template loader configuration, use can
@@ -71,7 +72,30 @@ public FreeMarkerLanguageDriver() {
71
72
}
72
73
73
74
/**
74
- * Creates a {@link ParameterHandler} that passes the actual parameters to the the JDBC statement.
75
+ * Creates the {@link freemarker.template.Configuration} instance
76
+ * and sets it up. If you want to change it (set another props, for
77
+ * example), you can override it in inherited class and use your own
78
+ * class in @Lang directive.
79
+ */
80
+ protected freemarker .template .Configuration createFreeMarkerConfiguration () {
81
+ freemarker .template .Configuration cfg = new freemarker .template .Configuration (
82
+ freemarker .template .Configuration .VERSION_2_3_22 );
83
+
84
+ TemplateLoader templateLoader = new ClassTemplateLoader (this .getClass ().getClassLoader (), basePackage );
85
+ cfg .setTemplateLoader (templateLoader );
86
+
87
+ // To avoid formatting numbers using spaces and commas in SQL
88
+ cfg .setNumberFormat ("computer" );
89
+
90
+ // Because it defaults to default system encoding, we should set it always explicitly
91
+ cfg .setDefaultEncoding ("utf-8" );
92
+
93
+ return cfg ;
94
+ }
95
+
96
+ /**
97
+ * Creates a {@link ParameterHandler} that passes the actual parameters
98
+ * to the the JDBC statement.
75
99
*
76
100
* @see DefaultParameterHandler
77
101
* @param mappedStatement The mapped statement that is being executed
@@ -86,52 +110,35 @@ public ParameterHandler createParameterHandler(MappedStatement mappedStatement,
86
110
}
87
111
88
112
/**
89
- * Creates an {@link SqlSource} that will hold the statement read from a mapper xml file.
90
- * It is called during startup, when the mapped statement is read from a class or an xml file.
113
+ * Creates an {@link SqlSource} that will hold the statement read
114
+ * from a mapper xml file. It is called during startup, when the
115
+ * mapped statement is read from a class or an xml file.
91
116
*
92
117
* @param configuration The MyBatis configuration
93
118
* @param script XNode parsed from a XML file
94
- * @param parameterType input parameter type got from a mapper method or specified in the parameterType xml attribute. Can be null.
119
+ * @param parameterType input parameter type got from a mapper method
120
+ * or specified in the parameterType xml attribute. Can be null.
95
121
*/
96
122
@ Override
97
123
public SqlSource createSqlSource (Configuration configuration , XNode script , Class <?> parameterType ) {
98
124
return createSqlSource (configuration , script .getNode ().getTextContent ());
99
125
}
100
126
101
127
/**
102
- * Creates an {@link SqlSource} that will hold the statement read from an annotation.
103
- * It is called during startup, when the mapped statement is read from a class or an xml file.
128
+ * Creates an {@link SqlSource} that will hold the statement read
129
+ * from an annotation. It is called during startup, when the mapped
130
+ * statement is read from a class or an xml file.
104
131
*
105
132
* @param configuration The MyBatis configuration
106
133
* @param script The content of the annotation
107
- * @param parameterType input parameter type got from a mapper method or specified in the parameterType xml attribute. Can be null.
134
+ * @param parameterType input parameter type got from a mapper method
135
+ * or specified in the parameterType xml attribute. Can be null.
108
136
*/
109
137
@ Override
110
138
public SqlSource createSqlSource (Configuration configuration , String script , Class <?> parameterType ) {
111
139
return createSqlSource (configuration , script );
112
140
}
113
141
114
- /**
115
- * Creates the {@link freemarker.template.Configuration} instance and sets it up.
116
- * If you want to change it (set another props, for example), you can override it in
117
- * inherited class and use your own class in @Lang directive.
118
- */
119
- protected freemarker .template .Configuration createFreeMarkerConfiguration () {
120
- freemarker .template .Configuration cfg = new freemarker .template .Configuration (
121
- freemarker .template .Configuration .VERSION_2_3_22 );
122
-
123
- TemplateLoader templateLoader = new ClassTemplateLoader (this .getClass ().getClassLoader (), basePackage );
124
- cfg .setTemplateLoader (templateLoader );
125
-
126
- // To avoid formatting numbers using spaces and commas in SQL
127
- cfg .setNumberFormat ("computer" );
128
-
129
- // Because it defaults to default system encoding, we should set it always explicitly
130
- cfg .setDefaultEncoding ("utf-8" );
131
-
132
- return cfg ;
133
- }
134
-
135
142
protected SqlSource createSqlSource (Template template , Configuration configuration ) {
136
143
return new FreeMarkerSqlSource (template , configuration );
137
144
}
@@ -156,4 +163,5 @@ private SqlSource createSqlSource(Configuration configuration, String scriptText
156
163
157
164
return createSqlSource (template , configuration );
158
165
}
166
+
159
167
}
0 commit comments