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 java.util.Objects; 019import java.util.function.Predicate; 020 021/** 022 * 默认 {@link QueryColumn} 行为。 023 * 024 * @author michael 025 * @author 王帅 026 */ 027public class QueryColumnBehavior { 028 029 private QueryColumnBehavior() { 030 } 031 032 /** 033 * 自定义全局的自动忽略参数的方法。 034 */ 035 private static Predicate<Object> ignoreFunction = Objects::isNull; 036 037 /** 038 * 当 {@code IN(...)} 条件只有 1 个参数时,是否自动把的内容转换为相等。 039 */ 040 private static boolean smartConvertInToEquals = false; 041 042 public static Predicate<Object> getIgnoreFunction() { 043 return ignoreFunction; 044 } 045 046 public static void setIgnoreFunction(Predicate<Object> ignoreFunction) { 047 QueryColumnBehavior.ignoreFunction = ignoreFunction; 048 } 049 050 public static boolean isSmartConvertInToEquals() { 051 return smartConvertInToEquals; 052 } 053 054 public static void setSmartConvertInToEquals(boolean smartConvertInToEquals) { 055 QueryColumnBehavior.smartConvertInToEquals = smartConvertInToEquals; 056 } 057 058 static boolean shouldIgnoreValue(Object value) { 059 return ignoreFunction.test(value); 060 } 061 062}