Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
life 2023-08-07 15:36:33 +08:00
commit f8efef2e18
28 changed files with 169 additions and 78 deletions

View File

@ -2,6 +2,37 @@
## v1.5.6 20230804:
- 新增:代码生成器重构并新增对 Solon 框架的代码生成功能,感谢 @Suomm
- 新增:添加新的默认的达梦方言,之前使用 Oracle感谢 @qimincow
- 优化:优化 QueryWrapper.toSQL() 的性能
- 优化:添加 "未配置事务生成器" 时的异常信息国际化支持
- 优化:重构 KeywordWrap.java 使之代码逻辑更加清晰
- 优化:重构代码生成器的 Generator使之在 web 中在线生成时,保证链接正常关闭
- 优化:代码生成器的 Column 添加关于数据库类型和长度的相关属性
- 优化:优化 QueryWrapper.exists() 的性能,感谢 @gongzhongqiang
- 优化:修改 FlexIDKeyGenerator 注释描述错误的问题,感谢 @duxlei
- 修复:新增 spring-devtools.properties 已解决 Spring 类转换异常的问题
- 修复QueryWrapper 同时 left join 两个同一个表的时候,逻辑删除条件不正确的问题 #I7QD29
- 修复RelationManager 在某些场景先可能出现 NPE 的问题
- 修复:`@UseDataSource` 注解在某些 Spring 场景下不生效的问题,感谢 @Suomm
- 修复:某些场景下,多数据源使用 JdbcTemplate 事务下使用报错的问题,感谢 @lifejwang11
- 修复FieldQueryManager.java 在某些极端场景下出现 NPE 的问题,感谢 @loong0306
- 修复:同表连接查询,别名匹配不正确的问题,感谢 @qimincow
- 修复QueryMethods.column 等构建列使用 as 方法设置别名无效的问题,感谢 @Suomm
- 文档:添加 QueryWrapper join 自身的相关示例
- 文档:常见问题添加启动失败说明列表,感谢 @Suomm
- 文档:优化关于 ActiveRecord 的相关文档,感谢 @Suomm
- 文档:修改 Auto-Mapper 的一些错误文档,感谢 @Suomm
- 文档:修改 APT 的配置描述错误的文档,感谢 @Suomm
- 文档:修改 APT generateEnable 描述错误的问题,感谢 @cijie
- 文档:修改代码生成器的示例代码错误的文档,感谢 @Suomm
- 文档:更新 MyBatis-Flex-Helper 的相关文档和截图
- 文档:优化 MyBatis 原生使用的相关文档,感谢 @pioneer-sun
- 文档:修改关于 FAQ 的相关描述错误问题,感谢 @wlf213
## v1.5.5 20230801:
- 新增:添加对 xml 分页查询的支持
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
@ -43,7 +74,7 @@
- 新增:多数据源功能添加负载均衡的能力
- 新增QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
- 新增:添加异常信息国际的支持,感谢 @Suomm
- 新增:添加异常信息国际的支持,感谢 @Suomm
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
- 新增ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm

View File

