mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
mp -> 3.5.6 & 适配jsqlparser
This commit is contained in:
parent
cd68b2e25d
commit
7eb5605fff
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mybatis-plus-join-adapter-jsqlparser-v46</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<name>mybatis-plus-join-adapter-jsqlparser-v46</name>
|
||||||
|
|
||||||
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>mybatis-plus-join</id>
|
||||||
|
<name>yulichang</name>
|
||||||
|
<email>yu_lichang@qq.com</email>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</connection>
|
||||||
|
<developerConnection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</developerConnection>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jdkVersion>1.8</jdkVersion>
|
||||||
|
<jdkVersion.test>1.8</jdkVersion.test>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<github.global.server>github</github.global.server>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-core</artifactId>
|
||||||
|
<version>3.5.5</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.github.yulichang.adapter.jsqlparser.v46;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||||
|
import net.sf.jsqlparser.schema.Column;
|
||||||
|
import net.sf.jsqlparser.statement.Statement;
|
||||||
|
import net.sf.jsqlparser.statement.select.*;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段解析
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.12
|
||||||
|
*/
|
||||||
|
public class JSqlParserHelperV46 {
|
||||||
|
|
||||||
|
public static void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
try {
|
||||||
|
boolean parser = false;
|
||||||
|
Statement statement = CCJSqlParserUtil.parse(String.format("SELECT %s FROM table %s %s", selectSql, alias, from));
|
||||||
|
if (statement instanceof Select) {
|
||||||
|
Select select = (Select) statement;
|
||||||
|
SelectBody selectBody = select.getSelectBody();
|
||||||
|
if (selectBody instanceof PlainSelect) {
|
||||||
|
PlainSelect plainSelect = (PlainSelect) selectBody;
|
||||||
|
if (CollectionUtils.isNotEmpty(plainSelect.getSelectItems())) {
|
||||||
|
for (SelectItem item : plainSelect.getSelectItems()) {
|
||||||
|
if (item instanceof SelectExpressionItem) {
|
||||||
|
String col;
|
||||||
|
SelectExpressionItem selectExpressionItem = (SelectExpressionItem) item;
|
||||||
|
if (null == selectExpressionItem.getAlias()) {
|
||||||
|
if (selectExpressionItem.getExpression() instanceof Column) {
|
||||||
|
col = ((Column) selectExpressionItem.getExpression()).getColumnName();
|
||||||
|
} else {
|
||||||
|
col = selectExpressionItem.getExpression().toString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
col = selectExpressionItem.getAlias().getName();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(col)) {
|
||||||
|
columConsumer.accept(StringUtils.getTargetColumn(col));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parser = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!parser)
|
||||||
|
throw ExceptionUtils.mpe("JSqlParser parser error <%s>", selectSql);
|
||||||
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throw new RuntimeException(throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mybatis-plus-join-adapter-jsqlparser</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<name>mybatis-plus-join-adapter-jsqlparser</name>
|
||||||
|
|
||||||
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>mybatis-plus-join</id>
|
||||||
|
<name>yulichang</name>
|
||||||
|
<email>yu_lichang@qq.com</email>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</connection>
|
||||||
|
<developerConnection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</developerConnection>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jdkVersion>1.8</jdkVersion>
|
||||||
|
<jdkVersion.test>1.8</jdkVersion.test>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<github.global.server>github</github.global.server>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-core</artifactId>
|
||||||
|
<version>${mpj.mybatis.plus.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.github.yulichang.adapter.jsqlparser;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||||
|
import net.sf.jsqlparser.schema.Column;
|
||||||
|
import net.sf.jsqlparser.statement.Statement;
|
||||||
|
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||||
|
import net.sf.jsqlparser.statement.select.SelectItem;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段解析
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.12
|
||||||
|
*/
|
||||||
|
public class JSqlParserHelper {
|
||||||
|
|
||||||
|
public static void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
try {
|
||||||
|
boolean parser = false;
|
||||||
|
Statement statement = CCJSqlParserUtil.parse(String.format("SELECT %s FROM table %s %s", selectSql, alias, from));
|
||||||
|
if (statement instanceof PlainSelect) {
|
||||||
|
PlainSelect plainSelect = (PlainSelect) statement;
|
||||||
|
if (CollectionUtils.isNotEmpty(plainSelect.getSelectItems())) {
|
||||||
|
for (SelectItem<?> item : plainSelect.getSelectItems()) {
|
||||||
|
String col;
|
||||||
|
if (item.getAlias() == null) {
|
||||||
|
if (item.getExpression() instanceof Column) {
|
||||||
|
Column column = (Column) item.getExpression();
|
||||||
|
col = column.getColumnName();
|
||||||
|
} else {
|
||||||
|
col = item.getExpression().toString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
col = item.getAlias().getName();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(col)) {
|
||||||
|
columConsumer.accept(StringUtils.getTargetColumn(col));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parser = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!parser)
|
||||||
|
throw ExceptionUtils.mpe("JSqlParser parser error <%s>", selectSql);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throw new RuntimeException(throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,9 +41,14 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>mybatis-plus-join-adapter-jsqlparser</artifactId>
|
||||||
<scope>provided</scope>
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-jsqlparser-v46</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -7,6 +7,7 @@ import org.apache.ibatis.session.Configuration;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ import java.util.stream.Collectors;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.3
|
* @since 1.4.3
|
||||||
*/
|
*/
|
||||||
public interface ITableInfoAdapter {
|
public interface IAdapter {
|
||||||
|
|
||||||
default boolean mpjHasLogic(TableInfo tableInfo) {
|
default boolean mpjHasLogic(TableInfo tableInfo) {
|
||||||
return tableInfo.isWithLogicDelete();
|
return tableInfo.isWithLogicDelete();
|
||||||
@ -44,4 +45,6 @@ public interface ITableInfoAdapter {
|
|||||||
return tableInfo.getOrderByFields().stream().map(f ->
|
return tableInfo.getOrderByFields().stream().map(f ->
|
||||||
new OrderFieldInfo(f.getColumn(), f.getType(), f.getSort())).collect(Collectors.toList());
|
new OrderFieldInfo(f.getColumn(), f.getType(), f.getSort())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer);
|
||||||
}
|
}
|
@ -4,21 +4,23 @@ import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||||
|
import com.github.yulichang.adapter.jsqlparser.v46.JSqlParserHelperV46;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.3
|
* @since 1.4.3
|
||||||
*/
|
*/
|
||||||
public class TableInfoAdapterV33x implements ITableInfoAdapter {
|
public class AdapterV33x implements IAdapter {
|
||||||
|
|
||||||
private static final boolean is330 = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.3.0") == 0;
|
private static final boolean is330 = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.3.0") == 0;
|
||||||
|
|
||||||
@ -51,11 +53,16 @@ public class TableInfoAdapterV33x implements ITableInfoAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier) {
|
public Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier) {
|
||||||
return is330 ? supplier.get() : ITableInfoAdapter.super.mpjGetField(fieldInfo, null);
|
return is330 ? supplier.get() : IAdapter.super.mpjGetField(fieldInfo, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OrderFieldInfo> mpjGetOrderField(TableInfo tableInfo) {
|
public List<OrderFieldInfo> mpjGetOrderField(TableInfo tableInfo) {
|
||||||
throw new UnsupportedOperationException("不支持排序");
|
throw new UnsupportedOperationException("不支持排序");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
JSqlParserHelperV46.parserColum(alias, from, selectSql, columConsumer);
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,18 +2,22 @@ package com.github.yulichang.adapter.v3431;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||||
|
import com.github.yulichang.adapter.jsqlparser.v46.JSqlParserHelperV46;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.7
|
* @since 1.4.7
|
||||||
*/
|
*/
|
||||||
public class TableInfoAdapter3431 implements ITableInfoAdapter {
|
@AllArgsConstructor
|
||||||
|
public class Adapter3431 implements IAdapter {
|
||||||
|
|
||||||
private static final boolean v = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3") < 0;
|
private static final boolean v = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3") < 0;
|
||||||
|
|
||||||
@ -22,4 +26,9 @@ public class TableInfoAdapter3431 implements ITableInfoAdapter {
|
|||||||
return v ? null : tableInfo.getOrderByFields().stream().map(f ->
|
return v ? null : tableInfo.getOrderByFields().stream().map(f ->
|
||||||
new OrderFieldInfo(f.getColumn(), f.getOrderByType(), f.getOrderBySort())).collect(Collectors.toList());
|
new OrderFieldInfo(f.getColumn(), f.getOrderByType(), f.getOrderBySort())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
JSqlParserHelperV46.parserColum(alias, from, selectSql, columConsumer);
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-v355</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<name>mybatis-plus-join-adapter-v355</name>
|
||||||
|
|
||||||
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>mybatis-plus-join</id>
|
||||||
|
<name>yulichang</name>
|
||||||
|
<email>yu_lichang@qq.com</email>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</connection>
|
||||||
|
<developerConnection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</developerConnection>
|
||||||
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jdkVersion>1.8</jdkVersion>
|
||||||
|
<jdkVersion.test>1.8</jdkVersion.test>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<github.global.server>github</github.global.server>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-base</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-core</artifactId>
|
||||||
|
<version>3.5.5</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.github.yulichang.adapter.v355;
|
||||||
|
|
||||||
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
|
import com.github.yulichang.adapter.jsqlparser.v46.JSqlParserHelperV46;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.12
|
||||||
|
*/
|
||||||
|
public class Adapter355 implements IAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
JSqlParserHelperV46.parserColum(alias, from, selectSql, columConsumer);
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,9 @@
|
|||||||
<module>mybatis-plus-join-adapter-v33x</module>
|
<module>mybatis-plus-join-adapter-v33x</module>
|
||||||
<module>mybatis-plus-join-adapter-v3431</module>
|
<module>mybatis-plus-join-adapter-v3431</module>
|
||||||
<module>mybatis-plus-join-adapter-v352</module>
|
<module>mybatis-plus-join-adapter-v352</module>
|
||||||
|
<module>mybatis-plus-join-adapter-v355</module>
|
||||||
|
<module>jsqlparser/mybatis-plus-join-adapter-jsqlparser</module>
|
||||||
|
<module>jsqlparser/mybatis-plus-join-adapter-jsqlparser-v46</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
@ -40,4 +43,11 @@
|
|||||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -54,6 +54,11 @@
|
|||||||
<artifactId>mybatis-plus-join-adapter-v352</artifactId>
|
<artifactId>mybatis-plus-join-adapter-v352</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-adapter-v355</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-extension</artifactId>
|
<artifactId>mybatis-plus-extension</artifactId>
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.github.yulichang.adapter;
|
||||||
|
|
||||||
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
|
import com.github.yulichang.adapter.jsqlparser.JSqlParserHelper;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.3
|
||||||
|
*/
|
||||||
|
public class Adapter implements IAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||||
|
JSqlParserHelper.parserColum(alias, from, selectSql, columConsumer);
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,12 @@ package com.github.yulichang.adapter;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||||
import com.github.yulichang.adapter.v33x.TableInfoAdapterV33x;
|
import com.github.yulichang.adapter.v33x.AdapterV33x;
|
||||||
import com.github.yulichang.adapter.v3431.TableInfoAdapter3431;
|
import com.github.yulichang.adapter.v3431.Adapter3431;
|
||||||
|
import com.github.yulichang.adapter.v355.Adapter355;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
@ -13,22 +15,23 @@ import com.github.yulichang.adapter.v3431.TableInfoAdapter3431;
|
|||||||
*/
|
*/
|
||||||
public class AdapterHelper {
|
public class AdapterHelper {
|
||||||
|
|
||||||
private static final ITableInfoAdapter adapter;
|
@Getter
|
||||||
|
private static final IAdapter adapter;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String version = MybatisPlusVersion.getVersion();
|
String version = MybatisPlusVersion.getVersion();
|
||||||
if (VersionUtils.compare(version, "3.5.4") >= 0) {
|
|
||||||
adapter = new TableInfoAdapter();
|
if (VersionUtils.compare(version, "3.5.6") >= 0) {
|
||||||
|
adapter = new Adapter();
|
||||||
|
} else if (VersionUtils.compare(version, "3.5.4") >= 0) {
|
||||||
|
adapter = new Adapter355();
|
||||||
} else if (VersionUtils.compare(version, "3.4.0") >= 0) {
|
} else if (VersionUtils.compare(version, "3.4.0") >= 0) {
|
||||||
adapter = new TableInfoAdapter3431();
|
adapter = new Adapter3431();
|
||||||
} else if (VersionUtils.compare(version, "3.3.0") >= 0) {
|
} else if (VersionUtils.compare(version, "3.3.0") >= 0) {
|
||||||
adapter = new TableInfoAdapterV33x();
|
adapter = new AdapterV33x();
|
||||||
} else {
|
} else {
|
||||||
throw ExceptionUtils.mpe("MPJ需要MP版本3.3.0+,当前MP版本%s", version);
|
throw ExceptionUtils.mpe("MPJ需要MP版本3.3.0+,当前MP版本%s", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ITableInfoAdapter getTableInfoAdapter() {
|
|
||||||
return adapter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package com.github.yulichang.adapter;
|
|
||||||
|
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yulichang
|
|
||||||
* @since 1.4.3
|
|
||||||
*/
|
|
||||||
public class TableInfoAdapter implements ITableInfoAdapter {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package com.github.yulichang.config;
|
package com.github.yulichang.config;
|
||||||
|
|
||||||
import com.github.yulichang.adapter.AdapterHelper;
|
import com.github.yulichang.adapter.AdapterHelper;
|
||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.IAdapter;
|
||||||
import com.github.yulichang.config.enums.IfExistsEnum;
|
import com.github.yulichang.config.enums.IfExistsEnum;
|
||||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||||
@ -45,7 +45,7 @@ public class ConfigProperties {
|
|||||||
/**
|
/**
|
||||||
* TableInfo适配器
|
* TableInfo适配器
|
||||||
*/
|
*/
|
||||||
public static ITableInfoAdapter tableInfoAdapter = AdapterHelper.getTableInfoAdapter();
|
public static IAdapter tableInfoAdapter = AdapterHelper.getAdapter();
|
||||||
/**
|
/**
|
||||||
* 子查询别名
|
* 子查询别名
|
||||||
*/
|
*/
|
||||||
|
@ -2,13 +2,16 @@ package com.github.yulichang.interceptor;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||||
|
import com.github.yulichang.adapter.AdapterHelper;
|
||||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||||
import com.github.yulichang.config.ConfigProperties;
|
import com.github.yulichang.config.ConfigProperties;
|
||||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||||
import com.github.yulichang.query.MPJQueryWrapper;
|
import com.github.yulichang.query.MPJQueryWrapper;
|
||||||
import com.github.yulichang.toolkit.*;
|
import com.github.yulichang.toolkit.Constant;
|
||||||
|
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||||
|
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||||
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
import com.github.yulichang.toolkit.support.FieldCache;
|
import com.github.yulichang.toolkit.support.FieldCache;
|
||||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
||||||
import com.github.yulichang.wrapper.resultmap.IResult;
|
import com.github.yulichang.wrapper.resultmap.IResult;
|
||||||
@ -205,7 +208,7 @@ public class MPJInterceptor implements Interceptor {
|
|||||||
resultMappings.add(selectToResult(wrapper.getEntityClass(), i, field.getType(), builder));
|
resultMappings.add(selectToResult(wrapper.getEntityClass(), i, field.getType(), builder));
|
||||||
}
|
}
|
||||||
} else if (wrapper.isResultMap()) {
|
} else if (wrapper.isResultMap()) {
|
||||||
ThrowOptional.tryDo(() -> JSqlParserHelper.paresColum(wrapper, i.getColumn(), col -> {
|
AdapterHelper.getAdapter().parserColum(wrapper.getAlias(), wrapper.getFrom(), i.getColumn(), col -> {
|
||||||
FieldCache strField = fieldMap.get(col);
|
FieldCache strField = fieldMap.get(col);
|
||||||
columnSet.add(col);
|
columnSet.add(col);
|
||||||
if (Objects.nonNull(strField)) {
|
if (Objects.nonNull(strField)) {
|
||||||
@ -213,7 +216,7 @@ public class MPJInterceptor implements Interceptor {
|
|||||||
col, strField.getType());
|
col, strField.getType());
|
||||||
resultMappings.add(selectToResult(wrapper.getEntityClass(), i, strField.getType(), builder));
|
resultMappings.add(selectToResult(wrapper.getEntityClass(), i, strField.getType(), builder));
|
||||||
}
|
}
|
||||||
})).catchDo();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,17 +168,17 @@ public class KtDeleteJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtDeleteJ
|
|||||||
Class<T> entityClass = getEntityClass();
|
Class<T> entityClass = getEntityClass();
|
||||||
TableInfo tableInfo = TableHelper.getAssert(entityClass);
|
TableInfo tableInfo = TableHelper.getAssert(entityClass);
|
||||||
//检查
|
//检查
|
||||||
boolean mainLogic = AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo);
|
boolean mainLogic = AdapterHelper.getAdapter().mpjHasLogic(tableInfo);
|
||||||
boolean check = classList.stream().allMatch(t -> {
|
boolean check = classList.stream().allMatch(t -> {
|
||||||
TableInfo ti = TableHelper.getAssert(t);
|
TableInfo ti = TableHelper.getAssert(t);
|
||||||
return mainLogic == AdapterHelper.getTableInfoAdapter().mpjHasLogic(ti);
|
return mainLogic == AdapterHelper.getAdapter().mpjHasLogic(ti);
|
||||||
});
|
});
|
||||||
if (!check) {
|
if (!check) {
|
||||||
throw ExceptionUtils.mpe("连表删除只适用于全部表(主表和副表)都是物理删除或全部都是逻辑删除, " +
|
throw ExceptionUtils.mpe("连表删除只适用于全部表(主表和副表)都是物理删除或全部都是逻辑删除, " +
|
||||||
"不支持同时存在物理删除和逻辑删除 [物理删除->(%s)] [逻辑删除->(%s)]",
|
"不支持同时存在物理删除和逻辑删除 [物理删除->(%s)] [逻辑删除->(%s)]",
|
||||||
classList.stream().filter(t -> !AdapterHelper.getTableInfoAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
classList.stream().filter(t -> !AdapterHelper.getAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
||||||
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)),
|
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)),
|
||||||
classList.stream().filter(t -> AdapterHelper.getTableInfoAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
classList.stream().filter(t -> AdapterHelper.getAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
||||||
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)));
|
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,12 +201,12 @@ public class KtUpdateJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtUpdateJ
|
|||||||
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%>", obj.getClass().getSimpleName());
|
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%>", obj.getClass().getSimpleName());
|
||||||
TableInfo tableInfo = TableHelper.getAssert(obj.getClass());
|
TableInfo tableInfo = TableHelper.getAssert(obj.getClass());
|
||||||
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object val;
|
Object val;
|
||||||
try {
|
try {
|
||||||
Field field = AdapterHelper.getTableInfoAdapter().mpjGetField(fieldInfo, () -> {
|
Field field = AdapterHelper.getAdapter().mpjGetField(fieldInfo, () -> {
|
||||||
Field field1 = ReflectionKit.getFieldMap(obj.getClass()).get(fieldInfo.getProperty());
|
Field field1 = ReflectionKit.getFieldMap(obj.getClass()).get(fieldInfo.getProperty());
|
||||||
field1.setAccessible(true);
|
field1.setAccessible(true);
|
||||||
return field1;
|
return field1;
|
||||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.github.yulichang.kt.segments.FuncArgs;
|
import com.github.yulichang.kt.segments.FuncArgs;
|
||||||
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.toolkit.KtUtils;
|
import com.github.yulichang.toolkit.KtUtils;
|
||||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
@ -98,7 +99,7 @@ public interface Query<Children> extends Serializable {
|
|||||||
* @param column 列
|
* @param column 列
|
||||||
*/
|
*/
|
||||||
default Children selectAs(String column, KProperty<?> alias) {
|
default Children selectAs(String column, KProperty<?> alias) {
|
||||||
getSelectColum().add(new SelectString(column + Constants.AS + alias.getName(), alias.getName()));
|
getSelectColum().add(new SelectString(column + Constant.AS + alias.getName(), alias.getName()));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ public interface Query<Children> extends Serializable {
|
|||||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(KtUtils.ref(column));
|
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(KtUtils.ref(column));
|
||||||
SelectCache cache = cacheMap.get(column.getName());
|
SelectCache cache = cacheMap.get(column.getName());
|
||||||
getSelectColum().add(new SelectString(
|
getSelectColum().add(new SelectString(
|
||||||
index + Constants.DOT + cache.getColumn() + Constants.AS + alias.getName(), alias.getName()));
|
index + Constants.DOT + cache.getColumn() + Constant.AS + alias.getName(), alias.getName()));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class DeleteJoin extends MPJAbstractMethod {
|
|||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||||
SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_JOIN;
|
SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_JOIN;
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo)) {
|
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo)) {
|
||||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), mpjTableName(tableInfo), sqlAlias(), sqlFrom(),
|
String sql = String.format(sqlMethod.getSql(), sqlFirst(), mpjTableName(tableInfo), sqlAlias(), sqlFrom(),
|
||||||
mpjDeleteLogic(tableInfo), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
mpjDeleteLogic(tableInfo), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||||
|
@ -73,7 +73,7 @@ public interface MPJBaseMethod extends Constants {
|
|||||||
/* 不存在排序字段,直接返回空 */
|
/* 不存在排序字段,直接返回空 */
|
||||||
List<OrderFieldInfo> orderByFields;
|
List<OrderFieldInfo> orderByFields;
|
||||||
try {
|
try {
|
||||||
orderByFields = AdapterHelper.getTableInfoAdapter().mpjGetOrderField(tableInfo);
|
orderByFields = AdapterHelper.getAdapter().mpjGetOrderField(tableInfo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return StringPool.EMPTY;
|
return StringPool.EMPTY;
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ public interface MPJBaseMethod extends Constants {
|
|||||||
return tableInfo.getFieldList().stream()
|
return tableInfo.getFieldList().stream()
|
||||||
.filter(i -> {
|
.filter(i -> {
|
||||||
if (ignoreLogicDelFiled) {
|
if (ignoreLogicDelFiled) {
|
||||||
return !(AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo) && i.isLogicDelete());
|
return !(AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && i.isLogicDelete());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}).map(i -> mpjGetSqlSet(i, newPrefix)).filter(Objects::nonNull).collect(joining(NEWLINE));
|
}).map(i -> mpjGetSqlSet(i, newPrefix)).filter(Objects::nonNull).collect(joining(NEWLINE));
|
||||||
|
@ -64,7 +64,7 @@ public class UpdateJoin extends MPJAbstractMethod {
|
|||||||
if (fieldStrategy == FieldStrategy.NEVER) {
|
if (fieldStrategy == FieldStrategy.NEVER) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjIsPrimitive(tableFieldInfo) || fieldStrategy == FieldStrategy.IGNORED) {
|
if (AdapterHelper.getAdapter().mpjIsPrimitive(tableFieldInfo) || fieldStrategy == FieldStrategy.IGNORED) {
|
||||||
return sqlScript;
|
return sqlScript;
|
||||||
}
|
}
|
||||||
if (fieldStrategy == FieldStrategy.NOT_EMPTY && tableFieldInfo.isCharSequence()) {
|
if (fieldStrategy == FieldStrategy.NOT_EMPTY && tableFieldInfo.isCharSequence()) {
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package com.github.yulichang.toolkit;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
||||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
|
||||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
|
||||||
import net.sf.jsqlparser.schema.Column;
|
|
||||||
import net.sf.jsqlparser.statement.Statement;
|
|
||||||
import net.sf.jsqlparser.statement.select.*;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yulichang
|
|
||||||
* @since 1.4.10
|
|
||||||
*/
|
|
||||||
public final class JSqlParserHelper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析sql select字段 刚接触JSqlParser有更好的用法欢迎PR
|
|
||||||
*
|
|
||||||
* @param selectSql 要解析的select sql片段
|
|
||||||
* @param columConsumer 解析的字段处理
|
|
||||||
*/
|
|
||||||
public static void paresColum(SelectWrapper<?, ?> wrapper, String selectSql, Consumer<String> columConsumer) throws Exception {
|
|
||||||
Statement statement = CCJSqlParserUtil.parse(String.format("SELECT %s FROM table %s %s", selectSql, wrapper.getAlias(), wrapper.getFrom()));
|
|
||||||
if (statement instanceof Select) {
|
|
||||||
Select select = (Select) statement;
|
|
||||||
SelectBody selectBody = select.getSelectBody();
|
|
||||||
if (selectBody instanceof PlainSelect) {
|
|
||||||
PlainSelect plainSelect = (PlainSelect) selectBody;
|
|
||||||
if (CollectionUtils.isNotEmpty(plainSelect.getSelectItems())) {
|
|
||||||
for (SelectItem item : plainSelect.getSelectItems()) {
|
|
||||||
if (item instanceof SelectExpressionItem) {
|
|
||||||
String col;
|
|
||||||
SelectExpressionItem selectExpressionItem = (SelectExpressionItem) item;
|
|
||||||
if (null == selectExpressionItem.getAlias()) {
|
|
||||||
if (selectExpressionItem.getExpression() instanceof Column) {
|
|
||||||
col = ((Column) selectExpressionItem.getExpression()).getColumnName();
|
|
||||||
} else {
|
|
||||||
col = selectExpressionItem.getExpression().toString();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
col = selectExpressionItem.getAlias().getName();
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(col)) {
|
|
||||||
columConsumer.accept(StringUtils.getTargetColumn(col));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -98,7 +98,7 @@ public class KtWrapperUtils {
|
|||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder(StringPool.EMPTY);
|
StringBuilder sb = new StringBuilder(StringPool.EMPTY);
|
||||||
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object val;
|
Object val;
|
||||||
|
@ -98,7 +98,7 @@ public class WrapperUtils {
|
|||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder(StringPool.EMPTY);
|
StringBuilder sb = new StringBuilder(StringPool.EMPTY);
|
||||||
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object val;
|
Object val;
|
||||||
|
@ -171,17 +171,17 @@ public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoi
|
|||||||
Class<T> entityClass = getEntityClass();
|
Class<T> entityClass = getEntityClass();
|
||||||
TableInfo tableInfo = TableHelper.getAssert(entityClass);
|
TableInfo tableInfo = TableHelper.getAssert(entityClass);
|
||||||
//检查
|
//检查
|
||||||
boolean mainLogic = AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo);
|
boolean mainLogic = AdapterHelper.getAdapter().mpjHasLogic(tableInfo);
|
||||||
boolean check = classList.stream().allMatch(t -> {
|
boolean check = classList.stream().allMatch(t -> {
|
||||||
TableInfo ti = TableHelper.getAssert(t);
|
TableInfo ti = TableHelper.getAssert(t);
|
||||||
return mainLogic == AdapterHelper.getTableInfoAdapter().mpjHasLogic(ti);
|
return mainLogic == AdapterHelper.getAdapter().mpjHasLogic(ti);
|
||||||
});
|
});
|
||||||
if (!check) {
|
if (!check) {
|
||||||
throw ExceptionUtils.mpe("连表删除只适用于全部表(主表和副表)都是物理删除或全部都是逻辑删除, " +
|
throw ExceptionUtils.mpe("连表删除只适用于全部表(主表和副表)都是物理删除或全部都是逻辑删除, " +
|
||||||
"不支持同时存在物理删除和逻辑删除 [物理删除->(%s)] [逻辑删除->(%s)]",
|
"不支持同时存在物理删除和逻辑删除 [物理删除->(%s)] [逻辑删除->(%s)]",
|
||||||
classList.stream().filter(t -> !AdapterHelper.getTableInfoAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
classList.stream().filter(t -> !AdapterHelper.getAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
||||||
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)),
|
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)),
|
||||||
classList.stream().filter(t -> AdapterHelper.getTableInfoAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
classList.stream().filter(t -> AdapterHelper.getAdapter().mpjHasLogic(TableHelper.getAssert(t)))
|
||||||
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)));
|
.map(Class::getSimpleName).collect(Collectors.joining(StringPool.COMMA)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,12 +203,12 @@ public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoi
|
|||||||
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%>", obj.getClass().getSimpleName());
|
Assert.isTrue(tableList.contain(obj.getClass()), "更新的实体不是主表或关联表 <%>", obj.getClass().getSimpleName());
|
||||||
TableInfo tableInfo = TableHelper.getAssert(obj.getClass());
|
TableInfo tableInfo = TableHelper.getAssert(obj.getClass());
|
||||||
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo) && fieldInfo.isLogicDelete()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object val;
|
Object val;
|
||||||
try {
|
try {
|
||||||
Field field = AdapterHelper.getTableInfoAdapter().mpjGetField(fieldInfo, () -> {
|
Field field = AdapterHelper.getAdapter().mpjGetField(fieldInfo, () -> {
|
||||||
Field field1 = ReflectionKit.getFieldMap(obj.getClass()).get(fieldInfo.getProperty());
|
Field field1 = ReflectionKit.getFieldMap(obj.getClass()).get(fieldInfo.getProperty());
|
||||||
field1.setAccessible(true);
|
field1.setAccessible(true);
|
||||||
return field1;
|
return field1;
|
||||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
import com.github.yulichang.toolkit.LambdaUtils;
|
||||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
@ -97,7 +98,7 @@ public interface Query<Children> extends Serializable {
|
|||||||
*/
|
*/
|
||||||
default <E> Children selectAs(String column, SFunction<E, ?> alias) {
|
default <E> Children selectAs(String column, SFunction<E, ?> alias) {
|
||||||
String name = LambdaUtils.getName(alias);
|
String name = LambdaUtils.getName(alias);
|
||||||
getSelectColum().add(new SelectString(column + Constants.AS + name, name));
|
getSelectColum().add(new SelectString(column + Constant.AS + name, name));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ public interface Query<Children> extends Serializable {
|
|||||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(LambdaUtils.getEntityClass(column));
|
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(LambdaUtils.getEntityClass(column));
|
||||||
SelectCache cache = cacheMap.get(LambdaUtils.getName(column));
|
SelectCache cache = cacheMap.get(LambdaUtils.getName(column));
|
||||||
String name = LambdaUtils.getName(alias);
|
String name = LambdaUtils.getName(alias);
|
||||||
getSelectColum().add(new SelectString(index + Constants.DOT + cache.getColumn() + Constants.AS + name, name));
|
getSelectColum().add(new SelectString(index + Constants.DOT + cache.getColumn() + Constant.AS + name, name));
|
||||||
return getChildren();
|
return getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class MPJTableFieldInfo {
|
|||||||
TableFieldInfo joinFieldInfo = joinTableInfo.getFieldList().stream().filter(f ->
|
TableFieldInfo joinFieldInfo = joinTableInfo.getFieldList().stream().filter(f ->
|
||||||
f.getProperty().equals(this.joinProperty)).findFirst().orElse(null);
|
f.getProperty().equals(this.joinProperty)).findFirst().orElse(null);
|
||||||
if (joinFieldInfo == null) {
|
if (joinFieldInfo == null) {
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasPK(joinTableInfo) && this.joinProperty.equals(joinTableInfo.getKeyProperty())) {
|
if (AdapterHelper.getAdapter().mpjHasPK(joinTableInfo) && this.joinProperty.equals(joinTableInfo.getKeyProperty())) {
|
||||||
this.joinColumn = joinTableInfo.getKeyColumn();
|
this.joinColumn = joinTableInfo.getKeyColumn();
|
||||||
this.joinField = ReflectionKit.getFieldList(this.joinClass).stream().filter(i ->
|
this.joinField = ReflectionKit.getFieldList(this.joinClass).stream().filter(i ->
|
||||||
i.getName().equals(joinTableInfo.getKeyProperty())).findFirst().orElse(null);
|
i.getName().equals(joinTableInfo.getKeyProperty())).findFirst().orElse(null);
|
||||||
@ -218,7 +218,7 @@ public class MPJTableFieldInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TableInfo tableInfo = getTableInfo(this.entityType);
|
TableInfo tableInfo = getTableInfo(this.entityType);
|
||||||
if (AdapterHelper.getTableInfoAdapter().mpjHasPK(tableInfo) && this.thisProperty.equals(tableInfo.getKeyProperty())) {
|
if (AdapterHelper.getAdapter().mpjHasPK(tableInfo) && this.thisProperty.equals(tableInfo.getKeyProperty())) {
|
||||||
this.thisField = ReflectionKit.getFieldList(ClassUtils.getUserClass(entityType)).stream().filter(f ->
|
this.thisField = ReflectionKit.getFieldList(ClassUtils.getUserClass(entityType)).stream().filter(f ->
|
||||||
f.getName().equals(tableInfo.getKeyProperty())).findFirst().orElse(null);
|
f.getName().equals(tableInfo.getKeyProperty())).findFirst().orElse(null);
|
||||||
Assert.notNull(this.thisField, "注解属性thisField不存在 %s , %s", entityType.getName(),
|
Assert.notNull(this.thisField, "注解属性thisField不存在 %s , %s", entityType.getName(),
|
||||||
@ -313,7 +313,7 @@ public class MPJTableFieldInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(Class<?> table, TableFieldInfo tableFieldInfo) {
|
private Field getField(Class<?> table, TableFieldInfo tableFieldInfo) {
|
||||||
return AdapterHelper.getTableInfoAdapter().mpjGetField(tableFieldInfo, () ->
|
return AdapterHelper.getAdapter().mpjGetField(tableFieldInfo, () ->
|
||||||
ReflectionKit.getFieldMap(table).get(tableFieldInfo.getProperty()));
|
ReflectionKit.getFieldMap(table).get(tableFieldInfo.getProperty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>1.4.11</revision>
|
<revision>1.4.11</revision>
|
||||||
<mpj.mybatis.plus.version>3.5.5</mpj.mybatis.plus.version>
|
<mpj.mybatis.plus.version>3.5.6</mpj.mybatis.plus.version>
|
||||||
|
|
||||||
<jdkVersion>1.8</jdkVersion>
|
<jdkVersion>1.8</jdkVersion>
|
||||||
<jdkVersion.test>1.8</jdkVersion.test>
|
<jdkVersion.test>1.8</jdkVersion.test>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>1.4.11</revision>
|
<revision>1.4.11</revision>
|
||||||
<mpj.mybatis.plus.version>3.5.5</mpj.mybatis.plus.version>
|
<mpj.mybatis.plus.version>3.5.6</mpj.mybatis.plus.version>
|
||||||
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
2
pom.xml
2
pom.xml
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>1.4.11</revision>
|
<revision>1.4.11</revision>
|
||||||
<mpj.mybatis.plus.version>3.5.5</mpj.mybatis.plus.version>
|
<mpj.mybatis.plus.version>3.5.6</mpj.mybatis.plus.version>
|
||||||
|
|
||||||
<jdkVersion>1.8</jdkVersion>
|
<jdkVersion>1.8</jdkVersion>
|
||||||
<jdkVersion.test>1.8</jdkVersion.test>
|
<jdkVersion.test>1.8</jdkVersion.test>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user