@@ -122,77 +122,84 @@ private boolean hasMappedStatement(String msId) {
122
122
return configuration .hasStatement (msId , false );
123
123
}
124
124
125
+ /**
126
+ * 创建一个查询的MS
127
+ *
128
+ * @param msId
129
+ * @param sqlSource
130
+ * @param resultType
131
+ */
132
+ private void newSelectMappedStatement (String msId , SqlSource sqlSource , final Class <?> resultType ) {
133
+ MappedStatement ms = new MappedStatement .Builder (configuration , msId , sqlSource , SqlCommandType .SELECT )
134
+ .resultMaps (new ArrayList <ResultMap >() {
135
+ {
136
+ add (new ResultMap .Builder (configuration , "defaultResultMap" , resultType , new ArrayList <ResultMapping >(0 )).build ());
137
+ }
138
+ })
139
+ .build ();
140
+ //缓存
141
+ configuration .addMappedStatement (ms );
142
+ }
143
+
144
+ /**
145
+ * 创建一个简单的MS
146
+ *
147
+ * @param msId
148
+ * @param sqlSource
149
+ * @param sqlCommandType
150
+ */
151
+ private void newUpdateMappedStatement (String msId , SqlSource sqlSource , SqlCommandType sqlCommandType ) {
152
+ MappedStatement ms = new MappedStatement .Builder (configuration , msId , sqlSource , sqlCommandType )
153
+ .resultMaps (new ArrayList <ResultMap >() {
154
+ {
155
+ add (new ResultMap .Builder (configuration , "defaultResultMap" , int .class , new ArrayList <ResultMapping >(0 )).build ());
156
+ }
157
+ })
158
+ .build ();
159
+ //缓存
160
+ configuration .addMappedStatement (ms );
161
+ }
162
+
125
163
private String select (String sql ) {
126
- String msId = newMsId (sql , SqlCommandType .INSERT );
164
+ String msId = newMsId (sql , SqlCommandType .SELECT );
127
165
if (hasMappedStatement (msId )) {
128
166
return msId ;
129
167
}
130
168
StaticSqlSource sqlSource = new StaticSqlSource (configuration , sql );
131
- newSelectMappedStatement (msId , sqlSource , Map .class , SqlCommandType . SELECT );
169
+ newSelectMappedStatement (msId , sqlSource , Map .class );
132
170
return msId ;
133
171
}
134
172
135
173
private String selectDynamic (String sql , Class <?> parameterType ) {
136
- String msId = newMsId (sql , SqlCommandType .INSERT );
174
+ String msId = newMsId (sql + parameterType , SqlCommandType .SELECT );
137
175
if (hasMappedStatement (msId )) {
138
176
return msId ;
139
177
}
140
178
SqlSource sqlSource = languageDriver .createSqlSource (configuration , sql , parameterType );
141
- newSelectMappedStatement (msId , sqlSource , Map .class , SqlCommandType . SELECT );
179
+ newSelectMappedStatement (msId , sqlSource , Map .class );
142
180
return msId ;
143
181
}
144
182
145
183
private String select (String sql , Class <?> resultType ) {
146
- String msId = newMsId (sql , SqlCommandType .INSERT );
184
+ String msId = newMsId (resultType + sql , SqlCommandType .SELECT );
147
185
if (hasMappedStatement (msId )) {
148
186
return msId ;
149
187
}
150
188
StaticSqlSource sqlSource = new StaticSqlSource (configuration , sql );
151
- newSelectMappedStatement (msId , sqlSource , resultType , SqlCommandType . SELECT );
189
+ newSelectMappedStatement (msId , sqlSource , resultType );
152
190
return msId ;
153
191
}
154
192
155
193
private String selectDynamic (String sql , Class <?> parameterType , Class <?> resultType ) {
156
- String msId = newMsId (sql , SqlCommandType .INSERT );
194
+ String msId = newMsId (resultType + sql + parameterType , SqlCommandType .SELECT );
157
195
if (hasMappedStatement (msId )) {
158
196
return msId ;
159
197
}
160
198
SqlSource sqlSource = languageDriver .createSqlSource (configuration , sql , parameterType );
161
- newSelectMappedStatement (msId , sqlSource , resultType , SqlCommandType . SELECT );
199
+ newSelectMappedStatement (msId , sqlSource , resultType );
162
200
return msId ;
163
201
}
164
202
165
- private void newSelectMappedStatement (String msId , SqlSource sqlSource , final Class <?> resultType , SqlCommandType sqlCommandType ) {
166
- MappedStatement ms = new MappedStatement .Builder (configuration , msId , sqlSource , sqlCommandType )
167
- .resultMaps (new ArrayList <ResultMap >() {
168
- {
169
- add (new ResultMap .Builder (configuration , "defaultResultMap" , resultType , new ArrayList <ResultMapping >(0 )).build ());
170
- }
171
- })
172
- .build ();
173
- //缓存
174
- configuration .addMappedStatement (ms );
175
- }
176
-
177
- /**
178
- * 创建一个简单的MS
179
- *
180
- * @param msId
181
- * @param sqlSource
182
- * @param sqlCommandType
183
- */
184
- private void newUpdateMappedStatement (String msId , SqlSource sqlSource , SqlCommandType sqlCommandType ) {
185
- MappedStatement ms = new MappedStatement .Builder (configuration , msId , sqlSource , sqlCommandType )
186
- .resultMaps (new ArrayList <ResultMap >() {
187
- {
188
- add (new ResultMap .Builder (configuration , "defaultResultMap" , int .class , new ArrayList <ResultMapping >(0 )).build ());
189
- }
190
- })
191
- .build ();
192
- //缓存
193
- configuration .addMappedStatement (ms );
194
- }
195
-
196
203
private String insert (String sql ) {
197
204
String msId = newMsId (sql , SqlCommandType .INSERT );
198
205
if (hasMappedStatement (msId )) {
@@ -204,7 +211,7 @@ private String insert(String sql) {
204
211
}
205
212
206
213
private String insertDynamic (String sql , Class <?> parameterType ) {
207
- String msId = newMsId (sql , SqlCommandType .INSERT );
214
+ String msId = newMsId (sql + parameterType , SqlCommandType .INSERT );
208
215
if (hasMappedStatement (msId )) {
209
216
return msId ;
210
217
}
@@ -224,7 +231,7 @@ private String update(String sql) {
224
231
}
225
232
226
233
private String updateDynamic (String sql , Class <?> parameterType ) {
227
- String msId = newMsId (sql , SqlCommandType .UPDATE );
234
+ String msId = newMsId (sql + parameterType , SqlCommandType .UPDATE );
228
235
if (hasMappedStatement (msId )) {
229
236
return msId ;
230
237
}
@@ -244,7 +251,7 @@ private String delete(String sql) {
244
251
}
245
252
246
253
private String deleteDynamic (String sql , Class <?> parameterType ) {
247
- String msId = newMsId (sql , SqlCommandType .DELETE );
254
+ String msId = newMsId (sql + parameterType , SqlCommandType .DELETE );
248
255
if (hasMappedStatement (msId )) {
249
256
return msId ;
250
257
}
0 commit comments