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.FlexConsts; 020import com.mybatisflex.core.dialect.IDialect; 021 022import java.util.List; 023 024/** 025 * 取相反数({@code -column})。 026 * 027 * @author 王帅 028 * @since 2023-11-09 029 */ 030public class NegativeQueryColumn extends QueryColumn implements HasParamsColumn { 031 032 private final QueryColumn queryColumn; 033 034 public NegativeQueryColumn(QueryColumn queryColumn) { 035 this.queryColumn = queryColumn; 036 } 037 038 @Override 039 public Object[] getParamValues() { 040 if (queryColumn instanceof HasParamsColumn) { 041 return ((HasParamsColumn) queryColumn).getParamValues(); 042 } 043 return FlexConsts.EMPTY_ARRAY; 044 } 045 046 @Override 047 protected String toSelectSql(List<QueryTable> queryTables, IDialect dialect) { 048 return toConditionSql(queryTables, dialect) + WrapperUtil.buildColumnAlias(alias, dialect); 049 } 050 051 @Override 052 protected String toConditionSql(List<QueryTable> queryTables, IDialect dialect) { 053 return "-" + queryColumn.toConditionSql(queryTables, dialect); 054 } 055 056}