Skip to content

Commit dfda99b

Browse files
fixes JOOQ: resource leaks
1 parent c7e64e7 commit dfda99b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

jooq-dialect/src/main/java/org/jooq/impl/FieldMapsForUpsertReplace.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.jooq.impl;
22

3-
import org.jooq.*;
4-
import org.jooq.Record;
5-
import org.jooq.RenderContext.CastMode;
6-
73
import java.util.AbstractMap;
84
import java.util.AbstractSet;
95
import java.util.ArrayList;
@@ -15,7 +11,14 @@
1511
import java.util.Map;
1612
import java.util.Map.Entry;
1713
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;
1922
import static org.jooq.impl.Keywords.K_VALUES;
2023
import static org.jooq.impl.Tools.BooleanDataKey.DATA_STORE_ASSIGNMENT;
2124

@@ -72,24 +75,13 @@ public static void toSQLUpsertSelect(Context<?> ctx, Select<?> select) {
7275
}
7376

7477
public Select<Record> upsertSelect() {
75-
Select<Record> select = null;
76-
7778
Map<Field<?>, List<Field<?>>> v = valuesFlattened();
7879

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);
9385
}
9486

9587
private void toSQL92Values(Context<?> ctx) {

jooq-dialect/src/main/java/org/jooq/impl/UpsertReplaceQueryImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void accept(Context<?> ctx) {
8080

8181
Table<?> t = InlineDerivedTable.inlineDerivedTable(ctx, table(ctx));
8282
if (t instanceof InlineDerivedTable<?> i) {
83-
copy(
83+
try (var copyUpsertReplaceQuery = copy(
8484
d -> {
8585
if (!d.upsertReplaceMaps.isEmpty()) {
8686
Table<?> m = DSL.table(name("t"));
@@ -97,7 +97,9 @@ public void accept(Context<?> ctx) {
9797
}
9898
},
9999
i.table
100-
).accept0(ctx);
100+
)) {
101+
copyUpsertReplaceQuery.accept0(ctx);
102+
}
101103
} else {
102104
accept0(ctx);
103105
}

0 commit comments

Comments
 (0)