public int [ ] batchUpdate ( String tableName , String primaryKey , List < Record > recordList , int batchSize ) { if ( recordList == null || recordList . size ( ) == 0 ) return new int [ 0 ] ; String [ ] pKeys = primaryKey . split ( "," ) ; config . dialect . trimPrimaryKeys ( pKeys ) ; Record record = recordList . get ( 0 ) ; Map < String , Object > cols = record . getColumns ( ) ; List < String > colNames = new ArrayList < String > ( ) ; // the same as the iterator in Dialect.forDbUpdate() to ensure the order of the columns for ( Entry < String , Object > e : cols . entrySet ( ) ) { String col = e . getKey ( ) ; if ( config . dialect . isPrimaryKey ( col , pKeys ) == false ) colNames . add ( col ) ; } for ( String pKey : pKeys ) colNames . ( pKey ) ; String columns = StrKit . join ( colNames . toArray ( new String [ colNames . size ( ) ] ) , "," ) ; Object [ ] idsNoUse = new Object [ pKeys . length ] ; StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forDbUpdate ( tableName , pKeys , idsNoUse , record , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns , recordList , batchSize ) ; }
Batch update records using the columns names of the first record in recordList . Ensure all the records can use the same sql as the first record .