View Javadoc
1   /*
2    *    Copyright 2016-2026 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 examples.simple;
17  
18  import org.mybatis.dynamic.sql.ParameterTypeConverter;
19  import org.mybatis.dynamic.sql.SqlColumn;
20  import org.mybatis.dynamic.sql.render.RenderingStrategy;
21  
22  /**
23   * This class is an example of a properly extended {@link SqlColumn}.
24   *
25   * @param <T> the Java type associated with this column
26   */
27  public class PrimaryKeyColumn<T> extends SqlColumn<T> {
28      private final boolean isPrimaryKeyColumn;
29  
30      private PrimaryKeyColumn(Builder<T> builder) {
31          super(builder);
32          isPrimaryKeyColumn = builder.isPrimaryKeyColumn;
33      }
34  
35      public boolean isPrimaryKeyColumn() {
36          return isPrimaryKeyColumn;
37      }
38  
39      @Override
40      public PrimaryKeyColumn<T> descending() {
41          return cast(super.descending());
42      }
43  
44      @Override
45      public PrimaryKeyColumn<T> as(String alias) {
46          return cast(super.as(alias));
47      }
48  
49      @Override
50      public PrimaryKeyColumn<T> qualifiedWith(String tableQualifier) {
51          return cast(super.qualifiedWith(tableQualifier));
52      }
53  
54      @Override
55      public PrimaryKeyColumn<T> asCamelCase() {
56          return cast(super.asCamelCase());
57      }
58  
59      @Override
60      public <S> PrimaryKeyColumn<S> withTypeHandler(String typeHandler) {
61          return cast(super.withTypeHandler(typeHandler));
62      }
63  
64      @Override
65      public <S> PrimaryKeyColumn<S> withRenderingStrategy(RenderingStrategy renderingStrategy) {
66          return cast(super.withRenderingStrategy(renderingStrategy));
67      }
68  
69      @Override
70      public <S> PrimaryKeyColumn<S> withParameterTypeConverter(ParameterTypeConverter<S, ?> parameterTypeConverter) {
71          return cast(super.withParameterTypeConverter(parameterTypeConverter));
72      }
73  
74      @Override
75      public <S> PrimaryKeyColumn<S> withJavaType(Class<S> javaType) {
76          return cast(super.withJavaType(javaType));
77      }
78  
79      @Override
80      public <S> PrimaryKeyColumn<S> withJavaProperty(String javaProperty) {
81          return cast(super.withJavaProperty(javaProperty));
82      }
83  
84      @Override
85      protected Builder<T> copyBuilder() {
86          return populateBaseBuilder(new Builder<>()).isPrimaryKeyColumn(isPrimaryKeyColumn);
87      }
88  
89      public static class Builder<T> extends AbstractBuilder<T, Builder<T>> {
90          private boolean isPrimaryKeyColumn;
91  
92          public Builder<T> isPrimaryKeyColumn(boolean isPrimaryKeyColumn) {
93              this.isPrimaryKeyColumn = isPrimaryKeyColumn;
94              return this;
95          }
96  
97          @Override
98          public PrimaryKeyColumn<T> build() {
99              return new PrimaryKeyColumn<>(this);
100         }
101 
102         @Override
103         protected Builder<T> getThis() {
104             return this;
105         }
106     }
107 }