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