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 */
016
017package com.mybatisflex.core.query;
018
019import com.mybatisflex.core.dialect.IDialect;
020import com.mybatisflex.core.util.StringUtil;
021
022import java.util.Objects;
023
024/**
025 * 原生查询表。
026 *
027 * @author 王帅
028 * @since 2023-10-16
029 */
030public class RawQueryTable extends QueryTable {
031
032    protected String content;
033
034    public RawQueryTable(String content) {
035        this.content = content;
036    }
037
038    @Override
039    public String toSql(IDialect dialect) {
040        return this.content + WrapperUtil.buildAlias(alias, dialect);
041    }
042
043    @Override
044    boolean isSameTable(QueryTable table) {
045        if (table == null) {
046            return false;
047        }
048        // 只比较别名,不比较内容
049        if (StringUtil.isNotBlank(alias)
050            && StringUtil.isNotBlank(table.alias)) {
051            return Objects.equals(alias, table.alias);
052        }
053        return false;
054    }
055
056    @Override
057    public String toString() {
058        return "RawQueryTable{" +
059            "content='" + content + '\'' +
060            '}';
061    }
062
063    public String getContent() {
064        return content;
065    }
066
067    @Override
068    public RawQueryTable clone() {
069        return (RawQueryTable) super.clone();
070    }
071
072}