From 46a25cde62f9bacbf3261bd9fa8991ee6868e807 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Tue, 20 Jun 2023 21:49:28 +0800 Subject: [PATCH 01/13] =?UTF-8?q?style:=20=E5=AE=8C=E5=96=84=20LogicDelete?= =?UTF-8?q?Processor=20=E6=8E=A5=E5=8F=A3=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logicdelete/LogicDeleteProcessor.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java index 97a39d5b..39895851 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteProcessor.java @@ -19,28 +19,35 @@ import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.table.TableInfo; +/** + * 逻辑删除处理器。 + */ public interface LogicDeleteProcessor { /** - * 用户构建查询正常数据的条件 - * @param logicColumn - * @param dialect + * 用户构建查询正常数据的条件。 + * + * @param logicColumn 逻辑删除列 + * @param dialect 数据库方言 */ String buildLogicNormalCondition(String logicColumn, IDialect dialect); /** - * 用户与构建删除数据时的内容 - * @param logicColumn - * @param dialect + * 用户与构建删除数据时的内容。 + * + * @param logicColumn 逻辑删除列 + * @param dialect 数据库方言 */ String buildLogicDeletedSet(String logicColumn, IDialect dialect); /** - * 用于构建通过 QueryWrapper 查询数据时的内容 - * @param queryWrapper - * @param tableInfo + * 用于构建通过 {@link QueryWrapper} 查询数据时的内容。 + * + * @param queryWrapper 条件构造器 + * @param tableInfo 表信息 */ void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo); + } From 7e504299f3ff4923b7c31a4ba44a270f02e0e545 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Tue, 20 Jun 2023 21:52:41 +0800 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E9=BB=98=E8=AE=A4=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractLogicDeleteProcessor.java | 66 +++++++++++++++++++ .../core/logicdelete/LogicDeleteManager.java | 34 ++++++++-- .../DefaultLogicDeleteProcessorImpl.java | 26 +++----- .../core/logicdelete/impl/package-info.java | 20 ++++++ 4 files changed, 122 insertions(+), 24 deletions(-) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java rename mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/{ => impl}/DefaultLogicDeleteProcessorImpl.java (77%) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/package-info.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java new file mode 100644 index 00000000..e3b6d32f --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/AbstractLogicDeleteProcessor.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.mybatisflex.core.logicdelete;
+
+import com.mybatisflex.core.dialect.IDialect;
+import com.mybatisflex.core.query.QueryCondition;
+import com.mybatisflex.core.query.QueryWrapper;
+import com.mybatisflex.core.table.TableInfo;
+
+import static com.mybatisflex.core.constant.SqlConsts.EQUALS;
+
+/**
+ * 逻辑删除处理器抽象类。
+ *
+ * @author 王帅
+ * @since 2023-06-20
+ */
+public abstract class AbstractLogicDeleteProcessor implements LogicDeleteProcessor {
+
+ @Override
+ public String buildLogicNormalCondition(String logicColumn, IDialect dialect) {
+ return dialect.wrap(logicColumn) + EQUALS + getLogicNormalValue();
+ }
+
+ @Override
+ public String buildLogicDeletedSet(String logicColumn, IDialect dialect) {
+ return dialect.wrap(logicColumn) + EQUALS + getLogicDeletedValue();
+ }
+
+ @Override
+ public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) {
+ queryWrapper.and(QueryCondition.create(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn()
+ , EQUALS
+ , getLogicNormalValue()));
+ }
+
+ /**
+ * 获取逻辑删除列未删除标记值。
+ *
+ * @return 未删除标记值
+ */
+ protected abstract Object getLogicNormalValue();
+
+ /**
+ * 获取逻辑删除列删除时标记值。
+ *
+ * @return 删除时标记值
+ */
+ protected abstract Object getLogicDeletedValue();
+
+}
+
+
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
index 8464e8c6..2a0e2235 100644
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
@@ -15,23 +15,41 @@
*/
package com.mybatisflex.core.logicdelete;
+import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessorImpl;
+
import java.util.function.Supplier;
+/**
+ * 逻辑删除管理器。
+ */
public class LogicDeleteManager {
+ private LogicDeleteManager() {
+ }
+
private static LogicDeleteProcessor processor = new DefaultLogicDeleteProcessorImpl();
private static final ThreadLocal
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * 逻辑删除处理器实现。
+ */
+package com.mybatisflex.core.logicdelete.impl;
\ No newline at end of file
From 8fef406cf2090e4d2bfcab53c8c31327319652a8 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 20 Jun 2023 21:56:23 +0800
Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?=
=?UTF-8?q?=E7=A7=8D=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86=E5=99=A8=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../impl/BooleanLogicDeleteProcessor.java | 45 ++++++++++++++++++
.../impl/DateTimeLogicDeleteProcessor.java | 46 +++++++++++++++++++
.../impl/IntegerLogicDeleteProcessor.java | 45 ++++++++++++++++++
3 files changed, 136 insertions(+)
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/BooleanLogicDeleteProcessor.java
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DateTimeLogicDeleteProcessor.java
create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/IntegerLogicDeleteProcessor.java
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/BooleanLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/BooleanLogicDeleteProcessor.java
new file mode 100644
index 00000000..bbd18397
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/BooleanLogicDeleteProcessor.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.logicdelete.impl;
+
+import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
+
+/**
+ * {@link Boolean} 类型的属性对应的逻辑删除处理器。
+ *
+ * @author 王帅
+ * @since 2023-06-20
+ */
+public class BooleanLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
+
+ /**
+ * 逻辑删除字段值为 {@code false} 表示数据未删除。
+ */
+ @Override
+ protected Object getLogicNormalValue() {
+ return "FALSE";
+ }
+
+ /**
+ * 逻辑删除字段值为 {@code true} 表示数据删除。
+ */
+ @Override
+ protected Object getLogicDeletedValue() {
+ return "TRUE";
+ }
+
+}
\ No newline at end of file
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DateTimeLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DateTimeLogicDeleteProcessor.java
new file mode 100644
index 00000000..c388af3f
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/DateTimeLogicDeleteProcessor.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.logicdelete.impl;
+
+import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
+import com.mybatisflex.core.query.RawFragment;
+
+/**
+ * {@link java.time.LocalDateTime} 类型的属性对应的逻辑删除处理器。
+ *
+ * @author 王帅
+ * @since 2023-06-20
+ */
+public class DateTimeLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
+
+ /**
+ * 逻辑删除字段值为 {@code null} 表示数据未删除。
+ */
+ @Override
+ protected Object getLogicNormalValue() {
+ return null;
+ }
+
+ /**
+ * 逻辑删除字段值为 {@code NOW()} 表示数据删除,并记录删除时间。
+ */
+ @Override
+ protected Object getLogicDeletedValue() {
+ return new RawFragment("NOW()");
+ }
+
+}
\ No newline at end of file
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/IntegerLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/IntegerLogicDeleteProcessor.java
new file mode 100644
index 00000000..e62af97f
--- /dev/null
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/IntegerLogicDeleteProcessor.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.logicdelete.impl;
+
+import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
+
+/**
+ * {@link Integer} 类型的属性对应的逻辑删除处理器。
+ *
+ * @author 王帅
+ * @since 2023-06-20
+ */
+public class IntegerLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
+
+ /**
+ * 逻辑删除字段值为 {@code 0} 表示数据未删除。
+ */
+ @Override
+ protected Object getLogicNormalValue() {
+ return "0";
+ }
+
+ /**
+ * 逻辑删除字段值为 {@code 1} 表示数据删除。
+ */
+ @Override
+ protected Object getLogicDeletedValue() {
+ return "1";
+ }
+
+}
\ No newline at end of file
From 75bd9799d4089067aa99ce1cbfe9813cf6c07d1a Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 20 Jun 2023 21:56:31 +0800
Subject: [PATCH 04/13] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E5=A4=9A?=
=?UTF-8?q?=E7=A7=8D=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86=E5=99=A8=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mybatisflex/coretest/LogicDeleteTest.java | 54 +++++++++++++++++++
1 file changed, 54 insertions(+)
create mode 100644 mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
new file mode 100644
index 00000000..1994733c
--- /dev/null
+++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.coretest;
+
+import com.mybatisflex.core.dialect.DialectFactory;
+import com.mybatisflex.core.dialect.IDialect;
+import com.mybatisflex.core.logicdelete.LogicDeleteProcessor;
+import com.mybatisflex.core.logicdelete.impl.BooleanLogicDeleteProcessor;
+import com.mybatisflex.core.logicdelete.impl.DateTimeLogicDeleteProcessor;
+import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessorImpl;
+import com.mybatisflex.core.logicdelete.impl.IntegerLogicDeleteProcessor;
+import org.junit.Test;
+
+/**
+ * 逻辑删除测试。
+ *
+ * @author 王帅
+ * @since 2023-06-20
+ */
+@SuppressWarnings("all")
+public class LogicDeleteTest {
+
+ private final String logicColumn = "deleted";
+ private final IDialect dialect = DialectFactory.getDialect();
+
+ @Test
+ public void test() {
+ print("DefaultLogicDeleteProcessor", new DefaultLogicDeleteProcessorImpl());
+ print("BooleanLogicDeleteProcessor", new BooleanLogicDeleteProcessor());
+ print("IntegerLogicDeleteProcessor", new IntegerLogicDeleteProcessor());
+ print("DateTimeLogicDeleteProcessor", new DateTimeLogicDeleteProcessor());
+ }
+
+ public void print(String type, LogicDeleteProcessor processor) {
+ System.out.println("===== " + type + " =====");
+ System.out.println(processor.buildLogicDeletedSet(logicColumn, dialect));
+ System.out.println(processor.buildLogicNormalCondition(logicColumn, dialect));
+ }
+
+}
\ No newline at end of file
From afd043051e4db00c93a4630b37fdf0540aaaa171 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 20 Jun 2023 21:56:40 +0800
Subject: [PATCH 05/13] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?=
=?UTF-8?q?=E7=A7=8D=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86=E5=99=A8=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E6=96=87=E6=A1=A3=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/zh/core/logic-delete.md | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/docs/zh/core/logic-delete.md b/docs/zh/core/logic-delete.md
index 361bef95..4bc2af17 100644
--- a/docs/zh/core/logic-delete.md
+++ b/docs/zh/core/logic-delete.md
@@ -122,12 +122,29 @@ globalConfig.setDeletedValueOfLogicDelete("...");
此时,我们可以使用 LogicDeleteManager.execWithoutLogicDelete() 方法处理,代码如下:
```java
-LogicDeleteManager.execWithoutLogicDelete(() ->
- accountMapper.deleteById(1)
+LogicDeleteManager.execWithoutLogicDelete(()->
+ accountMapper.deleteById(1)
);
```
+
以上代码中,`accountMapper` 会直接对 `Account` 数据进行物理删除,忽略逻辑删除字段配置。
+## 内置逻辑删除处理器
+
+MyBatis-Flex 提供了三种字段类型对应的逻辑删除处理器,用户可以根据逻辑删除字段的类型进行设置,它们分别是:
+
+| 处理器名称 | 对应字段类型 | 数据正常时的值 | 数据被删除时的值 |
+|------------------------------|----------|---------|----------|
+| IntegerLogicDeleteProcessor | integer | 0 | 1 |
+| BooleanLogicDeleteProcessor | tinyint | false | true |
+| DateTimeLogicDeleteProcessor | datetime | null | 被删除时间 |
+
+使用时,只需通过 `LogicDeleteManager` 来设置逻辑删除处理器即可,例如:
+
+```java
+LogicDeleteManager.setProcessor(new DateTimeLogicDeleteProcessor);
+```
+
## 自定义逻辑删除处理功能
在社区中,有许多用户提出希望使用时间类型,当删除时,设置删除字段为`当前时间`,当正常时,设置为 `0` 或者 `null`。
From 572bc87e51aa4d0cd30a0dca1017b507088485e4 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Tue, 20 Jun 2023 22:00:58 +0800
Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20=E9=87=8D=E5=91=BD=E5=90=8D?=
=?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84?=
=?UTF-8?q?=E7=90=86=E5=99=A8=E5=90=8D=E7=A7=B0=EF=BC=8C=E4=BF=9D=E6=8C=81?=
=?UTF-8?q?=E4=B8=80=E8=87=B4=E6=80=A7=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/mybatisflex/core/logicdelete/LogicDeleteManager.java | 4 ++--
...eteProcessorImpl.java => DefaultLogicDeleteProcessor.java} | 2 +-
.../test/java/com/mybatisflex/coretest/LogicDeleteTest.java | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
rename mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/{DefaultLogicDeleteProcessorImpl.java => DefaultLogicDeleteProcessor.java} (96%)
diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
index 2a0e2235..4ef6d8ee 100644
--- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
+++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/LogicDeleteManager.java
@@ -15,7 +15,7 @@
*/
package com.mybatisflex.core.logicdelete;
-import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessorImpl;
+import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessor;
import java.util.function.Supplier;
@@ -27,7 +27,7 @@ public class LogicDeleteManager {
private LogicDeleteManager() {
}
- private static LogicDeleteProcessor processor = new DefaultLogicDeleteProcessorImpl();
+ private static LogicDeleteProcessor processor = new DefaultLogicDeleteProcessor();
private static final ThreadLocal
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.mybatisflex.core.logicdelete.impl;
+
+import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
+
+/**
+ * {@link Long} 类型的属性对应的逻辑删除处理器。
+ *
+ * @author 王帅
+ * @since 2023-06-21
+ */
+public class LongLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
+
+ /**
+ * 逻辑删除字段值为 {@code 0} 表示数据未删除。
+ */
+ @Override
+ protected Object getLogicNormalValue() {
+ return "0";
+ }
+
+ /**
+ * 逻辑删除字段值为 {@code NOW()} 表示数据删除,并记录删除时时间戳。
+ */
+ @Override
+ protected Object getLogicDeletedValue() {
+ return "NOW()";
+ }
+
+}
\ No newline at end of file
From cc8564798005a5a951f038dcc5ac9e2bda6f620c Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Wed, 21 Jun 2023 10:52:33 +0800
Subject: [PATCH 12/13] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E5=A4=9A?=
=?UTF-8?q?=E7=A7=8D=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86=E5=99=A8=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../test/java/com/mybatisflex/coretest/LogicDeleteTest.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
index dc19d3a7..2974fddb 100644
--- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
+++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/LogicDeleteTest.java
@@ -19,10 +19,7 @@ package com.mybatisflex.coretest;
import com.mybatisflex.core.dialect.DialectFactory;
import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.logicdelete.LogicDeleteProcessor;
-import com.mybatisflex.core.logicdelete.impl.BooleanLogicDeleteProcessor;
-import com.mybatisflex.core.logicdelete.impl.DateTimeLogicDeleteProcessor;
-import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessor;
-import com.mybatisflex.core.logicdelete.impl.IntegerLogicDeleteProcessor;
+import com.mybatisflex.core.logicdelete.impl.*;
import org.junit.Test;
/**
@@ -43,6 +40,7 @@ public class LogicDeleteTest {
print("BooleanLogicDeleteProcessor", new BooleanLogicDeleteProcessor());
print("IntegerLogicDeleteProcessor", new IntegerLogicDeleteProcessor());
print("DateTimeLogicDeleteProcessor", new DateTimeLogicDeleteProcessor());
+ print("LongLogicDeleteProcessor", new LongLogicDeleteProcessor());
}
public void print(String type, LogicDeleteProcessor processor) {
From 65ffdd15d1c798fddc12142726635b21a9f08167 Mon Sep 17 00:00:00 2001
From: Suomm <1474983351@qq.com>
Date: Wed, 21 Jun 2023 10:53:35 +0800
Subject: [PATCH 13/13] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A?=
=?UTF-8?q?=E7=A7=8D=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86=E5=99=A8=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E6=96=87=E6=A1=A3=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/zh/core/logic-delete.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/zh/core/logic-delete.md b/docs/zh/core/logic-delete.md
index b6c4b219..f40968e5 100644
--- a/docs/zh/core/logic-delete.md
+++ b/docs/zh/core/logic-delete.md
@@ -138,6 +138,7 @@ MyBatis-Flex 提供了三种字段类型对应的逻辑删除处理器,用户
| IntegerLogicDeleteProcessor | integer | 0 | 1 |
| BooleanLogicDeleteProcessor | tinyint | false | true |
| DateTimeLogicDeleteProcessor | datetime | null | 被删除时间 |
+| LongLogicDeleteProcessor | bigint | 0 | 被删除时的时间戳 |
使用时,只需通过 `LogicDeleteManager` 来设置逻辑删除处理器即可,例如: