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

com.sap.cds.jdbc.h2.H2StatementResolver Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/*******************************************************************
 * © 2022 SAP SE or an SAP affiliate company. All rights reserved. *
 *******************************************************************/
package com.sap.cds.jdbc.h2;

import static com.sap.cds.impl.sql.SQLHelper.commaSeparated;
import static java.util.stream.Collectors.joining;

import java.util.stream.Stream;

import com.sap.cds.jdbc.spi.StatementResolver;

public class H2StatementResolver implements StatementResolver {

	/**
	 * H2: MERGE INTO
	 * 
	 * Updates existing rows, and insert rows that don't exist. If no key column is
	 * specified, the primary key columns are used to find the row. If more than one
	 * row per new row is affected, an exception is thrown.
	 * 
	 * https://www.h2database.com/html/commands.html#merge_into
	 */
	@Override
	public String upsert(String table, Stream keyColumns, Stream upsertColumns,
			Stream upsertValues) {
		String columns = commaSeparated(upsertColumns);
		String values = commaSeparated(upsertValues);

		return Stream.of("MERGE INTO", table, columns, "VALUES", values).collect(joining(" "));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy