001/* 002 * Copyright (c) 2022-2024, 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.exception.FlexAssert; 021 022import java.util.List; 023 024/** 025 * {@link QueryColumn} 适配器,用于将 {@link QueryCondition} 转换为 {@link QueryColumn}。 026 * 027 * @author 王帅 028 * @since 2024-09-29 029 */ 030public class QueryColumnAdapter extends QueryColumn implements HasParamsColumn { 031 032 private final QueryCondition condition; 033 034 public QueryColumnAdapter(QueryCondition condition) { 035 FlexAssert.notNull(condition, "condition"); 036 this.condition = condition; 037 } 038 039 public QueryCondition getCondition() { 040 return condition; 041 } 042 043 @Override 044 public Object[] getParamValues() { 045 return WrapperUtil.getValues(condition); 046 } 047 048 @Override 049 protected String toSelectSql(List<QueryTable> queryTables, IDialect dialect) { 050 return condition.toSql(queryTables, dialect) + WrapperUtil.buildColumnAlias(alias, dialect); 051 } 052 053 @Override 054 protected String toConditionSql(List<QueryTable> queryTables, IDialect dialect) { 055 return condition.toSql(queryTables, dialect); 056 } 057 058}