private void insert(BatchExecutor batchExecutor, MappingConfig config, SingleDml dml) throws SQLException {
        Map<String, Object> data = dml.getData();
        if (data == null || data.isEmpty()) {
            return;
        }

        DbMapping dbMapping = config.getDbMapping();

        Map<String, String> columnsMap = SyncUtil.getColumnsMap(dbMapping, data);

        StringBuilder insertSql = new StringBuilder();
        insertSql.append("INSERT INTO ").append(SyncUtil.getDbTableName(dbMapping)).append(" (");

        columnsMap.forEach((targetColumnName, srcColumnName) -> insertSql.append(targetColumnName).append(","));
        int len = insertSql.length();
        insertSql.delete(len - 1, len).append(") VALUES (");
        int mapLen = columnsMap.size();
        for (int i = 0; i < mapLen; i++) {
            insertSql.append("?,");
        }
        len = insertSql.length();
        insertSql.delete(len - 1, len).append(")");

        Map<String, Integer> ctype = getTargetColumnType(batchExecutor.getConn(), config);

        List<Map<String, ?>> values = new ArrayList<>();
        for (Map.Entry<String, String> entry : columnsMap.entrySet()) {
            String targetColumnName = entry.getKey();
            String srcColumnName = entry.getValue();
            if (srcColumnName == null) {
                srcColumnName = Util.cleanColumn(targetColumnName);
            }

            Integer type = ctype.get(Util.cleanColumn(targetColumnName).toLowerCase());
            if (type == null) {
                throw new RuntimeException("Target column: " + targetColumnName + " not matched");
            }
            Object value = data.get(srcColumnName);
            BatchExecutor.setValue(values, type, value);
        }

        try {
            batchExecutor.execute(insertSql.toString(), values);
        } catch (SQLException e) {
            if (skipDupException
                && (e.getMessage().contains("Duplicate entry") || e.getMessage().startsWith("ORA-00001: 违反唯一约束条件"))) {
                // ignore
                // TODO 增加更多关系数据库的主键冲突的错误码
            } else {
                throw e;
            }
        }
        if (logger.isTraceEnabled()) {
            logger.trace("Insert into target table, sql: {}", insertSql);
        }

    }
private void insert ( BatchExecutor batchExecutor , MappingConfig config , SingleDml dml ) throws SQLException { Map < String , Object > data = dml . getData ( ) ; if ( data == null || data . isEmpty ( ) ) { return ; } DbMapping dbMapping = config . getDbMapping ( ) ; Map < String , String > columnsMap = SyncUtil . getColumnsMap ( dbMapping , data ) ; StringBuilder insertSql = new StringBuilder ( ) ; insertSql . append ( "INSERT INTO " ) . append ( SyncUtil . getDbTableName ( dbMapping ) ) . append ( " (" ) ; columnsMap . forEach ( ( targetColumnName , srcColumnName ) -> insertSql . append ( targetColumnName ) . append ( "," ) ) ; int len = insertSql . length ( ) ; insertSql . delete ( len - 1 , len ) . append ( ") VALUES (" ) ; int mapLen = columnsMap . size ( ) ; for ( int i = 0 ; i < mapLen ; i ++ ) { insertSql . append ( "?," ) ; } len = insertSql . length ( ) ; insertSql . delete ( len - 1 , len ) . append ( ")" ) ; Map < String , Integer > ctype = getTargetColumnType ( batchExecutor . getConn ( ) , config ) ; List < Map < String , ? > > values = new ArrayList < > ( ) ; for ( Map . Entry < String , String > entry : columnsMap . entrySet ( ) ) { String targetColumnName = entry . getKey ( ) ; String srcColumnName = entry . getValue ( ) ; if ( srcColumnName == null ) { srcColumnName = Util . cleanColumn ( targetColumnName ) ; } Integer type = ctype . get ( Util . cleanColumn ( targetColumnName ) . toLowerCase ( ) ) ; if ( type == null ) { throw new RuntimeException ( "Target column: " + targetColumnName + " not matched" ) ; } Object value = data . get ( srcColumnName ) ; BatchExecutor . setValue ( values , type , value ) ; } try { batchExecutor . execute ( insertSql . toString ( ) , values ) ; } catch ( SQLException e ) { if ( skipDupException && ( e . getMessage ( ) . contains ( "Duplicate entry" ) || e . getMessage ( ) . startsWith ( "ORA-00001: 违反唯一约束条件" ) ) ) { } else { throw e ; } } if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Insert into target table, sql: {}" , insertSql ) ; } }
插入操作

@param config 配置项
@param dml DML数据