public static void update ( CallInfo callInfo , DataSet data ) { Table table = asTable ( data . getSource ( ) ) ; List < String > keyColumns = table . getKeyColumns ( ) ; if ( keyColumns . isEmpty ( ) ) { throw new InvalidOperationException ( "No key columns defined." ) ; } List < String > tableColumns = table . getColumns ( ) ; int columnCount = tableColumns . size ( ) ; List < String > columnsToUpdate = new LinkedList <> ( ) ; columnsToUpdate . addAll ( tableColumns ) ; columnsToUpdate . removeAll ( keyColumns ) ; if ( columnsToUpdate . isEmpty ( ) ) { throw new InvalidOperationException ( "No columns to update." ) ; } // Build SQL statement int [ ] paramIdx = new int [ columnCount ] ; int param = 0 ; StringBuilder sql = new StringBuilder ( "UPDATE " ) ; Iterator < String > itr = columnsToUpdate . iterator ( ) ; String col = itr . next ( ) ; paramIdx [ tableColumns . indexOf ( col ) ] = ++ param ; sql . append ( table . getName ( ) ) . append ( " SET " ) . append ( col ) . append ( "=?" ) ; while ( itr . hasNext ( ) ) { col = itr . next ( ) ; paramIdx [ tableColumns . indexOf ( col ) ] = ++ param ; sql . append ( ' ' ) . append ( col ) . append ( "=?" ) ; } itr = keyColumns . iterator ( ) ; col = itr . next ( ) ; paramIdx [ tableColumns . indexOf ( col ) ] = ++ param ; sql . append ( WHERE_ ) . append ( col ) . append ( "=?" ) ; while ( itr . hasNext ( ) ) { col = itr . next ( ) ; paramIdx [ tableColumns . indexOf ( col ) ] = ++ param ; sql . append ( AND_ ) . append ( col ) . append ( "=?" ) ; } table . setDirtyStatus ( true ) ; dataSetOperation ( callInfo , table , data , sql . toString ( ) , paramIdx ) ; }
Update rows according to data set .