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

org.simpleflatmapper.jdbc.impl.PostgresqlBatchInsertQueryExecutor 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.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");
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy