1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.insert.render;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Objects;
22
23 import org.jspecify.annotations.Nullable;
24
25 public class DefaultMultiRowInsertStatementProvider<T> implements MultiRowInsertStatementProvider<T> {
26
27 private final List<T> records;
28 private final String insertStatement;
29
30 private DefaultMultiRowInsertStatementProvider(Builder<T> builder) {
31 insertStatement = Objects.requireNonNull(builder.insertStatement);
32 records = Collections.unmodifiableList(builder.records);
33 }
34
35 @Override
36 public String getInsertStatement() {
37 return insertStatement;
38 }
39
40 @Override
41 public List<T> getRecords() {
42 return records;
43 }
44
45 public static class Builder<T> {
46 private final List<T> records = new ArrayList<>();
47 private @Nullable String insertStatement;
48
49 public Builder<T> withRecords(List<T> records) {
50 this.records.addAll(records);
51 return this;
52 }
53
54 public Builder<T> withInsertStatement(String insertStatement) {
55 this.insertStatement = insertStatement;
56 return this;
57 }
58
59 public DefaultMultiRowInsertStatementProvider<T> build() {
60 return new DefaultMultiRowInsertStatementProvider<>(this);
61 }
62 }
63 }