public int [ ] batchSave ( String tableName , List < Record > recordList , int batchSize ) { if ( recordList == null || recordList . size ( ) == 0 ) return new int [ 0 ] ; Record record = recordList . get ( 0 ) ; Map < String , Object > cols = record . getColumns ( ) ; int index = 0 ; StringBuilder columns = new StringBuilder ( ) ; // the same as the iterator in Dialect.forDbSave() to ensure the order of the columns for ( Entry < String , Object > e : cols . entrySet ( ) ) { if ( config . dialect . isOracle ( ) ) { // 支持 oracle 自增主键 Object value = e . getValue ( ) ; if ( value instanceof String && ( ( String ) value ) . endsWith ( ".nextval" ) ) { continue ; } } if ( index ++ > 0 ) { columns . append ( ' ' ) ; } columns . append ( e . getKey ( ) ) ; } String [ ] pKeysNoUse = new String [ 0 ] ; StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forDbSave ( tableName , pKeysNoUse , record , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns . toString ( ) , recordList , batchSize ) ; }
Batch save records using the insert into ... sql generated by the first record in recordList . Ensure all the record can use the same sql as the first record .