From b5fb969a55a77653b3752bc5a343cf9397a537b2 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 16 Aug 2023 12:27:59 +0200 Subject: [PATCH] [jOOQ/jOOQ#6587] Add InsertQuery.setRecordForUpdate(Record) --- jOOQ/src/main/java/org/jooq/InsertQuery.java | 16 ++++++++++++---- .../main/java/org/jooq/impl/InsertQueryImpl.java | 8 ++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/InsertQuery.java b/jOOQ/src/main/java/org/jooq/InsertQuery.java index 95cec9200b..abf6bcf428 100644 --- a/jOOQ/src/main/java/org/jooq/InsertQuery.java +++ b/jOOQ/src/main/java/org/jooq/InsertQuery.java @@ -105,10 +105,7 @@ public interface InsertQuery extends StoreQuery, Insert, void newRecord(); /** - * Short for calling - * newRecord(); - * setRecord(record); - * + * Short for calling {@link #newRecord()} and {@link #setRecord(Record)}. * * @param record The record to add to this insert statement. */ @@ -259,6 +256,17 @@ public interface InsertQuery extends StoreQuery, Insert, @Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) void addValuesForUpdate(Map map); + /** + * Add multiple values to the ON DUPLICATE KEY UPDATE clause of + * this INSERT statement, where this is supported. + *

+ * This works like {@link #setRecord(Record)}. + * + * @param record The record to add to this insert statement. + */ + @Support({ CUBRID, DERBY, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + void setRecordForUpdate(R record); + /** * Adds a new condition the {@link #onConflict(Field...)} clause. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index 469c255726..a7c6596bf9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -300,6 +300,14 @@ implements updateMap.set(map); } + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public final void setRecordForUpdate(R record) { + for (int i = 0; i < record.size(); i++) + if (record.changed(i)) + addValueForUpdate((Field) record.field(i), record.get(i)); + } + @Override public final void addConditions(Condition conditions) { updateWhere.addConditions(conditions);