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.logicdelete.impl; 017 018import com.mybatisflex.core.FlexGlobalConfig; 019import com.mybatisflex.core.dialect.IDialect; 020import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor; 021import com.mybatisflex.core.table.TableInfo; 022 023import static com.mybatisflex.core.constant.SqlConsts.EQUALS; 024import static com.mybatisflex.core.constant.SqlConsts.SINGLE_QUOTE; 025 026/** 027 * 默认逻辑删除处理器。 028 * @author michael 029 */ 030public class DefaultLogicDeleteProcessor extends AbstractLogicDeleteProcessor { 031 032 @Override 033 public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) { 034 return dialect.wrap(logicColumn) + EQUALS + prepareValue(getLogicNormalValue()); 035 } 036 037 @Override 038 public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) { 039 return dialect.wrap(logicColumn) + EQUALS + prepareValue(getLogicDeletedValue()); 040 } 041 042 @Override 043 public Object getLogicNormalValue() { 044 return FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete(); 045 } 046 047 @Override 048 public Object getLogicDeletedValue() { 049 return FlexGlobalConfig.getDefaultConfig().getDeletedValueOfLogicDelete(); 050 } 051 052 private static Object prepareValue(Object value) { 053 if (value instanceof Number || value instanceof Boolean) { 054 return value; 055 } 056 return SINGLE_QUOTE + value + SINGLE_QUOTE; 057 } 058 059} 060 061