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.query; 017 018import com.mybatisflex.core.dialect.IDialect; 019import com.mybatisflex.core.util.ObjectUtil; 020import com.mybatisflex.core.util.StringUtil; 021 022import java.util.List; 023 024public class SelectQueryColumn extends QueryColumn implements HasParamsColumn { 025 026 private QueryWrapper queryWrapper; 027 028 public SelectQueryColumn(QueryWrapper queryWrapper) { 029 this.queryWrapper = queryWrapper; 030 } 031 032 033 QueryWrapper getQueryWrapper() { 034 return queryWrapper; 035 } 036 037 @Override 038 String toSelectSql(List<QueryTable> queryTables, IDialect dialect) { 039 String selectSql = dialect.forSelectByQuery(queryWrapper); 040 if (StringUtil.isNotBlank(selectSql) && StringUtil.isNotBlank(alias)) { 041 selectSql = WrapperUtil.withAlias(selectSql, alias, dialect); 042 } 043 return selectSql; 044 } 045 046 @Override 047 public SelectQueryColumn clone() { 048 SelectQueryColumn clone = (SelectQueryColumn) super.clone(); 049 // deep clone ... 050 clone.queryWrapper = ObjectUtil.clone(this.queryWrapper); 051 return clone; 052 } 053 054 @Override 055 String toConditionSql(List<QueryTable> queryTables, IDialect dialect) { 056 return super.toConditionSql(queryTables, dialect); 057 } 058 059 @Override 060 public Object[] getParamValues() { 061 return queryWrapper.getAllValueArray(); 062 } 063 064}