@ -81,3 +81,9 @@
- [MyBatis-Flex 视频教程 - 27 version 乐观锁的简单使用](https://www.bilibili.com/video/BV1Rc411F7wp)
- [MyBatis-Flex 视频教程 - 28 tenantId 多租户的简单使用](https://www.bilibili.com/video/BV1eP41167TU)
- [MyBatis-Flex 视频教程 - 29 typeHandler 的简单使用](https://www.bilibili.com/video/BV1B841127ea)
- [MyBatis-Flex 视频教程 - 30 数据脱敏的简单使用](https://www.bilibili.com/video/BV1gz4y1s7Wg)
- [MyBatis-Flex 视频教程 - 31 枚举属性的使用](https://www.bilibili.com/video/BV1mm4y1W7SD)
- [MyBatis-Flex 视频教程 - 32 关联查询Join Query](https://www.bilibili.com/video/BV1B8411d7iC)

View File

@ -2,6 +2,37 @@
## v1.5.6 20230804:
- 新增:代码生成器重构并新增对 Solon 框架的代码生成功能,感谢 @Suomm
- 新增:添加新的默认的达梦方言,之前使用 Oracle感谢 @qimincow
- 优化:优化 QueryWrapper.toSQL() 的性能
- 优化:添加 "未配置事务生成器" 时的异常信息国际化支持
- 优化:重构 KeywordWrap.java 使之代码逻辑更加清晰
- 优化:重构代码生成器的 Generator使之在 web 中在线生成时,保证链接正常关闭
- 优化:代码生成器的 Column 添加关于数据库类型和长度的相关属性
- 优化:优化 QueryWrapper.exists() 的性能,感谢 @gongzhongqiang
- 优化:修改 FlexIDKeyGenerator 注释描述错误的问题,感谢 @duxlei
- 修复:新增 spring-devtools.properties 已解决 Spring 类转换异常的问题
- 修复QueryWrapper 同时 left join 两个同一个表的时候,逻辑删除条件不正确的问题 #I7QD29
- 修复RelationManager 在某些场景先可能出现 NPE 的问题
- 修复:`@UseDataSource` 注解在某些 Spring 场景下不生效的问题,感谢 @Suomm
- 修复:某些场景下,多数据源使用 JdbcTemplate 事务下使用报错的问题,感谢 @lifejwang11
- 修复FieldQueryManager.java 在某些极端场景下出现 NPE 的问题,感谢 @loong0306
- 修复:同表连接查询,别名匹配不正确的问题,感谢 @qimincow
- 修复QueryMethods.column 等构建列使用 as 方法设置别名无效的问题,感谢 @Suomm
- 文档:添加 QueryWrapper join 自身的相关示例
- 文档:常见问题添加启动失败说明列表,感谢 @Suomm
- 文档:优化关于 ActiveRecord 的相关文档,感谢 @Suomm
- 文档:修改 Auto-Mapper 的一些错误文档,感谢 @Suomm
- 文档:修改 APT 的配置描述错误的文档,感谢 @Suomm
- 文档:修改 APT generateEnable 描述错误的问题,感谢 @cijie
- 文档:修改代码生成器的示例代码错误的文档,感谢 @Suomm
- 文档:更新 MyBatis-Flex-Helper 的相关文档和截图
- 文档:优化 MyBatis 原生使用的相关文档,感谢 @pioneer-sun
- 文档:修改关于 FAQ 的相关描述错误问题,感谢 @wlf213
## v1.5.5 20230801:
- 新增:添加对 xml 分页查询的支持
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
@ -43,7 +74,7 @@
- 新增:多数据源功能添加负载均衡的能力
- 新增QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
- 新增:添加异常信息国际的支持,感谢 @Suomm
- 新增:添加异常信息国际的支持,感谢 @Suomm
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
- 新增ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm

View File

@ -51,7 +51,7 @@ VALUES (1, '张三', 18, '2020-01-11'),
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>

View File

@ -12,12 +12,12 @@
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
<scope>provided</scope>
</dependency>
```
@ -28,12 +28,12 @@
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
<scope>provided</scope>
</dependency>
``````
@ -44,12 +44,12 @@
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
<scope>provided</scope>
</dependency>
```
@ -70,7 +70,7 @@
<path>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-processor</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</path>
</annotationProcessorPaths>
</configuration>

View File

@ -220,7 +220,7 @@ pom.xml 添加 `annotationProcessorPaths` 配置,
```
dependencies {
...
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:<version>1.5.5</version>'
annotationProcessor 'com.mybatis-flex:mybatis-flex-processor:<version>1.5.6</version>'
}
```

View File

@ -10,7 +10,7 @@
<dependency>
<groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-codegen</artifactId>
<version>1.5.5</version>
<version>1.5.6</version>
</dependency>
```

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -25,6 +25,7 @@ import java.util.Map;
/**
* 默认方言抽象类
* @author michael
*/
public abstract class JdbcDialect implements IDialect {
@ -42,6 +43,9 @@ public abstract class JdbcDialect implements IDialect {
Column column = new Column();
column.setName(columnMetaData.getColumnName(i));
column.setRawType(columnMetaData.getColumnTypeName(i));
column.setRawLength(columnMetaData.getColumnDisplaySize(i));
String jdbcType = columnMetaData.getColumnClassName(i);
column.setPropertyType(JdbcTypeMapping.getType(jdbcType));

View File

@ -21,9 +21,7 @@ import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.codegen.config.ColumnConfig;
import com.mybatisflex.core.util.StringUtil;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
@ -71,6 +69,16 @@ public class Column {
*/
private boolean needGenColumnAnnotation = false;
/**
* 数据库的字段类型比如 varchar/tinyint
*/
private String rawType;
/**
* 数据库中的字段长度比如 varchar(32) 中的 32
*/
private int rawLength;
/**
* 字段配置
*/
@ -145,6 +153,22 @@ public class Column {
isAutoIncrement = autoIncrement;
}
public String getRawType() {
return rawType;
}
public void setRawType(String rawType) {
this.rawType = rawType;
}
public int getRawLength() {
return rawLength;
}
public void setRawLength(int rawLength) {
this.rawLength = rawLength;
}
public ColumnConfig getColumnConfig() {
return columnConfig;
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -827,7 +827,7 @@ public interface BaseMapper<T> {
((FunctionQueryColumn) selectColumns.get(0)).getFnName()
)) {
// 第一个查询列不是 COUNT 函数使用 COUNT(*) 替换所有的查询列
queryWrapper.select(count());
CPI.setSelectColumns(queryWrapper, Collections.singletonList(count()));
}
// 第一个查询列是 COUNT 函数可以使用 COUNT(1)COUNT(列名) 代替默认的 COUNT(*)
objects = selectObjectListByQuery(queryWrapper);
@ -839,7 +839,7 @@ public interface BaseMapper<T> {
objects = selectObjectListByQuery(MapperUtil.rawCountQueryWrapper(queryWrapper));
} else {
// 使用 COUNT(*) 替换所有的查询列
queryWrapper.select(count());
CPI.setSelectColumns(queryWrapper, Collections.singletonList(count()));
objects = selectObjectListByQuery(queryWrapper);
}
}

View File

@ -24,7 +24,7 @@ public class FlexConsts {
}
public static final String NAME = "MyBatis-Flex";
public static final String VERSION = "1.5.5";
public static final String VERSION = "1.5.6";
public static final String DEFAULT_PRIMARY_FIELD = "id";

View File

@ -33,7 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
* 1每台机器允许最大的并发量为 10w/s
* 2出现时间回拨重启机器时在时间回拨未恢复的情况下可能出现 id 重复
* <p>
* ID组成时间7+| 毫秒内的时间自增 00~992| 机器ID0 ~ 91| 随机数000~9993用于分库分表时通过 id 取模保证分布均衡
* ID组成时间7+| 毫秒内的时间自增 00~992| 机器ID00 ~ 992| 随机数00~992用于分库分表时通过 id 取模保证分布均衡
*/
public class FlexIDKeyGenerator implements IKeyGenerator {
@ -85,12 +85,14 @@ public class FlexIDKeyGenerator implements IKeyGenerator {
lastTimeMillis = currentTimeMillis;
long diffTimeMillis = currentTimeMillis - INITIAL_TIMESTAMP;
return diffTimeMillis * 1000000 + clockSeq * 10000 + workId * 1000 + getRandomInt();
//ID组成时间7+| 毫秒内的时间自增 00~992| 机器ID00 ~ 992| 随机数00~992
return diffTimeMillis * 1000000 + clockSeq * 10000 + workId * 100 + getRandomInt();
}
private int getRandomInt() {
return ThreadLocalRandom.current().nextInt(1000);
return ThreadLocalRandom.current().nextInt(100);
}

View File

@ -362,7 +362,9 @@ public class AccountSqlTester {
@Test
public void testJoinSelf() {
QueryWrapper queryWrapper = QueryWrapper.create()
.select()
.select(ACCOUNT.ALL_COLUMNS
// ,column("a0.xxxx").as("xxx")
)
.from(ACCOUNT).as("a0")
.leftJoin(ACCOUNT).as("a1").on(ACCOUNT.ID.eq(ACCOUNT.AGE).and(ACCOUNT.USER_NAME.like("a")))
.where(ACCOUNT.AGE.ge(10));

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -19,74 +19,64 @@ import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.datasource.FlexDataSource;
import com.mybatisflex.core.transaction.TransactionContext;
import com.mybatisflex.core.util.StringUtil;
import org.apache.ibatis.transaction.Transaction;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.apache.ibatis.transaction.Transaction;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.mybatis.spring.transaction.SpringManagedTransaction;
/**
* spring事务支持解决issusehttps://gitee.com/mybatis-flex/mybatis-flex/issues/I7HJ4J
* spring 事务支持解决 issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7HJ4J
*
* @author life
*/
public class FlexSpringTransaction implements Transaction {
private static final Logger LOGGER = LoggerFactory.getLogger(FlexSpringTransaction.class);
DataSource dataSource;
private final FlexDataSource dataSource;
private final Map<String, Connection> connectionMap = new HashMap<>();
Map<String,Connection> connectionMap =new HashMap<>();
boolean isTransaction =false;
TransactionIsolationLevel level;
boolean autoCommit;
private boolean isTransaction = false;
private boolean autoCommit;
public FlexSpringTransaction(DataSource dataSource, TransactionIsolationLevel level,
boolean autoCommit) {
public FlexSpringTransaction(FlexDataSource dataSource, boolean autoCommit) {
this.dataSource = dataSource;
this.level = level;
this.autoCommit = autoCommit;
}
@Override
public Connection getConnection() throws SQLException {
if (dataSource instanceof FlexDataSource) {
String dataSourceKey = DataSourceKey.get();
if (StringUtil.isBlank(dataSourceKey)) {
dataSourceKey = ((FlexDataSource) dataSource).getDefaultDataSourceKey();
}
Connection connection = connectionMap.get(dataSourceKey);
if (connection == null){
connection = this.dataSource.getConnection();
connectionMap.put(dataSourceKey,connection);
}
this.autoCommit = connection.getAutoCommit();
if ( TransactionContext.getXID() != null){
isTransaction = true;
}
return connection;
}else{
throw new SQLException("The datasource must be FlexDataSource");
String dataSourceKey = DataSourceKey.get();
if (StringUtil.isBlank(dataSourceKey)) {
dataSourceKey = dataSource.getDefaultDataSourceKey();
}
Connection connection = connectionMap.get(dataSourceKey);
if (connection == null) {
connection = this.dataSource.getConnection();
connectionMap.put(dataSourceKey, connection);
}
this.autoCommit = connection.getAutoCommit();
if (TransactionContext.getXID() != null) {
this.isTransaction = true;
}
return connection;
}
@Override
public void commit() throws SQLException {
if (!isTransaction && !autoCommit){
if (!isTransaction && !autoCommit) {
getConnection().commit();
}
}
@Override
public void rollback() throws SQLException {
if (!isTransaction && !autoCommit){
if (!isTransaction && !autoCommit) {
getConnection().rollback();
}
}

View File

@ -15,14 +15,15 @@
*/
package com.mybatisflex.spring;
import java.sql.Connection;
import java.util.Properties;
import javax.sql.DataSource;
import com.mybatisflex.core.datasource.FlexDataSource;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.apache.ibatis.transaction.Transaction;
import org.mybatis.spring.transaction.SpringManagedTransaction;
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;
/**
* @author life
*/
@ -33,7 +34,7 @@ public class FlexTransactionFactory extends SpringManagedTransactionFactory {
*/
@Override
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
return new FlexSpringTransaction(dataSource,level,autoCommit);
return new FlexSpringTransaction((FlexDataSource) dataSource, autoCommit);
}
/**

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -4,7 +4,7 @@
<parent>
<artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId>
<version>1.5.5</version>
<version>1.5.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -7,7 +7,7 @@
<groupId>com.mybatis-flex</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.5.5</version>
<version>1.5.6</version>
<name>mybatis-flex</name>
<url>https://mybatis-flex.com</url>
@ -54,7 +54,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<mybatis-flex.version>1.5.5</mybatis-flex.version>
<mybatis-flex.version>1.5.6</mybatis-flex.version>
<mybatis.version>3.5.13</mybatis.version>
<mybatis-spring.version>2.1.0</mybatis-spring.version>