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] =?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