mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
f8efef2e18
33
changes.md
33
changes.md
@ -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:
|
## v1.5.5 20230801:
|
||||||
- 新增:添加对 xml 分页查询的支持
|
- 新增:添加对 xml 分页查询的支持
|
||||||
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
||||||
@ -43,7 +74,7 @@
|
|||||||
- 新增:多数据源功能添加负载均衡的能力
|
- 新增:多数据源功能添加负载均衡的能力
|
||||||
- 新增:QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
|
- 新增:QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
|
||||||
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
|
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
|
||||||
- 新增:添加异常信息国际哈的支持,感谢 @Suomm
|
- 新增:添加异常信息国际化的支持,感谢 @Suomm
|
||||||
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
|
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
|
||||||
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
|
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
|
||||||
- 新增:ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm
|
- 新增:ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm
|
||||||
|
|||||||
@ -81,3 +81,9 @@
|
|||||||
- [MyBatis-Flex 视频教程 - 27 version 乐观锁的简单使用](https://www.bilibili.com/video/BV1Rc411F7wp)
|
- [MyBatis-Flex 视频教程 - 27 version 乐观锁的简单使用](https://www.bilibili.com/video/BV1Rc411F7wp)
|
||||||
- [MyBatis-Flex 视频教程 - 28 tenantId 多租户的简单使用](https://www.bilibili.com/video/BV1eP41167TU)
|
- [MyBatis-Flex 视频教程 - 28 tenantId 多租户的简单使用](https://www.bilibili.com/video/BV1eP41167TU)
|
||||||
- [MyBatis-Flex 视频教程 - 29 typeHandler 的简单使用](https://www.bilibili.com/video/BV1B841127ea)
|
- [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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
## v1.5.5 20230801:
|
||||||
- 新增:添加对 xml 分页查询的支持
|
- 新增:添加对 xml 分页查询的支持
|
||||||
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
- 新增:逻辑删除添加列默认值为 null 值时的构建功能,感谢 @Suomm
|
||||||
@ -43,7 +74,7 @@
|
|||||||
- 新增:多数据源功能添加负载均衡的能力
|
- 新增:多数据源功能添加负载均衡的能力
|
||||||
- 新增:QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
|
- 新增:QueryWrapper 的.and() .or() 方法, 增加一个 condition 参数的方法,感谢 @jerryzhengsz
|
||||||
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
|
- 新增:添加 BaseMapper.selectOneWithRelationsByIdAs() 方法,感谢 @jerryzhengsz1
|
||||||
- 新增:添加异常信息国际哈的支持,感谢 @Suomm
|
- 新增:添加异常信息国际化的支持,感谢 @Suomm
|
||||||
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
|
- 新增:添加主键逻辑删除处理器的支持,感谢 @Suomm
|
||||||
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
|
- 新增:在 Service 中可以直接获取链式更新 UpdateChain 方法,感谢 @Suomm
|
||||||
- 新增:ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm
|
- 新增:ActiveRecord 添加 join 查询和 Relations 查询的功能,感谢 @Suomm
|
||||||
|
|||||||
@ -51,7 +51,7 @@ VALUES (1, '张三', 18, '2020-01-11'),
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
|
|||||||
@ -12,12 +12,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-core</artifactId>
|
<artifactId>mybatis-flex-core</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-processor</artifactId>
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
@ -28,12 +28,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-spring</artifactId>
|
<artifactId>mybatis-flex-spring</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-processor</artifactId>
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
``````
|
``````
|
||||||
@ -44,12 +44,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-processor</artifactId>
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
@ -70,7 +70,7 @@
|
|||||||
<path>
|
<path>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-processor</artifactId>
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -220,7 +220,7 @@ pom.xml 添加 `annotationProcessorPaths` 配置,
|
|||||||
```
|
```
|
||||||
dependencies {
|
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>'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-codegen</artifactId>
|
<artifactId>mybatis-flex-codegen</artifactId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认方言抽象类。
|
* 默认方言抽象类。
|
||||||
|
* @author michael
|
||||||
*/
|
*/
|
||||||
public abstract class JdbcDialect implements IDialect {
|
public abstract class JdbcDialect implements IDialect {
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ public abstract class JdbcDialect implements IDialect {
|
|||||||
Column column = new Column();
|
Column column = new Column();
|
||||||
column.setName(columnMetaData.getColumnName(i));
|
column.setName(columnMetaData.getColumnName(i));
|
||||||
|
|
||||||
|
column.setRawType(columnMetaData.getColumnTypeName(i));
|
||||||
|
column.setRawLength(columnMetaData.getColumnDisplaySize(i));
|
||||||
|
|
||||||
String jdbcType = columnMetaData.getColumnClassName(i);
|
String jdbcType = columnMetaData.getColumnClassName(i);
|
||||||
column.setPropertyType(JdbcTypeMapping.getType(jdbcType));
|
column.setPropertyType(JdbcTypeMapping.getType(jdbcType));
|
||||||
|
|
||||||
|
|||||||
@ -21,9 +21,7 @@ import com.mybatisflex.annotation.KeyType;
|
|||||||
import com.mybatisflex.codegen.config.ColumnConfig;
|
import com.mybatisflex.codegen.config.ColumnConfig;
|
||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,6 +69,16 @@ public class Column {
|
|||||||
*/
|
*/
|
||||||
private boolean needGenColumnAnnotation = false;
|
private boolean needGenColumnAnnotation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库的字段类型,比如 varchar/tinyint 等
|
||||||
|
*/
|
||||||
|
private String rawType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库中的字段长度,比如 varchar(32) 中的 32
|
||||||
|
*/
|
||||||
|
private int rawLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段配置。
|
* 字段配置。
|
||||||
*/
|
*/
|
||||||
@ -145,6 +153,22 @@ public class Column {
|
|||||||
isAutoIncrement = autoIncrement;
|
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() {
|
public ColumnConfig getColumnConfig() {
|
||||||
return columnConfig;
|
return columnConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -827,7 +827,7 @@ public interface BaseMapper<T> {
|
|||||||
((FunctionQueryColumn) selectColumns.get(0)).getFnName()
|
((FunctionQueryColumn) selectColumns.get(0)).getFnName()
|
||||||
)) {
|
)) {
|
||||||
// 第一个查询列不是 COUNT 函数,使用 COUNT(*) 替换所有的查询列
|
// 第一个查询列不是 COUNT 函数,使用 COUNT(*) 替换所有的查询列
|
||||||
queryWrapper.select(count());
|
CPI.setSelectColumns(queryWrapper, Collections.singletonList(count()));
|
||||||
}
|
}
|
||||||
// 第一个查询列是 COUNT 函数,可以使用 COUNT(1)、COUNT(列名) 代替默认的 COUNT(*)
|
// 第一个查询列是 COUNT 函数,可以使用 COUNT(1)、COUNT(列名) 代替默认的 COUNT(*)
|
||||||
objects = selectObjectListByQuery(queryWrapper);
|
objects = selectObjectListByQuery(queryWrapper);
|
||||||
@ -839,7 +839,7 @@ public interface BaseMapper<T> {
|
|||||||
objects = selectObjectListByQuery(MapperUtil.rawCountQueryWrapper(queryWrapper));
|
objects = selectObjectListByQuery(MapperUtil.rawCountQueryWrapper(queryWrapper));
|
||||||
} else {
|
} else {
|
||||||
// 使用 COUNT(*) 替换所有的查询列
|
// 使用 COUNT(*) 替换所有的查询列
|
||||||
queryWrapper.select(count());
|
CPI.setSelectColumns(queryWrapper, Collections.singletonList(count()));
|
||||||
objects = selectObjectListByQuery(queryWrapper);
|
objects = selectObjectListByQuery(queryWrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class FlexConsts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final String NAME = "MyBatis-Flex";
|
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";
|
public static final String DEFAULT_PRIMARY_FIELD = "id";
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
* 1、每台机器允许最大的并发量为 10w/s。
|
* 1、每台机器允许最大的并发量为 10w/s。
|
||||||
* 2、出现时间回拨,重启机器时,在时间回拨未恢复的情况下,可能出现 id 重复。
|
* 2、出现时间回拨,重启机器时,在时间回拨未恢复的情况下,可能出现 id 重复。
|
||||||
* <p>
|
* <p>
|
||||||
* ID组成:时间(7+)| 毫秒内的时间自增 (00~99:2)| 机器ID(0 ~ 9:1)| 随机数(000~999:3)用于分库分表时,通过 id 取模,保证分布均衡。
|
* ID组成:时间(7+)| 毫秒内的时间自增 (00~99:2)| 机器ID(00 ~ 99:2)| 随机数(00~99:2)用于分库分表时,通过 id 取模,保证分布均衡。
|
||||||
*/
|
*/
|
||||||
public class FlexIDKeyGenerator implements IKeyGenerator {
|
public class FlexIDKeyGenerator implements IKeyGenerator {
|
||||||
|
|
||||||
@ -85,12 +85,14 @@ public class FlexIDKeyGenerator implements IKeyGenerator {
|
|||||||
lastTimeMillis = currentTimeMillis;
|
lastTimeMillis = currentTimeMillis;
|
||||||
|
|
||||||
long diffTimeMillis = currentTimeMillis - INITIAL_TIMESTAMP;
|
long diffTimeMillis = currentTimeMillis - INITIAL_TIMESTAMP;
|
||||||
return diffTimeMillis * 1000000 + clockSeq * 10000 + workId * 1000 + getRandomInt();
|
|
||||||
|
//ID组成:时间(7+)| 毫秒内的时间自增 (00~99:2)| 机器ID(00 ~ 99:2)| 随机数(00~99:2)
|
||||||
|
return diffTimeMillis * 1000000 + clockSeq * 10000 + workId * 100 + getRandomInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int getRandomInt() {
|
private int getRandomInt() {
|
||||||
return ThreadLocalRandom.current().nextInt(1000);
|
return ThreadLocalRandom.current().nextInt(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -362,7 +362,9 @@ public class AccountSqlTester {
|
|||||||
@Test
|
@Test
|
||||||
public void testJoinSelf() {
|
public void testJoinSelf() {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.select()
|
.select(ACCOUNT.ALL_COLUMNS
|
||||||
|
// ,column("a0.xxxx").as("xxx")
|
||||||
|
)
|
||||||
.from(ACCOUNT).as("a0")
|
.from(ACCOUNT).as("a0")
|
||||||
.leftJoin(ACCOUNT).as("a1").on(ACCOUNT.ID.eq(ACCOUNT.AGE).and(ACCOUNT.USER_NAME.like("a")))
|
.leftJoin(ACCOUNT).as("a1").on(ACCOUNT.ID.eq(ACCOUNT.AGE).and(ACCOUNT.USER_NAME.like("a")))
|
||||||
.where(ACCOUNT.AGE.ge(10));
|
.where(ACCOUNT.AGE.ge(10));
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -19,74 +19,64 @@ import com.mybatisflex.core.datasource.DataSourceKey;
|
|||||||
import com.mybatisflex.core.datasource.FlexDataSource;
|
import com.mybatisflex.core.datasource.FlexDataSource;
|
||||||
import com.mybatisflex.core.transaction.TransactionContext;
|
import com.mybatisflex.core.transaction.TransactionContext;
|
||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
|
import org.apache.ibatis.transaction.Transaction;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
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
|
* @author life
|
||||||
*/
|
*/
|
||||||
public class FlexSpringTransaction implements Transaction {
|
public class FlexSpringTransaction implements Transaction {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FlexSpringTransaction.class);
|
private final FlexDataSource dataSource;
|
||||||
DataSource dataSource;
|
private final Map<String, Connection> connectionMap = new HashMap<>();
|
||||||
|
|
||||||
Map<String,Connection> connectionMap =new HashMap<>();
|
private boolean isTransaction = false;
|
||||||
|
private boolean autoCommit;
|
||||||
boolean isTransaction =false;
|
|
||||||
|
|
||||||
TransactionIsolationLevel level;
|
|
||||||
boolean autoCommit;
|
|
||||||
|
|
||||||
|
|
||||||
public FlexSpringTransaction(DataSource dataSource, TransactionIsolationLevel level,
|
public FlexSpringTransaction(FlexDataSource dataSource, boolean autoCommit) {
|
||||||
boolean autoCommit) {
|
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.level = level;
|
|
||||||
this.autoCommit = autoCommit;
|
this.autoCommit = autoCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
if (dataSource instanceof FlexDataSource) {
|
String dataSourceKey = DataSourceKey.get();
|
||||||
String dataSourceKey = DataSourceKey.get();
|
if (StringUtil.isBlank(dataSourceKey)) {
|
||||||
if (StringUtil.isBlank(dataSourceKey)) {
|
dataSourceKey = dataSource.getDefaultDataSourceKey();
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
if (!isTransaction && !autoCommit){
|
if (!isTransaction && !autoCommit) {
|
||||||
getConnection().commit();
|
getConnection().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
if (!isTransaction && !autoCommit){
|
if (!isTransaction && !autoCommit) {
|
||||||
getConnection().rollback();
|
getConnection().rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,14 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.mybatisflex.spring;
|
package com.mybatisflex.spring;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import com.mybatisflex.core.datasource.FlexDataSource;
|
||||||
import java.util.Properties;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import org.apache.ibatis.session.TransactionIsolationLevel;
|
import org.apache.ibatis.session.TransactionIsolationLevel;
|
||||||
import org.apache.ibatis.transaction.Transaction;
|
import org.apache.ibatis.transaction.Transaction;
|
||||||
import org.mybatis.spring.transaction.SpringManagedTransaction;
|
|
||||||
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
|
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author life
|
* @author life
|
||||||
*/
|
*/
|
||||||
@ -33,7 +34,7 @@ public class FlexTransactionFactory extends SpringManagedTransactionFactory {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
|
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
|
||||||
return new FlexSpringTransaction(dataSource,level,autoCommit);
|
return new FlexSpringTransaction((FlexDataSource) dataSource, autoCommit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mybatis-flex-test</artifactId>
|
<artifactId>mybatis-flex-test</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mybatis-flex-test</artifactId>
|
<artifactId>mybatis-flex-test</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mybatis-flex-test</artifactId>
|
<artifactId>mybatis-flex-test</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mybatis-flex-test</artifactId>
|
<artifactId>mybatis-flex-test</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>parent</artifactId>
|
<artifactId>parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.5.5</version>
|
<version>1.5.6</version>
|
||||||
|
|
||||||
<name>mybatis-flex</name>
|
<name>mybatis-flex</name>
|
||||||
<url>https://mybatis-flex.com</url>
|
<url>https://mybatis-flex.com</url>
|
||||||
@ -54,7 +54,7 @@
|
|||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<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.version>3.5.13</mybatis.version>
|
||||||
<mybatis-spring.version>2.1.0</mybatis-spring.version>
|
<mybatis-spring.version>2.1.0</mybatis-spring.version>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user