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.HashMap;
19  import java.util.Map;
20  import java.util.Objects;
21  
22  import org.jspecify.annotations.Nullable;
23  
24  public class DefaultGeneralInsertStatementProvider
25          implements GeneralInsertStatementProvider, InsertSelectStatementProvider {
26      private final String insertStatement;
27      private final Map<String, Object> parameters;
28  
29      private DefaultGeneralInsertStatementProvider(Builder builder) {
30          insertStatement = Objects.requireNonNull(builder.insertStatement);
31          parameters = builder.parameters;
32      }
33  
34      @Override
35      public Map<String, Object> getParameters() {
36          return parameters;
37      }
38  
39      @Override
40      public String getInsertStatement() {
41          return insertStatement;
42      }
43  
44      public static Builder withInsertStatement(String insertStatement) {
45          return new Builder().withInsertStatement(insertStatement);
46      }
47  
48      public static class Builder {
49          private @Nullable String insertStatement;
50          private final Map<String, Object> parameters = new HashMap<>();
51  
52          public Builder withInsertStatement(String insertStatement) {
53              this.insertStatement = insertStatement;
54              return this;
55          }
56  
57          public Builder withParameters(Map<String, Object> parameters) {
58              this.parameters.putAll(parameters);
59              return this;
60          }
61  
62          public DefaultGeneralInsertStatementProvider build() {
63              return new DefaultGeneralInsertStatementProvider(this);
64          }
65      }
66  }