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 027/** 028 * @author michael 029 */ 030public class RawValue implements Serializable { 031 032 private Object object; 033 034 public RawValue(Object object) { 035 this.object = object; 036 } 037 038 039 public String toSql(IDialect dialect) { 040 if (object instanceof String) { 041 return (String) object; 042 } 043 044 if (object instanceof QueryWrapper) { 045 return SqlConsts.BRACKET_LEFT + dialect.buildSelectSql((QueryWrapper) object) + SqlConsts.BRACKET_RIGHT; 046 } 047 048 if (object instanceof QueryCondition) { 049 return ((QueryCondition) object).toSql(null, dialect); 050 } 051 052 if (object instanceof QueryColumn) { 053 return CPI.toSelectSql((QueryColumn) object, null, dialect); 054 } 055 056 return object.toString(); 057 } 058 059}