1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }