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.select.render;
17  
18  import java.util.Collections;
19  import java.util.HashMap;
20  import java.util.Map;
21  import java.util.Objects;
22  
23  import org.jspecify.annotations.Nullable;
24  
25  public class DefaultSelectStatementProvider implements SelectStatementProvider {
26      private final String selectStatement;
27      private final Map<String, Object> parameters;
28  
29      private DefaultSelectStatementProvider(Builder builder) {
30          selectStatement = Objects.requireNonNull(builder.selectStatement);
31          parameters = Collections.unmodifiableMap(Objects.requireNonNull(builder.parameters));
32      }
33  
34      @Override
35      public Map<String, Object> getParameters() {
36          return parameters;
37      }
38  
39      @Override
40      public String getSelectStatement() {
41          return selectStatement;
42      }
43  
44      public static Builder withSelectStatement(String selectStatement) {
45          return new Builder().withSelectStatement(selectStatement);
46      }
47  
48      public static class Builder {
49          private @Nullable String selectStatement;
50          private final Map<String, Object> parameters = new HashMap<>();
51  
52          public Builder withSelectStatement(String selectStatement) {
53              this.selectStatement = selectStatement;
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 DefaultSelectStatementProvider build() {
63              return new DefaultSelectStatementProvider(this);
64          }
65      }
66  }