From effdc96299ab80422425b27e5ca928907963afd2 Mon Sep 17 00:00:00 2001
From: yulichang <570810310@qq.com>
Date: Wed, 30 Oct 2024 15:46:06 +0800
Subject: [PATCH] feat: wrapper ext
---
mybatis-plus-join-core/pom.xml | 21 +++++++-
.../config/MPJInterceptorConfig.java | 3 +-
.../toolkit/MybatisJoinPlusVersion.java | 53 +++++++++++++++++++
.../wrapper/JoinAbstractLambdaWrapper.java | 3 +-
.../yulichang/wrapper/MPJLambdaWrapper.java | 6 ++-
.../yulichang/wrapper/interfaces/IExt.java | 14 +++++
mybatis-plus-join-test/test-join/pom.xml | 11 ++++
.../com/github/yulichang/wrapper/ext/Ext.java | 14 +++++
.../test/join/unit/ExtWrapperTest.java | 34 ++++++++++++
plugin/mybatis-plus-join-solon-plugin/pom.xml | 1 +
plugin/mybatis-plus-join-wrapper-ext/pom.xml | 16 ++++++
.../com/github/yulichang/wrapper/ext/Ext.java | 13 +++++
pom.xml | 1 +
13 files changed, 185 insertions(+), 5 deletions(-)
create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MybatisJoinPlusVersion.java
create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/IExt.java
create mode 100644 mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
create mode 100644 mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ExtWrapperTest.java
create mode 100644 plugin/mybatis-plus-join-wrapper-ext/pom.xml
create mode 100644 plugin/mybatis-plus-join-wrapper-ext/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
diff --git a/mybatis-plus-join-core/pom.xml b/mybatis-plus-join-core/pom.xml
index c82d434..fcc76fe 100644
--- a/mybatis-plus-join-core/pom.xml
+++ b/mybatis-plus-join-core/pom.xml
@@ -64,6 +64,11 @@
mybatis-plus-join-adapter-v355
${revision}
+
+ com.github.yulichang
+ mybatis-plus-join-wrapper-ext
+ ${revision}
+
com.baomidou
mybatis-plus-extension
@@ -99,5 +104,19 @@
-
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+
+
+
+
+
+
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MPJInterceptorConfig.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MPJInterceptorConfig.java
index dc5f62d..f61326f 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MPJInterceptorConfig.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/config/MPJInterceptorConfig.java
@@ -3,6 +3,7 @@ package com.github.yulichang.config;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.yulichang.interceptor.MPJInterceptor;
import com.github.yulichang.toolkit.InterceptorList;
+import com.github.yulichang.toolkit.MybatisJoinPlusVersion;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.plugin.Interceptor;
@@ -30,7 +31,7 @@ public class MPJInterceptorConfig {
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
" / | /\n" +
- " 1.5.2-SNAPSHOT");
+ " " + MybatisJoinPlusVersion.getVersion());
}
}
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MybatisJoinPlusVersion.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MybatisJoinPlusVersion.java
new file mode 100644
index 0000000..2f046b5
--- /dev/null
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/toolkit/MybatisJoinPlusVersion.java
@@ -0,0 +1,53 @@
+package com.github.yulichang.toolkit;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.CodeSource;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+
+/**
+ * copy {@link com.baomidou.mybatisplus.core.MybatisPlusVersion}
+ *
+ * @since 1.5.2
+ */
+public class MybatisJoinPlusVersion {
+
+ private MybatisJoinPlusVersion() {
+ }
+
+ public static String getVersion() {
+ return determineSpringBootVersion();
+ }
+
+ private static String determineSpringBootVersion() {
+ final Package pkg = MybatisJoinPlusVersion.class.getPackage();
+ if (pkg != null && pkg.getImplementationVersion() != null) {
+ return pkg.getImplementationVersion();
+ }
+ CodeSource codeSource = MybatisJoinPlusVersion.class.getProtectionDomain().getCodeSource();
+ if (codeSource == null) {
+ return null;
+ }
+ URL codeSourceLocation = codeSource.getLocation();
+ try {
+ URLConnection connection = codeSourceLocation.openConnection();
+ if (connection instanceof JarURLConnection) {
+ return getImplementationVersion(((JarURLConnection) connection).getJarFile());
+ }
+ try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
+ return getImplementationVersion(jarFile);
+ }
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ private static String getImplementationVersion(JarFile jarFile) throws IOException {
+ return jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ }
+
+}
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java
index 52f41af..c69a334 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java
@@ -14,6 +14,7 @@ import com.github.yulichang.config.enums.LogicDelTypeEnum;
import com.github.yulichang.toolkit.*;
import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.enums.PrefixEnum;
+import com.github.yulichang.wrapper.ext.Ext;
import com.github.yulichang.wrapper.interfaces.MConsumer;
import com.github.yulichang.wrapper.interfaces.MFunction;
import com.github.yulichang.wrapper.interfaces.QueryJoin;
@@ -40,7 +41,7 @@ import static java.util.stream.Collectors.joining;
*/
@SuppressWarnings({"DuplicatedCode", "unused"})
public abstract class JoinAbstractLambdaWrapper>
- extends JoinAbstractWrapper implements QueryJoin {
+ extends JoinAbstractWrapper implements QueryJoin, Ext {
/**
* 是否存在对一或对多
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
index 44045eb..cf4a320 100644
--- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/MPJLambdaWrapper.java
@@ -2,11 +2,13 @@ package com.github.yulichang.wrapper;
import com.baomidou.mybatisplus.core.conditions.SharedString;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
-import com.baomidou.mybatisplus.core.toolkit.*;
+import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
+import com.baomidou.mybatisplus.core.toolkit.Assert;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.toolkit.*;
-import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
import com.github.yulichang.wrapper.interfaces.*;
diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/IExt.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/IExt.java
new file mode 100644
index 0000000..7dc6c11
--- /dev/null
+++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/IExt.java
@@ -0,0 +1,14 @@
+package com.github.yulichang.wrapper.interfaces;
+
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+
+/**
+ * @param wrapper
+ * @auther yulichang
+ * @since 1.5.2
+ */
+public interface IExt> {
+
+ Children getChildren();
+}
+
diff --git a/mybatis-plus-join-test/test-join/pom.xml b/mybatis-plus-join-test/test-join/pom.xml
index 34051b6..b0bad7c 100644
--- a/mybatis-plus-join-test/test-join/pom.xml
+++ b/mybatis-plus-join-test/test-join/pom.xml
@@ -13,6 +13,17 @@
test-join
+
+ com.github.yulichang
+ mybatis-plus-join-boot-starter
+ ${revision}
+
+
+ com.github.yulichang
+ mybatis-plus-join-wrapper-ext
+
+
+
com.github.yulichang
test-base
diff --git a/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/wrapper/ext/Ext.java b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
new file mode 100644
index 0000000..e2355b6
--- /dev/null
+++ b/mybatis-plus-join-test/test-join/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
@@ -0,0 +1,14 @@
+package com.github.yulichang.wrapper.ext;
+
+import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.github.yulichang.wrapper.interfaces.IExt;
+
+@SuppressWarnings("unused")
+public interface Ext> extends IExt {
+
+ default Children cccEq(SFunction c, Object val) {
+ getChildren().eq(c, val);
+ return getChildren();
+ }
+}
diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ExtWrapperTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ExtWrapperTest.java
new file mode 100644
index 0000000..1e948bd
--- /dev/null
+++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ExtWrapperTest.java
@@ -0,0 +1,34 @@
+package com.github.yulichang.test.join.unit;
+
+import com.github.yulichang.test.join.entity.UserDO;
+import com.github.yulichang.test.util.Reset;
+import com.github.yulichang.test.util.ThreadLocalUtils;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class ExtWrapperTest {
+
+
+ @BeforeEach
+ void setUp() {
+ Reset.reset();
+ }
+
+
+ @Test
+ void applyFunc() {
+ ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, " +
+ "t.sex, t.head_img, t.create_time, t.address_id, " +
+ "t.address_id2, t.del, t.create_by, t.update_by " +
+ "FROM `user` t WHERE t.del = false AND (t.id = ?)");
+ MPJLambdaWrapper wrapper = JoinWrappers.lambda(UserDO.class)
+ .selectAll()
+ .cccEq(UserDO::getId, 1);
+ wrapper.list();
+ }
+
+}
diff --git a/plugin/mybatis-plus-join-solon-plugin/pom.xml b/plugin/mybatis-plus-join-solon-plugin/pom.xml
index 87dac5a..4204d07 100644
--- a/plugin/mybatis-plus-join-solon-plugin/pom.xml
+++ b/plugin/mybatis-plus-join-solon-plugin/pom.xml
@@ -9,6 +9,7 @@
${revision}
../../pom.xml
+ ${revision}
mybatis-plus-join-solon-plugin
diff --git a/plugin/mybatis-plus-join-wrapper-ext/pom.xml b/plugin/mybatis-plus-join-wrapper-ext/pom.xml
new file mode 100644
index 0000000..1c07b79
--- /dev/null
+++ b/plugin/mybatis-plus-join-wrapper-ext/pom.xml
@@ -0,0 +1,16 @@
+
+
+ 4.0.0
+
+ com.github.yulichang
+ mybatis-plus-join-root
+ ${revision}
+ ../../pom.xml
+
+ ${revision}
+
+ mybatis-plus-join-wrapper-ext
+
+
\ No newline at end of file
diff --git a/plugin/mybatis-plus-join-wrapper-ext/src/main/java/com/github/yulichang/wrapper/ext/Ext.java b/plugin/mybatis-plus-join-wrapper-ext/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
new file mode 100644
index 0000000..9d393a6
--- /dev/null
+++ b/plugin/mybatis-plus-join-wrapper-ext/src/main/java/com/github/yulichang/wrapper/ext/Ext.java
@@ -0,0 +1,13 @@
+package com.github.yulichang.wrapper.ext;
+
+
+/**
+ * 自定义Wrapper扩展
+ *
+ * @param wrapper 一般是指 MPJLambdaWrapper
+ * @auther yulichang
+ * @since 1.5.2
+ */
+@SuppressWarnings("unused")
+public interface Ext {
+}
diff --git a/pom.xml b/pom.xml
index 53875f5..959f14c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
plugin/mybatis-plus-join-solon-plugin
plugin/mybatis-plus-join-processor
+ plugin/mybatis-plus-join-wrapper-ext
mybatis-plus-join-test