|
1 | 1 | package org.jooq.impl; |
2 | 2 |
|
3 | | -import org.jooq.*; |
4 | | -import org.jooq.Record; |
5 | | -import org.jooq.RenderContext.CastMode; |
6 | | - |
7 | 3 | import java.util.AbstractMap; |
8 | 4 | import java.util.AbstractSet; |
9 | 5 | import java.util.ArrayList; |
|
15 | 11 | import java.util.Map; |
16 | 12 | import java.util.Map.Entry; |
17 | 13 | import java.util.Set; |
18 | | - |
| 14 | +import java.util.stream.IntStream; |
| 15 | +import org.jooq.Context; |
| 16 | +import org.jooq.DataType; |
| 17 | +import org.jooq.Field; |
| 18 | +import org.jooq.Record; |
| 19 | +import org.jooq.RenderContext.CastMode; |
| 20 | +import org.jooq.Select; |
| 21 | +import org.jooq.Table; |
19 | 22 | import static org.jooq.impl.Keywords.K_VALUES; |
20 | 23 | import static org.jooq.impl.Tools.BooleanDataKey.DATA_STORE_ASSIGNMENT; |
21 | 24 |
|
@@ -72,24 +75,13 @@ public static void toSQLUpsertSelect(Context<?> ctx, Select<?> select) { |
72 | 75 | } |
73 | 76 |
|
74 | 77 | public Select<Record> upsertSelect() { |
75 | | - Select<Record> select = null; |
76 | | - |
77 | 78 | Map<Field<?>, List<Field<?>>> v = valuesFlattened(); |
78 | 79 |
|
79 | | - for (int i = 0; i < rows; i++) { |
80 | | - int row = i; |
81 | | - Select<Record> iteration = DSL.select(Tools.map( |
82 | | - v.entrySet(), e -> patchDefault0(e.getValue().get(row), e.getKey()) |
83 | | - )); |
84 | | - |
85 | | - if (select == null) { |
86 | | - select = iteration; |
87 | | - } else { |
88 | | - select = select.unionAll(iteration); |
89 | | - } |
90 | | - } |
91 | | - |
92 | | - return select; |
| 80 | + return IntStream.range(0, rows) |
| 81 | + .mapToObj(row -> (Select<Record>) DSL.select(Tools.map(v.entrySet(), |
| 82 | + e -> patchDefault0(e.getValue().get(row), e.getKey())))) |
| 83 | + .reduce(Select::unionAll) |
| 84 | + .orElse(null); |
93 | 85 | } |
94 | 86 |
|
95 | 87 | private void toSQL92Values(Context<?> ctx) { |
|
0 commit comments