diff --git a/jOOQ-tools/src/org/jooq/xtend/InsertDSL.xtend b/jOOQ-tools/src/org/jooq/xtend/InsertDSL.xtend index b55ea224e6..f22f4b3213 100644 --- a/jOOQ-tools/src/org/jooq/xtend/InsertDSL.xtend +++ b/jOOQ-tools/src/org/jooq/xtend/InsertDSL.xtend @@ -312,7 +312,12 @@ class InsertDSL extends Generators { return this; } - + + @Override + public final InsertImpl set(Record record) { + return set(Utils.map(record)); + } + @Override public final InsertImpl newRecord() { getDelegate().newRecord(); diff --git a/jOOQ/src/main/java/org/jooq/InsertOnDuplicateSetStep.java b/jOOQ/src/main/java/org/jooq/InsertOnDuplicateSetStep.java index 29dc136378..47f68dad6c 100644 --- a/jOOQ/src/main/java/org/jooq/InsertOnDuplicateSetStep.java +++ b/jOOQ/src/main/java/org/jooq/InsertOnDuplicateSetStep.java @@ -66,34 +66,46 @@ public interface InsertOnDuplicateSetStep { /** * Set values for UPDATE in the INSERT statement's - * ON DUPLICATE KEY UPDATE clause + * ON DUPLICATE KEY UPDATE clause. */ @Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE }) InsertOnDuplicateSetMoreStep set(Field field, T value); /** * Set values for UPDATE in the INSERT statement's - * ON DUPLICATE KEY UPDATE clause + * ON DUPLICATE KEY UPDATE clause. */ @Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE }) InsertOnDuplicateSetMoreStep set(Field field, Field value); /** * Set values for UPDATE in the INSERT statement's - * ON DUPLICATE KEY UPDATE clause + * ON DUPLICATE KEY UPDATE clause. */ @Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE }) InsertOnDuplicateSetMoreStep set(Field field, Select> value); /** * Set multiple values for UPDATE in the INSERT - * statement's ON DUPLICATE KEY UPDATE clause + * statement's ON DUPLICATE KEY UPDATE clause. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE }) InsertOnDuplicateSetMoreStep set(Map, ?> map); + /** + * Set multiple values for UPDATE in the INSERT + * statement's ON DUPLICATE KEY UPDATE clause. + *

+ * This is the same as calling {@link #set(Map)} with the argument record + * treated as a Map, Object>. + * + * @see #set(Map) + */ + @Support({ CUBRID, DB2, HSQLDB, MYSQL, ORACLE, SQLSERVER, SYBASE }) + InsertOnDuplicateSetMoreStep set(Record record); + } diff --git a/jOOQ/src/main/java/org/jooq/InsertSetStep.java b/jOOQ/src/main/java/org/jooq/InsertSetStep.java index 8fbde7242f..0081d07748 100644 --- a/jOOQ/src/main/java/org/jooq/InsertSetStep.java +++ b/jOOQ/src/main/java/org/jooq/InsertSetStep.java @@ -63,54 +63,65 @@ import org.jooq.impl.Executor; public interface InsertSetStep { /** - * Set a value for a field in the INSERT statement + * Set a value for a field in the INSERT statement. */ @Support InsertSetMoreStep set(Field field, T value); /** - * Set a value for a field in the INSERT statement + * Set a value for a field in the INSERT statement. */ @Support InsertSetMoreStep set(Field field, Field value); /** - * Set a value for a field in the INSERT statement + * Set a value for a field in the INSERT statement. */ @Support InsertSetMoreStep set(Field field, Select> value); /** - * Set a value for a field in the INSERT statement + * Set values in the INSERT statement. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support InsertSetMoreStep set(Map, ?> map); /** - * Add values to the insert statement with implicit field names + * Set values in the INSERT statement. + *

+ * This is the same as calling {@link #set(Map)} with the argument record + * treated as a Map, Object>. + * + * @see #set(Map) + */ + @Support + InsertSetMoreStep set(Record record); + + /** + * Add values to the insert statement with implicit field names. */ @Support InsertValuesStepN values(Object... values); /** - * Add values to the insert statement with implicit field names + * Add values to the insert statement with implicit field names. */ @Support InsertValuesStepN values(Field... values); /** - * Add values to the insert statement with implicit field names + * Add values to the insert statement with implicit field names. */ @Support InsertValuesStepN values(Collection values); /** * Use a SELECT statement as the source of values for the - * INSERT statement + * INSERT statement. *

* This variant of the INSERT .. SELECT statement does not * allow for specifying a subset of the fields inserted into. It will insert diff --git a/jOOQ/src/main/java/org/jooq/MergeMatchedSetStep.java b/jOOQ/src/main/java/org/jooq/MergeMatchedSetStep.java index e4a0e1d1ec..8399922c66 100644 --- a/jOOQ/src/main/java/org/jooq/MergeMatchedSetStep.java +++ b/jOOQ/src/main/java/org/jooq/MergeMatchedSetStep.java @@ -67,21 +67,21 @@ public interface MergeMatchedSetStep { /** * Set values for UPDATE in the MERGE statement's - * WHEN MATCHED clause + * WHEN MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeMatchedSetMoreStep set(Field field, T value); /** * Set values for UPDATE in the MERGE statement's - * WHEN MATCHED clause + * WHEN MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeMatchedSetMoreStep set(Field field, Field value); /** * Set values for UPDATE in the MERGE statement's - * WHEN MATCHED clause + * WHEN MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeMatchedSetMoreStep set(Field field, Select> value); @@ -90,10 +90,22 @@ public interface MergeMatchedSetStep { * Set multiple values for UPDATE in the MERGE * statement's WHEN MATCHED clause. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeMatchedSetMoreStep set(Map, ?> map); + + /** + * Set multiple values for UPDATE in the MERGE + * statement's WHEN MATCHED clause. + *

+ * This is the same as calling {@link #set(Map)} with the argument record + * treated as a Map, Object>. + * + * @see #set(Map) + */ + @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) + MergeMatchedSetMoreStep set(Record record); } diff --git a/jOOQ/src/main/java/org/jooq/MergeNotMatchedSetStep.java b/jOOQ/src/main/java/org/jooq/MergeNotMatchedSetStep.java index 896c973bee..f784ad17eb 100644 --- a/jOOQ/src/main/java/org/jooq/MergeNotMatchedSetStep.java +++ b/jOOQ/src/main/java/org/jooq/MergeNotMatchedSetStep.java @@ -67,21 +67,21 @@ public interface MergeNotMatchedSetStep { /** * Set values for INSERT in the MERGE statement's - * WHEN NOT MATCHED clause + * WHEN NOT MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeNotMatchedSetMoreStep set(Field field, T value); /** * Set values for INSERT in the MERGE statement's - * WHEN NOT MATCHED clause + * WHEN NOT MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeNotMatchedSetMoreStep set(Field field, Field value); /** * Set values for INSERT in the MERGE statement's - * WHEN NOT MATCHED clause + * WHEN NOT MATCHED clause. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeMatchedSetMoreStep set(Field field, Select> value); @@ -90,10 +90,22 @@ public interface MergeNotMatchedSetStep { * Set multiple values for INSERT in the MERGE * statement's WHEN NOT MATCHED clause. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) MergeNotMatchedSetMoreStep set(Map, ?> map); + + /** + * Set multiple values for INSERT in the MERGE + * statement's WHEN NOT MATCHED clause. + *

+ * This is the same as calling {@link #set(Map)} with the argument record + * treated as a Map, Object>. + * + * @see #set(Map) + */ + @Support({ CUBRID, DB2, HSQLDB, ORACLE, SQLSERVER, SYBASE }) + MergeNotMatchedSetMoreStep set(Record record); } diff --git a/jOOQ/src/main/java/org/jooq/StoreQuery.java b/jOOQ/src/main/java/org/jooq/StoreQuery.java index 722fae2901..a6ac2d516a 100644 --- a/jOOQ/src/main/java/org/jooq/StoreQuery.java +++ b/jOOQ/src/main/java/org/jooq/StoreQuery.java @@ -77,9 +77,9 @@ public interface StoreQuery extends Query { /** * Add multiple values to the store statement. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support void addValues(Map, ?> map); diff --git a/jOOQ/src/main/java/org/jooq/UpdateSetStep.java b/jOOQ/src/main/java/org/jooq/UpdateSetStep.java index de2681f76c..25d2737b16 100644 --- a/jOOQ/src/main/java/org/jooq/UpdateSetStep.java +++ b/jOOQ/src/main/java/org/jooq/UpdateSetStep.java @@ -55,30 +55,40 @@ import java.util.Map; public interface UpdateSetStep { /** - * Set a value for a field in the UPDATE statement + * Set a value for a field in the UPDATE statement. */ @Support UpdateSetMoreStep set(Field field, T value); /** - * Set a value for a field in the UPDATE statement + * Set a value for a field in the UPDATE statement. */ @Support UpdateSetMoreStep set(Field field, Field value); /** - * Set a value for a field in the UPDATE statement + * Set a value for a field in the UPDATE statement. */ @Support UpdateSetMoreStep set(Field field, Select> value); /** - * Set a value for a field in the UPDATE statement + * Set a value for a field in the UPDATE statement. *

- * Please assure that key/value pairs have matching <T> - * types. Values can either be of type <T> or - * Field<T> + * Values can either be of type <T> or + * Field<T>. jOOQ will attempt to convert values to their + * corresponding field's type. */ @Support UpdateSetMoreStep set(Map, ?> map); -} + + /** + * Set a value for a field in the UPDATE statement. + *

+ * This is the same as calling {@link #set(Map)} with the argument record + * treated as a Map, Object>. + * + * @see #set(Map) + */ + @Support + UpdateSetMoreStep set(Record record);} diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertImpl.java index 1c381babaa..ab4ce68174 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertImpl.java @@ -465,6 +465,11 @@ class InsertImpl>emptyList()); diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdateImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdateImpl.java index 9a441059dc..e922ddd733 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UpdateImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UpdateImpl.java @@ -151,6 +151,11 @@ final class UpdateImpl return this; } + @Override + public final UpdateImpl set(Record record) { + return set(Utils.map(record)); + } + // [jooq-tools] START [set] @Generated("This method was generated using jOOQ-tools") @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/Utils.java b/jOOQ/src/main/java/org/jooq/impl/Utils.java index 8cf90ed6c5..dad9c9111e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Utils.java +++ b/jOOQ/src/main/java/org/jooq/impl/Utils.java @@ -71,7 +71,9 @@ import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.regex.Pattern; @@ -567,6 +569,20 @@ final class Utils { return array == null ? Collections.emptyList() : Arrays.asList(array); } + /** + * Turn a {@link Record} into a {@link Map} + */ + static final Map, Object> map(Record record) { + Map, Object> result = new LinkedHashMap, Object>(); + int size = record.size(); + + for (int i = 0; i < size; i++) { + result.put(record.field(i), record.getValue(i)); + } + + return result; + } + /** * Extract the first item from an iterable or null, if there is * no such item, or if iterable itself is null