org.simpleflatmapper.jdbc.impl.PostgresqlBatchInsertQueryExecutor 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.jdbc.MultiIndexFieldMapper;
public final class PostgresqlBatchInsertQueryExecutor extends AbstractBatchInsertQueryExecutor {
private final String[] keys;
public PostgresqlBatchInsertQueryExecutor(
String table,
String[] insertColumns,
String[] insertColumnExpressions,
String[] updateColumns,
String[] generatedKeys,
String[] keys,
MultiIndexFieldMapper[] multiIndexFieldMappers) {
super(table, insertColumns, insertColumnExpressions, updateColumns, generatedKeys, multiIndexFieldMappers);
this.keys = keys;
}
protected void onDuplicateKeys(StringBuilder sb) {
sb.append(" ON CONFLICT (");
for(int i = 0; i < keys.length; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(keys[i]);
}
sb.append(") DO ");
if (updateColumns.length > 0) {
sb.append("UPDATE SET ");
for (int i = 0; i < updateColumns.length; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(updateColumns[i])
.append(" = EXCLUDED.")
.append(updateColumns[i]);
}
} else {
sb.append("NOTHING");
}
}
}