2323import java .sql .SQLException ;
2424import java .sql .Statement ;
2525import java .util .ArrayList ;
26- import java .util .HashMap ;
27- import java .util .HashSet ;
2826import java .util .Iterator ;
2927import java .util .List ;
3028import java .util .Map ;
@@ -359,8 +357,7 @@ else if (colType == Long.class || colType == long.class)
359357 */
360358 public boolean delete () {
361359 Table table = getTable ();
362- String pKey = table .getPrimaryKey ();
363- Object id = attrs .get (pKey );
360+ Object id = attrs .get (table .getPrimaryKey ());
364361 if (id == null )
365362 throw new ActiveRecordException ("You can't delete model without id." );
366363 return deleteById (table , id );
@@ -378,8 +375,17 @@ public boolean deleteById(Object id) {
378375 }
379376
380377 private boolean deleteById (Table table , Object id ) {
381- String sql = getConfig ().dialect .forModelDeleteById (table );
382- return Db .update (sql , id ) >= 1 ;
378+ Config config = getConfig ();
379+ Connection conn = null ;
380+ try {
381+ conn = config .getConnection ();
382+ String sql = config .dialect .forModelDeleteById (table );
383+ return Db .update (config , conn , sql , id ) >= 1 ;
384+ } catch (Exception e ) {
385+ throw new ActiveRecordException (e );
386+ } finally {
387+ config .close (conn );
388+ }
383389 }
384390
385391 /**
@@ -581,8 +587,9 @@ public M removeNullValueAttrs() {
581587 */
582588 public M keep (String ... attrs ) {
583589 if (attrs != null && attrs .length > 0 ) {
584- Map <String , Object > newAttrs = new HashMap <String , Object >(attrs .length );
585- Set <String > newModifyFlag = new HashSet <String >();
590+ Config config = getConfig ();
591+ Map <String , Object > newAttrs = config .containerFactory .getAttrsMap (); // new HashMap<String, Object>(attrs.length);
592+ Set <String > newModifyFlag = config .containerFactory .getModifyFlagSet (); // new HashSet<String>();
586593 for (String a : attrs ) {
587594 if (this .attrs .containsKey (a )) // prevent put null value to the newColumns
588595 newAttrs .put (a , this .attrs .get (a ));
0 commit comments