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.common;
17  
18  import org.jspecify.annotations.Nullable;
19  import org.mybatis.dynamic.sql.SqlTable;
20  import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
21  import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
22  
23  /**
24   * Builder class shared between the delete and update model builders.
25   *
26   * @param <T> type of the implementing builder
27   */
28  public abstract class CommonBuilder<T extends CommonBuilder<T>> {
29      private @Nullable SqlTable table;
30      private @Nullable String tableAlias;
31      private @Nullable EmbeddedWhereModel whereModel;
32      private @Nullable Long limit;
33      private @Nullable OrderByModel orderByModel;
34      private @Nullable StatementConfiguration statementConfiguration;
35  
36      public @Nullable SqlTable table() {
37          return table;
38      }
39  
40      public @Nullable String tableAlias() {
41          return tableAlias;
42      }
43  
44      public @Nullable EmbeddedWhereModel whereModel() {
45          return whereModel;
46      }
47  
48      public @Nullable Long limit() {
49          return limit;
50      }
51  
52      public @Nullable OrderByModel orderByModel() {
53          return orderByModel;
54      }
55  
56      public @Nullable StatementConfiguration statementConfiguration() {
57          return statementConfiguration;
58      }
59  
60      public T withTable(SqlTable table) {
61          this.table = table;
62          return getThis();
63      }
64  
65      public T withTableAlias(@Nullable String tableAlias) {
66          this.tableAlias = tableAlias;
67          return getThis();
68      }
69  
70      public T withWhereModel(@Nullable EmbeddedWhereModel whereModel) {
71          this.whereModel = whereModel;
72          return getThis();
73      }
74  
75      public T withLimit(@Nullable Long limit) {
76          this.limit = limit;
77          return getThis();
78      }
79  
80      public T withOrderByModel(@Nullable OrderByModel orderByModel) {
81          this.orderByModel = orderByModel;
82          return getThis();
83      }
84  
85      public T withStatementConfiguration(StatementConfiguration statementConfiguration) {
86          this.statementConfiguration = statementConfiguration;
87          return getThis();
88      }
89  
90      protected abstract T getThis();
91  }