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.delete.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 DefaultDeleteStatementProvider implements DeleteStatementProvider {
25      private final String deleteStatement;
26      private final Map<String, Object> parameters;
27  
28      private DefaultDeleteStatementProvider(Builder builder) {
29          deleteStatement = Objects.requireNonNull(builder.deleteStatement);
30          parameters = builder.parameters;
31      }
32  
33      @Override
34      public Map<String, Object> getParameters() {
35          return parameters;
36      }
37  
38      @Override
39      public String getDeleteStatement() {
40          return deleteStatement;
41      }
42  
43      public static Builder withDeleteStatement(String deleteStatement) {
44          return new Builder().withDeleteStatement(deleteStatement);
45      }
46  
47      public static class Builder {
48          private @Nullable String deleteStatement;
49          private final Map<String, Object> parameters = new HashMap<>();
50  
51          public Builder withDeleteStatement(String deleteStatement) {
52              this.deleteStatement = deleteStatement;
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 DefaultDeleteStatementProvider build() {
62              return new DefaultDeleteStatementProvider(this);
63          }
64      }
65  }