001/** 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.query; 017 018import com.mybatisflex.core.dialect.IDialect; 019 020import java.io.Serializable; 021import java.util.Objects; 022 023/** 024 * 查询列,描述的是一张表的字段 025 */ 026public class QueryTable implements Serializable { 027 028 protected String name; 029 protected String alias; 030 031 public QueryTable() { 032 } 033 034 public QueryTable(String name) { 035 this.name = name; 036 } 037 038 public QueryTable(String table, String alias) { 039 this.name = table; 040 this.alias = alias; 041 } 042 043 public String getName() { 044 return name; 045 } 046 047 public void setName(String name) { 048 this.name = name; 049 } 050 051 052 public QueryTable as(String alias) { 053 this.alias = alias; 054 return this; 055 } 056 057 boolean isSameTable(QueryTable table) { 058 return table != null && Objects.equals(name, table.name); 059 } 060 061 062 public String toSql(IDialect dialect) { 063 return dialect.wrap(name) + WrapperUtil.buildAsAlias(dialect.wrap(alias)); 064 } 065 066 @Override 067 public String toString() { 068 return "QueryTable{" + 069 "name='" + name + '\'' + 070 ", alias='" + alias + '\'' + 071 '}'; 072 } 073}