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.where;
17  
18  import java.util.List;
19  import java.util.Objects;
20  import java.util.function.Consumer;
21  
22  import org.jspecify.annotations.NonNull;
23  import org.jspecify.annotations.Nullable;
24  import org.mybatis.dynamic.sql.AndOrCriteriaGroup;
25  import org.mybatis.dynamic.sql.SqlCriterion;
26  import org.mybatis.dynamic.sql.common.AbstractBooleanExpressionDSL;
27  import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
28  import org.mybatis.dynamic.sql.util.ConfigurableStatement;
29  
30  public abstract class AbstractWhereFinisher<T extends AbstractWhereFinisher<T>> extends AbstractBooleanExpressionDSL<T>
31          implements ConfigurableStatement<T> {
32      private final ConfigurableStatement<?> parentStatement;
33  
34      protected AbstractWhereFinisher(ConfigurableStatement<?> parentStatement) {
35          this.parentStatement = Objects.requireNonNull(parentStatement);
36      }
37  
38      void initialize(SqlCriterion sqlCriterion) {
39          setInitialCriterion(sqlCriterion, StatementType.WHERE);
40      }
41  
42      void initialize(@Nullable SqlCriterion sqlCriterion, List<AndOrCriteriaGroup> subCriteria) {
43          setInitialCriterion(sqlCriterion, StatementType.WHERE);
44          super.subCriteria.addAll(subCriteria);
45      }
46  
47      @NonNull
48      @Override
49      public T configureStatement(Consumer<StatementConfiguration> consumer) {
50          parentStatement.configureStatement(consumer);
51          return getThis();
52      }
53  
54      protected EmbeddedWhereModel buildModel() {
55          return new EmbeddedWhereModel.Builder()
56                  .withInitialCriterion(getInitialCriterion())
57                  .withSubCriteria(subCriteria)
58                  .build();
59      }
60  }