View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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  }