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 */ 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.HasParamsColumn; 022import com.mybatisflex.core.query.QueryColumn; 023import com.mybatisflex.core.query.QueryCondition; 024import com.mybatisflex.core.query.QueryWrapper; 025 026import java.io.Serializable; 027 028/** 029 * @author michael 030 */ 031public class RawValue implements Serializable { 032 033 private Object object; 034 035 public RawValue(Object object) { 036 this.object = object; 037 } 038 039 040 public String toSql(IDialect dialect) { 041 if (object instanceof String) { 042 return (String) object; 043 } 044 045 if (object instanceof QueryWrapper) { 046 return SqlConsts.BRACKET_LEFT + dialect.buildSelectSql((QueryWrapper) object) + SqlConsts.BRACKET_RIGHT; 047 } 048 049 if (object instanceof QueryCondition) { 050 return ((QueryCondition) object).toSql(null, dialect); 051 } 052 053 if (object instanceof QueryColumn) { 054 return CPI.toSelectSql((QueryColumn) object, null, dialect); 055 } 056 057 return object.toString(); 058 } 059 060 public Object[] getParams() { 061 if (object instanceof String) { 062 return new Object[0]; 063 } 064 065 if (object instanceof QueryWrapper) { 066 return CPI.getValueArray((QueryWrapper) object); 067 } 068 069 if (object instanceof QueryCondition) { 070 return CPI.getConditionParams((QueryCondition) object); 071 } 072 073 if (object instanceof HasParamsColumn) { 074 return ((HasParamsColumn) object).getParamValues(); 075 } 076 077 return new Object[0]; 078 } 079 080}