org.simpleflatmapper.jdbc.impl.MysqlBatchInsertQueryExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-jdbc Show documentation
Show all versions of sfm-jdbc Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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(")");
}
}
}
}