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.update;
017
018import com.mybatisflex.core.constant.SqlConsts;
019import com.mybatisflex.core.dialect.IDialect;
020import com.mybatisflex.core.query.CPI;
021import com.mybatisflex.core.query.QueryColumn;
022import com.mybatisflex.core.query.QueryCondition;
023import com.mybatisflex.core.query.QueryWrapper;
024
025import java.io.Serializable;
026
027public class RawValue implements Serializable {
028
029    private Object object;
030
031    public RawValue(Object object) {
032        this.object = object;
033    }
034
035
036    public String toSql(IDialect dialect) {
037        if (object instanceof String) {
038            return (String) object;
039        }
040
041        if (object instanceof QueryWrapper) {
042            return SqlConsts.BRACKET_LEFT + dialect.buildSelectSql((QueryWrapper) object) + SqlConsts.BRACKET_RIGHT;
043        }
044
045        if (object instanceof QueryCondition) {
046            return ((QueryCondition) object).toSql(null, dialect);
047        }
048
049        if (object instanceof QueryColumn) {
050            return CPI.toSelectSql((QueryColumn) object, null, dialect);
051        }
052
053        return object.toString();
054    }
055
056}