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;
17  
18  import java.sql.JDBCType;
19  import java.util.Objects;
20  import java.util.Optional;
21  
22  public class SqlTable implements TableExpression {
23  
24      protected String tableName;
25  
26      protected SqlTable(String tableName) {
27          this.tableName = Objects.requireNonNull(tableName);
28      }
29  
30      public String tableName() {
31          return tableName;
32      }
33  
34      public BasicColumn allColumns() {
35          return SqlColumn.of("*", this); //$NON-NLS-1$
36      }
37  
38      public <T> SqlColumn<T> column(String name) {
39          return SqlColumn.of(name, this);
40      }
41  
42      public <T> SqlColumn<T> column(String name, JDBCType jdbcType) {
43          return SqlColumn.of(name, this, jdbcType);
44      }
45  
46      public <T> SqlColumn<T> column(String name, JDBCType jdbcType, String typeHandler) {
47          SqlColumn<T> column = SqlColumn.of(name, this, jdbcType);
48          return column.withTypeHandler(typeHandler);
49      }
50  
51      @Override
52      public <R> R accept(TableExpressionVisitor<R> visitor) {
53          return visitor.visit(this);
54      }
55  
56      public Optional<String> tableAlias() {
57          return Optional.empty();
58      }
59  
60      public static SqlTable of(String name) {
61          return new SqlTable(name);
62      }
63  }