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.Objects;
19
20 import org.jspecify.annotations.Nullable;
21
22 public class DefaultInsertStatementProvider<T> implements InsertStatementProvider<T> {
23 private final String insertStatement;
24 private final T row;
25
26 private DefaultInsertStatementProvider(Builder<T> builder) {
27 insertStatement = Objects.requireNonNull(builder.insertStatement);
28 row = Objects.requireNonNull(builder.row);
29 }
30
31 @Override
32 public T getRow() {
33 return row;
34 }
35
36 @Override
37 public String getInsertStatement() {
38 return insertStatement;
39 }
40
41 public static <T> Builder<T> withRow(T row) {
42 return new Builder<T>().withRow(row);
43 }
44
45 public static class Builder<T> {
46 private @Nullable String insertStatement;
47 private @Nullable T row;
48
49 public Builder<T> withInsertStatement(String insertStatement) {
50 this.insertStatement = insertStatement;
51 return this;
52 }
53
54 public Builder<T> withRow(T row) {
55 this.row = row;
56 return this;
57 }
58
59 public DefaultInsertStatementProvider<T> build() {
60 return new DefaultInsertStatementProvider<>(this);
61 }
62 }
63 }