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.update.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 DefaultUpdateStatementProvider implements UpdateStatementProvider {
25      private final String updateStatement;
26      private final Map<String, Object> parameters;
27  
28      private DefaultUpdateStatementProvider(Builder builder) {
29          updateStatement = Objects.requireNonNull(builder.updateStatement);
30          parameters = builder.parameters;
31      }
32  
33      @Override
34      public Map<String, Object> getParameters() {
35          return parameters;
36      }
37  
38      @Override
39      public String getUpdateStatement() {
40          return updateStatement;
41      }
42  
43      public static Builder withUpdateStatement(String updateStatement) {
44          return new Builder().withUpdateStatement(updateStatement);
45      }
46  
47      public static class Builder {
48          private @Nullable String updateStatement;
49          private final Map<String, Object> parameters = new HashMap<>();
50  
51          public Builder withUpdateStatement(String updateStatement) {
52              this.updateStatement = updateStatement;
53              return this;
54          }
55  
56          public Builder withParameters(Map<String, Object> parameters) {
57              this.parameters.putAll(parameters);
58              return this;
59          }
60  
61          public DefaultUpdateStatementProvider build() {
62              return new DefaultUpdateStatementProvider(this);
63          }
64      }
65  }