@@ -158,12 +158,7 @@ public String selectByPrimaryKey(final Map<String, Object> params) {
158
158
notNullKeyProperty (column .getProperty (), entity );
159
159
WHERE (column .getColumn () + "=#{key}" );
160
160
} else {
161
- MetaObject metaObject = MapperTemplate .forObject (entity );
162
- for (EntityHelper .EntityColumn column : entityTable .getEntityClassPKColumns ()) {
163
- Object value = metaObject .getValue (column .getProperty ());
164
- notNullKeyProperty (column .getProperty (), value );
165
- WHERE (column .getColumn () + "=#{key." + column .getProperty () + "}" );
166
- }
161
+ applyWherePk (this , MapperTemplate .forObject (entity ), entityTable .getEntityClassPKColumns (), "key" );
167
162
}
168
163
}}.toString ();
169
164
}
@@ -176,7 +171,6 @@ public String selectByPrimaryKey(final Map<String, Object> params) {
176
171
*/
177
172
public String insert (final Map <String , Object > params ) {
178
173
return new SQL () {{
179
- Object entity = getEntity (params );
180
174
Class <?> entityClass = getEntityClass (params );
181
175
EntityHelper .EntityTable entityTable = EntityHelper .getEntityTable (entityClass );
182
176
INSERT_INTO (entityTable .getName ());
@@ -259,12 +253,7 @@ public String deleteByPrimaryKey(final Map<String, Object> params) {
259
253
notNullKeyProperty (column .getProperty (), entity );
260
254
WHERE (column .getColumn () + "=#{key}" );
261
255
} else {
262
- MetaObject metaObject = MapperTemplate .forObject (entity );
263
- for (EntityHelper .EntityColumn column : entityTable .getEntityClassPKColumns ()) {
264
- Object value = metaObject .getValue (column .getProperty ());
265
- notNullKeyProperty (column .getProperty (), value );
266
- WHERE (column .getColumn () + "=#{key." + column .getProperty () + "}" );
267
- }
256
+ applyWherePk (this , MapperTemplate .forObject (entity ), entityTable .getEntityClassPKColumns (), "key" );
268
257
}
269
258
}}.toString ();
270
259
}
@@ -288,17 +277,7 @@ public String updateByPrimaryKey(final Map<String, Object> params) {
288
277
SET (column .getColumn () + "=#{record." + column .getProperty () + "}" );
289
278
}
290
279
}
291
- if (entityTable .getEntityClassPKColumns ().size () == 1 ) {
292
- EntityHelper .EntityColumn column = entityTable .getEntityClassPKColumns ().iterator ().next ();
293
- notNullKeyProperty (column .getProperty (), metaObject .getValue (column .getProperty ()));
294
- WHERE (column .getColumn () + "=#{record." + column .getProperty () + "}" );
295
- } else {
296
- for (EntityHelper .EntityColumn column : entityTable .getEntityClassPKColumns ()) {
297
- Object value = metaObject .getValue (column .getProperty ());
298
- notNullKeyProperty (column .getProperty (), value );
299
- WHERE (column .getColumn () + "=#{record." + column .getProperty () + "}" );
300
- }
301
- }
280
+ applyWherePk (this , metaObject , entityTable .getEntityClassPKColumns (), "record" );
302
281
}}.toString ();
303
282
}
304
283
@@ -322,16 +301,7 @@ public String updateByPrimaryKeySelective(final Map<String, Object> params) {
322
301
SET (column .getColumn () + "=#{record." + column .getProperty () + "}" );
323
302
}
324
303
}
325
- if (entityTable .getEntityClassPKColumns ().size () == 1 ) {
326
- EntityHelper .EntityColumn column = entityTable .getEntityClassPKColumns ().iterator ().next ();
327
- notNullKeyProperty (column .getProperty (), metaObject .getValue (column .getProperty ()));
328
- WHERE (column .getColumn () + "=#{record." + column .getProperty () + "}" );
329
- } else {
330
- for (EntityHelper .EntityColumn column : entityTable .getEntityClassPKColumns ()) {
331
- notNullKeyProperty (column .getProperty (), metaObject .getValue (column .getProperty ()));
332
- WHERE (column .getColumn () + "=#{record." + column .getProperty () + "}" );
333
- }
334
- }
304
+ applyWherePk (this , metaObject , entityTable .getEntityClassPKColumns (), "record" );
335
305
}}.toString ();
336
306
}
337
307
0 commit comments