|
| 1 | +/* |
| 2 | + * Copyright 2016-2024 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.where.render; |
| 17 | + |
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.Map; |
| 20 | +import java.util.Objects; |
| 21 | + |
| 22 | +public class DefaultWhereClauseProvider implements WhereClauseProvider { |
| 23 | + private final String whereClause; |
| 24 | + private final Map<String, Object> parameters; |
| 25 | + |
| 26 | + private DefaultWhereClauseProvider(Builder builder) { |
| 27 | + whereClause = Objects.requireNonNull(builder.whereClause); |
| 28 | + parameters = builder.parameters; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public Map<String, Object> getParameters() { |
| 33 | + return parameters; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public String getWhereClause() { |
| 38 | + return whereClause; |
| 39 | + } |
| 40 | + |
| 41 | + public static Builder withWhereClause(String whereClause) { |
| 42 | + return new Builder().withWhereClause(whereClause); |
| 43 | + } |
| 44 | + |
| 45 | + public static class Builder { |
| 46 | + private String whereClause; |
| 47 | + private final Map<String, Object> parameters = new HashMap<>(); |
| 48 | + |
| 49 | + public Builder withWhereClause(String whereClause) { |
| 50 | + this.whereClause = whereClause; |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + public Builder withParameters(Map<String, Object> parameters) { |
| 55 | + this.parameters.putAll(parameters); |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + public DefaultWhereClauseProvider build() { |
| 60 | + return new DefaultWhereClauseProvider(this); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments