mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
223686186f
@ -139,12 +139,13 @@ LogicDeleteManager.execWithoutLogicDelete(()->
|
||||
|
||||
MyBatis-Flex 提供了三种字段类型对应的逻辑删除处理器,用户可以根据逻辑删除字段的类型进行设置,它们分别是:
|
||||
|
||||
| 处理器名称 | 对应字段类型 | 数据正常时的值 | 数据被删除时的值 |
|
||||
|------------------------------|----------|---------|----------|
|
||||
| IntegerLogicDeleteProcessor | integer | 0 | 1 |
|
||||
| BooleanLogicDeleteProcessor | tinyint | false | true |
|
||||
| DateTimeLogicDeleteProcessor | datetime | null | 被删除时间 |
|
||||
| TimeStampLogicDeleteProcessor | bigint | 0 | 被删除时的时间戳 |
|
||||
| 处理器名称 | 对应字段类型 | 数据正常时的值 | 数据被删除时的值 |
|
||||
|--------------------------------|-----------|---------|----------|
|
||||
| IntegerLogicDeleteProcessor | integer | 0 | 1 |
|
||||
| BooleanLogicDeleteProcessor | tinyint | false | true |
|
||||
| DateTimeLogicDeleteProcessor | datetime | null | 被删除时间 |
|
||||
| TimeStampLogicDeleteProcessor | bigint | 0 | 被删除时的时间戳 |
|
||||
| PrimaryKeyLogicDeleteProcessor | 该条数据的主键类型 | null | 该条数据的主键值 |
|
||||
|
||||
使用时,只需通过 `LogicDeleteManager` 来设置逻辑删除处理器即可,例如:
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
|
||||
package com.mybatisflex.core.logicdelete.impl;
|
||||
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.exception.FlexAssert;
|
||||
import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
|
||||
@ -36,24 +35,25 @@ import static com.mybatisflex.core.constant.SqlConsts.EQUALS;
|
||||
*/
|
||||
public class PrimaryKeyLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
|
||||
|
||||
@Override
|
||||
public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) {
|
||||
return dialect.wrap(logicColumn) + " IS NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) {
|
||||
List<IdInfo> primaryKeyList = tableInfo.getPrimaryKeyList();
|
||||
FlexAssert.notEmpty(primaryKeyList, "Must have one primary key.");
|
||||
FlexAssert.notEmpty(primaryKeyList, "Entity must have one primary key.");
|
||||
String column = primaryKeyList.get(0).getColumn();
|
||||
return dialect.wrap(logicColumn) + EQUALS + dialect.wrap(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常未删除的值为 0 (或者可配置为其他值)。
|
||||
* 正常未删除的值为 {@code null},兼容不同的主键类型。
|
||||
*/
|
||||
@Override
|
||||
public Object getLogicNormalValue() {
|
||||
Object normalValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete();
|
||||
if (normalValueOfLogicDelete instanceof Number) {
|
||||
return normalValueOfLogicDelete;
|
||||
}
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user