All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jdbc.impl.MysqlBatchInsertQueryExecutor Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.jdbc.impl;

import org.simpleflatmapper.converter.ContextFactory;
import org.simpleflatmapper.jdbc.MultiIndexFieldMapper;

public final class MysqlBatchInsertQueryExecutor extends AbstractBatchInsertQueryExecutor {

    public MysqlBatchInsertQueryExecutor(
            CrudMeta meta,
            String[] insertColumns,
            String[] insertColumnExpressions,
            String[] updateColumns,
            String[] generatedKeys,
            MultiIndexFieldMapper[] multiIndexFieldMappers,
            ContextFactory contextFactory) {
        super(meta, insertColumns, insertColumnExpressions, updateColumns, generatedKeys, multiIndexFieldMappers, contextFactory);
    }

    protected void appendInsertInto(StringBuilder sb) {
        if (updateColumns != null && updateColumns.length == 0) {
            sb.append("INSERT IGNORE INTO ");
        } else {
            sb.append("INSERT INTO ");
        }
    }

    protected void onDuplicateKeys(StringBuilder sb) {
        if (updateColumns.length > 0) {
            sb.append(" ON DUPLICATE KEY UPDATE ");
            for (int i = 0; i < updateColumns.length; i++) {
                if (i > 0) {
                    sb.append(", ");
                }
                sb.append(updateColumns[i])
                        .append(" = VALUES(")
                        .append(updateColumns[i])
                        .append(")");
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy