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.logicdelete; 017 018import com.mybatisflex.core.dialect.IDialect; 019import com.mybatisflex.core.query.QueryCondition; 020import com.mybatisflex.core.query.QueryWrapper; 021import com.mybatisflex.core.table.TableInfo; 022 023import static com.mybatisflex.core.constant.SqlConsts.EQUALS; 024 025/** 026 * 逻辑删除处理器抽象类。 027 * 028 * @author 王帅 029 * @since 2023-06-20 030 */ 031public abstract class AbstractLogicDeleteProcessor implements LogicDeleteProcessor { 032 033 @Override 034 public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) { 035 return dialect.wrap(logicColumn) + EQUALS + getLogicNormalValue(); 036 } 037 038 @Override 039 public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) { 040 return dialect.wrap(logicColumn) + EQUALS + getLogicDeletedValue(); 041 } 042 043 @Override 044 public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) { 045 queryWrapper.and(QueryCondition.create(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn() 046 , EQUALS 047 , getLogicNormalValue())); 048 } 049 050 /** 051 * 获取逻辑删除列未删除标记值。 052 * 053 * @return 未删除标记值 054 */ 055 protected abstract Object getLogicNormalValue(); 056 057 /** 058 * 获取逻辑删除列删除时标记值。 059 * 060 * @return 删除时标记值 061 */ 062 protected abstract Object getLogicDeletedValue(); 063 064} 065 066