支持表级配置
This commit is contained in:
154
README.md
154
README.md
@@ -1,4 +1,5 @@
|
|||||||
# tape-mybatis-generator-plugin
|
# tape-mybatis-generator-plugin
|
||||||
|
|
||||||
> MyBatis 代码生成插件
|
> MyBatis 代码生成插件
|
||||||
|
|
||||||
## 功能特性
|
## 功能特性
|
||||||
@@ -12,17 +13,22 @@
|
|||||||
## 插件说明
|
## 插件说明
|
||||||
|
|
||||||
### TapeMybatisGeneratorPlugin
|
### TapeMybatisGeneratorPlugin
|
||||||
|
|
||||||
扩展 MyBatis Mapper,添加以下功能:
|
扩展 MyBatis Mapper,添加以下功能:
|
||||||
|
|
||||||
- 在 Mapper 接口中添加 `selectPrimaryKeyByExample` 方法
|
- 在 Mapper 接口中添加 `selectPrimaryKeyByExample` 方法
|
||||||
- 在 Mapper XML 中生成对应的 SQL 查询语句
|
- 在 Mapper XML 中生成对应的 SQL 查询语句
|
||||||
|
|
||||||
### TapeRepositoryGeneratorPlugin
|
### TapeRepositoryGeneratorPlugin
|
||||||
|
|
||||||
为非视图表生成 Repository 层代码:
|
为非视图表生成 Repository 层代码:
|
||||||
|
|
||||||
- **接口位置**: `{facadeRepositoryPackage}.I{TableName}Repository`
|
- **接口位置**: `{facadeRepositoryPackage}.I{TableName}Repository`
|
||||||
- **实现类位置**: `{domainRepositoryPackage}.{TableName}RepositoryImpl`
|
- **实现类位置**: `{domainRepositoryPackage}.{TableName}RepositoryImpl`
|
||||||
- **视图表过滤**: 根据 `viewKeyWords` 配置自动识别并跳过视图表
|
- **视图表过滤**: 根据 `viewKeyWords` 配置自动识别并跳过视图表
|
||||||
|
|
||||||
**生成的方法**:
|
**生成的方法**:
|
||||||
|
|
||||||
- `trashById(long id)` - 移动到回收站(单个)
|
- `trashById(long id)` - 移动到回收站(单个)
|
||||||
- `trashAll({Example} example)` - 移动到回收站(批量)
|
- `trashAll({Example} example)` - 移动到回收站(批量)
|
||||||
- `deleteById(long id, boolean release)` - 删除(单个,支持物理删除)
|
- `deleteById(long id, boolean release)` - 删除(单个,支持物理删除)
|
||||||
@@ -46,20 +52,25 @@
|
|||||||
- `update({Model} record)` - 更新记录(支持乐观锁)
|
- `update({Model} record)` - 更新记录(支持乐观锁)
|
||||||
|
|
||||||
### TapeRepoviewGeneratorPlugin
|
### TapeRepoviewGeneratorPlugin
|
||||||
|
|
||||||
为视图表生成 RepoView 层代码:
|
为视图表生成 RepoView 层代码:
|
||||||
|
|
||||||
- **接口位置**: `{facadeRepoviewPackage}.I{TableName}Repo`
|
- **接口位置**: `{facadeRepoviewPackage}.I{TableName}Repo`
|
||||||
- **实现类位置**: `{domainRepoviewPackage}.{TableName}RepoImpl`
|
- **实现类位置**: `{domainRepoviewPackage}.{TableName}RepoImpl`
|
||||||
- **视图表识别**: 仅处理包含 `viewKeyWords` 关键字的表
|
- **视图表识别**: 仅处理包含 `viewKeyWords` 关键字的表
|
||||||
|
|
||||||
**生成的方法**:
|
**生成的方法**:
|
||||||
|
|
||||||
- `findOne({Example} example)` - 查找单条记录
|
- `findOne({Example} example)` - 查找单条记录
|
||||||
- `getList({Example} example)` - 获取记录列表(支持分页)
|
- `getList({Example} example)` - 获取记录列表(支持分页)
|
||||||
- `count({Example} example)` - 统计记录数
|
- `count({Example} example)` - 统计记录数
|
||||||
|
|
||||||
### 其他功能
|
### 其他功能
|
||||||
|
|
||||||
通过 `TapeMybatisGeneratorPlugin` 为所有 Example 类添加支持:
|
通过 `TapeMybatisGeneratorPlugin` 为所有 Example 类添加支持:
|
||||||
|
|
||||||
**添加的字段**:
|
**添加的字段**:
|
||||||
|
|
||||||
- `offset` - 偏移量
|
- `offset` - 偏移量
|
||||||
- `rows` - 每页数量
|
- `rows` - 每页数量
|
||||||
- `startPageNum` - 最小页码(默认 1)
|
- `startPageNum` - 最小页码(默认 1)
|
||||||
@@ -68,6 +79,7 @@
|
|||||||
- `withBLOBs` - 是否返回BLOBs列的数据
|
- `withBLOBs` - 是否返回BLOBs列的数据
|
||||||
|
|
||||||
**添加的方法**:
|
**添加的方法**:
|
||||||
|
|
||||||
- `limit(int rows)` - 设置每页数量
|
- `limit(int rows)` - 设置每页数量
|
||||||
- `limit(int offset, int rows)` - 设置偏移量和每页数量
|
- `limit(int offset, int rows)` - 设置偏移量和每页数量
|
||||||
- `usePage(int pageNum, int pageSize)` - 使用页码和每页数量(自动计算 offset)
|
- `usePage(int pageNum, int pageSize)` - 使用页码和每页数量(自动计算 offset)
|
||||||
@@ -79,9 +91,11 @@
|
|||||||
- `getRows()` - 获取当前分页limit的rows
|
- `getRows()` - 获取当前分页limit的rows
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
|
|
||||||
### 1. 在 `pom.xml` 中配置插件
|
### 1. 在 `pom.xml` 中配置插件
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>application</finalName>
|
<finalName>application</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -162,29 +176,65 @@
|
|||||||
### 3. 配置参数说明
|
### 3. 配置参数说明
|
||||||
|
|
||||||
| 参数名 | 说明 | 默认值 | 必需 |
|
| 参数名 | 说明 | 默认值 | 必需 |
|
||||||
|--------------------------------|-------------------------------|---------------------------------------------------------|------|
|
|--------------------------------|-------------------------------|---------------------------------------------------------|----|
|
||||||
| `targetProject` | 生成代码的目标项目路径 | `src/main/java` | 否 |
|
| `targetProject` | 生成代码的目标项目路径 | `src/main/java` | 否 |
|
||||||
| `mapperPackage` | Mapper 接口的包路径 | `com.iqudoo.platform.application.database.mapper` | 是 |
|
| `mapperPackage` | Mapper 接口的包路径 | `com.iqudoo.platform.application.database.mapper` | 是 |
|
||||||
| `modelPackage` | Model 类的包路径 | `com.iqudoo.platform.application.database.model` | 是 |
|
| `modelPackage` | Model 类的包路径 | `com.iqudoo.platform.application.database.model` | 是 |
|
||||||
| `facadeRepositoryPackage` | Repository 接口的包路径 | `com.iqudoo.platform.application.facade.repository` | 否 |
|
| `facadeRepositoryPackage` | Repository 接口的包路径 | `com.iqudoo.platform.application.facade.repository` | 否 |
|
||||||
| `domainRepositoryPackage` | Repository 实现类的包路径 | `com.iqudoo.platform.application.domain.repository` | 否 |
|
| `domainRepositoryPackage` | Repository 实现类的包路径 | `com.iqudoo.platform.application.domain.repository` | 否 |
|
||||||
| `facadeViewRepositoryPackage` | RepoView 接口的包路径 | `com.iqudoo.platform.application.facade.repoview` | 否 |
|
| `facadeViewRepositoryPackage` | RepoView 接口的包路径 | `com.iqudoo.platform.application.facade.repoview` | 否 |
|
||||||
| `domainViewRepositoryPackage` | RepoView 实现类的包路径 | `com.iqudoo.platform.application.domain.repoview` | 否 |
|
| `domainViewRepositoryPackage` | RepoView 实现类的包路径 | `com.iqudoo.platform.application.domain.repoview` | 否 |
|
||||||
| `guidGeneratorClass` | GUID生成工具类 | `com.iqudoo.framework.tape.modules.utils.SnowflakeUtil` | 否 |
|
| `guidGeneratorClass` | GUID生成工具类 | `com.iqudoo.framework.tape.modules.utils.SnowflakeUtil` | 否 |
|
||||||
| `guidGeneratorCode` | GUID生成方法 | `SnowflakeUtil.nextId()` | 否 |
|
| `guidGeneratorCode` | GUID生成方法 | `SnowflakeUtil.nextId()` | 否 |
|
||||||
| `changeLogContextClassPackage` | 变更日志上下文包路径 | `com.iqudoo.platform.application.domain.changeLog` | 否 |
|
| `changeLogContextClassPackage` | 变更日志上下文包路径 | `com.iqudoo.platform.application.domain.changeLog` | 否 |
|
||||||
| `changeLogContextClassName` | 变更日志上下文类 | `ChangeLogContext` | 否 |
|
| `changeLogContextClassName` | 变更日志上下文类 | `ChangeLogContext` | 否 |
|
||||||
| `changeLogEnable` | 变更日志监听开关 | `false` | 否 |
|
| `changeLogEnable` | 变更日志监听开关 | `false` | 否 |
|
||||||
| `slowQueryLoggerTime` | 慢查询日志时间阈值 | `300` | 否 |
|
| `slowQueryLoggerTime` | 慢查询日志时间阈值 | `300` | 否 |
|
||||||
| `slowQueryLoggerLevel` | 慢查询日志类型:error,warn,debug,info | `error` | 否 |
|
| `slowQueryLoggerLevel` | 慢查询日志类型:error,warn,debug,info | `error` | 否 |
|
||||||
| `optimisticLockEnable` | 乐观锁开关 | `true` | 否 |
|
| `optimisticLockEnable` | 乐观锁开关 | `true` | 否 |
|
||||||
| `ignorePageSize` | 忽略分页阈值 | `10000` | 否 |
|
| `ignorePageSize` | 忽略分页阈值 | `10000` | 否 |
|
||||||
| `startPageNum` | 分页开始页码 | `1` | 否 |
|
| `startPageNum` | 分页开始页码 | `1` | 否 |
|
||||||
| `maxPageSize` | 最大每页数量 | `100` | 否 |
|
| `maxPageSize` | 最大每页数量 | `100` | 否 |
|
||||||
|
|
||||||
|
### 3. TABLE级配置,未配置时使用全局配置
|
||||||
|
|
||||||
|
| 参数名 |
|
||||||
|
|------------------------|
|
||||||
|
| `changeLogEnable` |
|
||||||
|
| `slowQueryLoggerTime` |
|
||||||
|
| `slowQueryLoggerLevel` |
|
||||||
|
| `optimisticLockEnable` |
|
||||||
|
| `ignorePageSize` |
|
||||||
|
| `startPageNum` |
|
||||||
|
| `maxPageSize` |
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<!-- your table -->
|
||||||
|
<table tableName="your table name"
|
||||||
|
domainObjectName="YourTableName"
|
||||||
|
enableInsert="true"
|
||||||
|
enableDeleteByPrimaryKey="true"
|
||||||
|
enableUpdateByPrimaryKey="true"
|
||||||
|
enableCountByExample="true"
|
||||||
|
enableUpdateByExample="true"
|
||||||
|
enableDeleteByExample="true"
|
||||||
|
enableSelectByExample="true"
|
||||||
|
selectByExampleQueryId="false">
|
||||||
|
<property name="useActualColumnNames" value="false"/>
|
||||||
|
<property name="changeLogEnable" value="false"/>
|
||||||
|
<property name="slowQueryLoggerTime" value="200"/>
|
||||||
|
<property name="slowQueryLoggerLevel" value="warn"/>
|
||||||
|
<property name="optimisticLockEnable" value="false"/>
|
||||||
|
<property name="ignorePageSize" value="10000"/>
|
||||||
|
<property name="startPageNum" value="1"/>
|
||||||
|
<property name="maxPageSize" value="100"/>
|
||||||
|
</table>
|
||||||
|
```
|
||||||
|
|
||||||
## 变更日志监听
|
## 变更日志监听
|
||||||
|
|
||||||
ChangeLogContext应该提供以下实现的静态方法,供Repository实现中调用
|
ChangeLogContext应该提供以下实现的静态方法,供Repository实现中调用
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class ChangeLogContext {
|
public class ChangeLogContext {
|
||||||
|
|
||||||
@@ -206,30 +256,33 @@ public class ChangeLogContext {
|
|||||||
|
|
||||||
```mysql
|
```mysql
|
||||||
DROP TABLE IF EXISTS `your_table_name`;
|
DROP TABLE IF EXISTS `your_table_name`;
|
||||||
CREATE TABLE `your_table_name` (
|
CREATE TABLE `your_table_name`
|
||||||
`guid` bigint(0) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'GUID',
|
(
|
||||||
-- ----------------------------
|
`guid` bigint(0) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'GUID',
|
||||||
-- add your table other table field
|
-- ----------------------------
|
||||||
-- ----------------------------
|
-- add your table other table field
|
||||||
`is_hidden` int(0) NOT NULL DEFAULT 0 COMMENT '隐藏标志',
|
-- ----------------------------
|
||||||
`is_delete` int(0) NOT NULL DEFAULT 0 COMMENT '删除标志',
|
`is_hidden` int(0) NOT NULL DEFAULT 0 COMMENT '隐藏标志',
|
||||||
`delete_token` varchar(32) NULL DEFAULT '' COMMENT '删除令牌',
|
`is_delete` int(0) NOT NULL DEFAULT 0 COMMENT '删除标志',
|
||||||
`data_version` int(0) NOT NULL DEFAULT 0 COMMENT '数据版本',
|
`delete_token` varchar(32) NULL DEFAULT '' COMMENT '删除令牌',
|
||||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
|
`data_version` int(0) NOT NULL DEFAULT 0 COMMENT '数据版本',
|
||||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '更新时间',
|
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
|
||||||
PRIMARY KEY (`guid`) USING BTREE,
|
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '更新时间',
|
||||||
-- UNIQUE KEY `idx_unique_key` (`you unique key`,`delete_token`) USING BTREE,
|
PRIMARY KEY (`guid`) USING BTREE,
|
||||||
-- KEY `idx_common_query` (
|
-- UNIQUE KEY `idx_unique_key` (`you unique key`,`delete_token`) USING BTREE,
|
||||||
-- 等值查询字段,
|
-- KEY `idx_common_query` (
|
||||||
-- `is_hidden`,`is_delete`,
|
-- 等值查询字段,
|
||||||
-- 其他参与排序字段,
|
-- `is_hidden`,`is_delete`,
|
||||||
-- `create_time` desc,
|
-- 其他参与排序字段,
|
||||||
-- `guid`) USING BTREE
|
-- `create_time` desc,
|
||||||
KEY `idx_common_query` (`is_hidden`,`is_delete`,`create_time` desc,`guid`) USING BTREE
|
-- `guid`) USING BTREE
|
||||||
) ENGINE = InnoDB COMMENT = '你的表格备注' ROW_FORMAT = Dynamic;
|
KEY `idx_common_query` (`is_hidden`, `is_delete`, `create_time` desc, `guid`) USING BTREE
|
||||||
|
) ENGINE = InnoDB COMMENT = '你的表格备注'
|
||||||
|
ROW_FORMAT = Dynamic;
|
||||||
```
|
```
|
||||||
|
|
||||||
**必需字段说明**:
|
**必需字段说明**:
|
||||||
|
|
||||||
- `guid` - 主键,类型为 `bigint UNSIGNED`
|
- `guid` - 主键,类型为 `bigint UNSIGNED`
|
||||||
- `is_hidden` - 隐藏标志,用于回收站功能
|
- `is_hidden` - 隐藏标志,用于回收站功能
|
||||||
- `is_delete` - 删除标志,用于软删除功能
|
- `is_delete` - 删除标志,用于软删除功能
|
||||||
@@ -258,31 +311,16 @@ CREATE TABLE `your_table_name` (
|
|||||||
selectByExampleQueryId="false">
|
selectByExampleQueryId="false">
|
||||||
<property name="useActualColumnNames" value="false"/>
|
<property name="useActualColumnNames" value="false"/>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<!-- 视图表配置(表名包含 VIEW_ 或 V_ 前缀,大小写不敏感) -->
|
|
||||||
<table tableName="v_your_view_name"
|
|
||||||
domainObjectName="ViewYourViewName"
|
|
||||||
enableInsert="false"
|
|
||||||
enableDeleteByPrimaryKey="false"
|
|
||||||
enableUpdateByPrimaryKey="false"
|
|
||||||
enableCountByExample="true"
|
|
||||||
enableUpdateByExample="false"
|
|
||||||
enableDeleteByExample="false"
|
|
||||||
enableSelectByExample="true"
|
|
||||||
selectByExampleQueryId="false">
|
|
||||||
<property name="useActualColumnNames" value="false"/>
|
|
||||||
<generatedKey column="guid" sqlStatement="JDBC" identity="false"/>
|
|
||||||
</table>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 注意事项
|
## 非视图表注意事项
|
||||||
|
|
||||||
1. **主键要求**:表必须有一个主键字段,且字段名为 `guid`,类型为 `bigint UNSIGNED`
|
1. **主键要求**:表必须有一个主键字段,且字段名为 `guid`,类型为 `bigint UNSIGNED`
|
||||||
2. **视图表识别**:视图表通过表名中的关键字识别,默认关键字为 `view_` 和 `v_` 不区分大小写
|
|
||||||
3. **分页功能**:所有 Example 类都自动包含分页功能,可通过 `usePage()` 方法使用
|
3. **分页功能**:所有 Example 类都自动包含分页功能,可通过 `usePage()` 方法使用
|
||||||
4. **乐观锁**:更新操作使用 `data_version` 字段实现乐观锁,更新时需要传入正确的版本号
|
4. **乐观锁**:更新操作使用 `data_version` 字段实现乐观锁,更新时需要传入正确的版本号
|
||||||
5. **软删除**:删除操作默认是软删除(设置 `is_delete` 标志),可通过 `release=true` 参数执行物理删除
|
5. **软删除**:删除操作默认是软删除(设置 `is_delete` 标志),可通过 `release=true` 参数执行物理删除
|
||||||
6. **回收站**:通过 `is_hidden` 字段实现回收站功能,`trash` 方法将记录移动到回收站,`recover` 方法恢复记录
|
6. **回收站**:通过 `is_hidden` 字段实现回收站功能,`trash` 方法将记录移动到回收站,`recover` 方法恢复记录
|
||||||
7. **自动字段**:插入记录时,插件会自动设置 `guid`(使用雪花算法)、`is_delete`、`is_hidden`、`delete_token`、`data_version`、`create_time`、`update_time` 等字段
|
7. **自动字段**:插入记录时,插件会自动设置 `guid`
|
||||||
|
(使用雪花算法)、`is_delete`、`is_hidden`、`delete_token`、`data_version`、`create_time`、`update_time` 等字段
|
||||||
8. **BLOB 字段支持**:如果表包含 BLOB 字段,插件会自动使用 `selectByExampleWithBLOBs` 和 `updateByExampleWithBLOBs` 方法
|
8. **BLOB 字段支持**:如果表包含 BLOB 字段,插件会自动使用 `selectByExampleWithBLOBs` 和 `updateByExampleWithBLOBs` 方法
|
||||||
9. **MyBatis Generator 版本**:本插件基于 MyBatis Generator 1.4.1 开发,建议使用 1.4.0 或更高版本
|
9. **MyBatis Generator 版本**:本插件基于 MyBatis Generator 1.4.1 开发,建议使用 1.4.0 或更高版本
|
||||||
Binary file not shown.
@@ -11,6 +11,7 @@ import org.mybatis.generator.api.dom.xml.Document;
|
|||||||
import org.mybatis.generator.api.dom.xml.TextElement;
|
import org.mybatis.generator.api.dom.xml.TextElement;
|
||||||
import org.mybatis.generator.api.dom.xml.XmlElement;
|
import org.mybatis.generator.api.dom.xml.XmlElement;
|
||||||
import org.mybatis.generator.config.Context;
|
import org.mybatis.generator.config.Context;
|
||||||
|
import org.mybatis.generator.config.TableConfiguration;
|
||||||
import org.mybatis.generator.internal.util.StringUtility;
|
import org.mybatis.generator.internal.util.StringUtility;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,6 +55,51 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getIgnorePageSize(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String getIgnorePageSize = tableConfiguration.getProperty("ignorePageSize");
|
||||||
|
if (getIgnorePageSize != null && !getIgnorePageSize.isEmpty()) {
|
||||||
|
int value = Integer.parseInt(getIgnorePageSize);
|
||||||
|
if (value > 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return ignorePageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxPageSize(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String getMaxPageSize = tableConfiguration.getProperty("maxPageSize");
|
||||||
|
if (getMaxPageSize != null && !getMaxPageSize.isEmpty()) {
|
||||||
|
int value = Integer.parseInt(getMaxPageSize);
|
||||||
|
if (value > 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return maxPageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartPageNum(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String getStartPageNum = tableConfiguration.getProperty("startPageNum");
|
||||||
|
if (getStartPageNum != null && !getStartPageNum.isEmpty()) {
|
||||||
|
int value = Integer.parseInt(getStartPageNum);
|
||||||
|
if (value > 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return startPageNum;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
@Override
|
@Override
|
||||||
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
||||||
@@ -65,7 +111,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
"maxPageSize",
|
"maxPageSize",
|
||||||
JavaVisibility.PROTECTED,
|
JavaVisibility.PROTECTED,
|
||||||
integerType,
|
integerType,
|
||||||
this.maxPageSize + ""
|
getMaxPageSize(introspectedTable) + ""
|
||||||
);
|
);
|
||||||
topLevelClass.addField(maxPageSizeField);
|
topLevelClass.addField(maxPageSizeField);
|
||||||
|
|
||||||
@@ -73,7 +119,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
"ignorePageSize",
|
"ignorePageSize",
|
||||||
JavaVisibility.PROTECTED,
|
JavaVisibility.PROTECTED,
|
||||||
integerType,
|
integerType,
|
||||||
this.ignorePageSize + ""
|
getIgnorePageSize(introspectedTable) + ""
|
||||||
);
|
);
|
||||||
topLevelClass.addField(ignorePageSizeField);
|
topLevelClass.addField(ignorePageSizeField);
|
||||||
|
|
||||||
@@ -81,7 +127,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
"startPageNum",
|
"startPageNum",
|
||||||
JavaVisibility.PROTECTED,
|
JavaVisibility.PROTECTED,
|
||||||
integerType,
|
integerType,
|
||||||
startPageNum + ""
|
getStartPageNum(introspectedTable) + ""
|
||||||
);
|
);
|
||||||
topLevelClass.addField(startPageNumField);
|
topLevelClass.addField(startPageNumField);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.mybatis.generator.api.*;
|
|||||||
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
|
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
|
||||||
import org.mybatis.generator.api.dom.java.*;
|
import org.mybatis.generator.api.dom.java.*;
|
||||||
import org.mybatis.generator.config.Context;
|
import org.mybatis.generator.config.Context;
|
||||||
|
import org.mybatis.generator.config.TableConfiguration;
|
||||||
import org.mybatis.generator.internal.util.StringUtility;
|
import org.mybatis.generator.internal.util.StringUtility;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -66,10 +67,19 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
modelPackage = stringConfig("modelPackage", modelPackage);
|
modelPackage = stringConfig("modelPackage", modelPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isChangeLogEnable() {
|
private boolean isChangeLogEnable(IntrospectedTable introspectedTable) {
|
||||||
|
String tableChangeLogEnable = changeLogEnable;
|
||||||
try {
|
try {
|
||||||
boolean b = Boolean.parseBoolean(changeLogEnable);
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
if (b && changeLogContextClassName != null && !changeLogContextClassName.isEmpty()) {
|
String getChangeLogEnable = tableConfiguration.getProperty("changeLogEnable");
|
||||||
|
if (getChangeLogEnable != null && !getChangeLogEnable.isEmpty()) {
|
||||||
|
tableChangeLogEnable = getChangeLogEnable;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boolean b = Boolean.parseBoolean(tableChangeLogEnable);
|
||||||
|
if (b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
@@ -77,9 +87,18 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOptimisticLockEnable() {
|
private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) {
|
||||||
|
String tableOptimisticLockEnable = optimisticLockEnable;
|
||||||
try {
|
try {
|
||||||
boolean b = Boolean.parseBoolean(optimisticLockEnable);
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String getOptimisticLockEnable = tableConfiguration.getProperty("optimisticLockEnable");
|
||||||
|
if (getOptimisticLockEnable != null && !getOptimisticLockEnable.isEmpty()) {
|
||||||
|
tableOptimisticLockEnable = getOptimisticLockEnable;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boolean b = Boolean.parseBoolean(tableOptimisticLockEnable);
|
||||||
if (b) {
|
if (b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -88,6 +107,30 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel");
|
||||||
|
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
|
||||||
|
return tableSlowQueryLoggerLevel;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return slowQueryLoggerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime");
|
||||||
|
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) {
|
||||||
|
return tableSlowQueryLoggerTime;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return slowQueryLoggerTime;
|
||||||
|
}
|
||||||
|
|
||||||
private String stringConfig(String key, String defaultValue) {
|
private String stringConfig(String key, String defaultValue) {
|
||||||
String v = properties.getProperty(key);
|
String v = properties.getProperty(key);
|
||||||
if (StringUtility.stringHasValue(v)) {
|
if (StringUtility.stringHasValue(v)) {
|
||||||
@@ -381,7 +424,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addAnnotation("@SuppressWarnings(\"DuplicatedCode\")");
|
implClass.addAnnotation("@SuppressWarnings(\"DuplicatedCode\")");
|
||||||
implClass.addAnnotation("@Repository");
|
implClass.addAnnotation("@Repository");
|
||||||
|
|
||||||
addImportPackages(implClass, modelClassName, exampleClassName, mapperClassName, interfaceName);
|
addImportPackages(implClass, introspectedTable, modelClassName, exampleClassName, mapperClassName, interfaceName);
|
||||||
|
|
||||||
FullyQualifiedJavaType superInterface = new FullyQualifiedJavaType(facadeRepositoryPackage + "." + interfaceName);
|
FullyQualifiedJavaType superInterface = new FullyQualifiedJavaType(facadeRepositoryPackage + "." + interfaceName);
|
||||||
implClass.addSuperInterface(superInterface);
|
implClass.addSuperInterface(superInterface);
|
||||||
@@ -404,23 +447,23 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
generateFindAnyByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
generateFindAnyByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
||||||
generateFindValidByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
generateFindValidByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
||||||
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
||||||
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
|
generateInsertMethod(implClass, introspectedTable, modelClassName, mapperFieldName);
|
||||||
generateBatchInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
|
generateBatchInsertMethod(implClass, introspectedTable, modelClassName, mapperFieldName);
|
||||||
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
generateUpdateMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
generateUpdateByExampleSelectiveMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateDeleteByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateDeleteByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateDeleteAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateTrashByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateTrashByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateTrashAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateTrashAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateRecoverByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateRecoverByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateRecoverAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateRecoverAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateFindValidOneMethod(implClass, modelClassName, exampleClassName);
|
generateFindValidOneMethod(implClass, modelClassName, exampleClassName);
|
||||||
generateFindTrashOneMethod(implClass, modelClassName, exampleClassName);
|
generateFindTrashOneMethod(implClass, modelClassName, exampleClassName);
|
||||||
generateGetValidListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
generateGetValidListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateGetTrashListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
generateGetTrashListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateCountByValidMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountByValidMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateCountByValidWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountByValidWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateCountByTrashMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountByTrashMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateCountByTrashWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountByTrashWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
||||||
|
|
||||||
return implClass;
|
return implClass;
|
||||||
@@ -469,9 +512,9 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addImportPackages(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperClassName, String interfaceName) {
|
private void addImportPackages(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperClassName, String interfaceName) {
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType(guidGeneratorClass));
|
implClass.addImportedType(new FullyQualifiedJavaType(guidGeneratorClass));
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType(changeLogContextClassPackage + "." + changeLogContextClassName));
|
implClass.addImportedType(new FullyQualifiedJavaType(changeLogContextClassPackage + "." + changeLogContextClassName));
|
||||||
}
|
}
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType(mapperPackage + "." + mapperClassName));
|
implClass.addImportedType(new FullyQualifiedJavaType(mapperPackage + "." + mapperClassName));
|
||||||
@@ -562,7 +605,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateInsertMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, IntrospectedTable introspectedTable) {
|
private void generateInsertMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String mapperFieldName) {
|
||||||
Method method = new Method("insert");
|
Method method = new Method("insert");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -601,8 +644,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int count = " + mapperFieldName + ".insert(aDo);");
|
method.addBodyLine("int count = " + mapperFieldName + ".insert(aDo);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] insert " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] insert " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
@@ -613,7 +656,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("record.setDataVersion(aDo.getDataVersion());");
|
method.addBodyLine("record.setDataVersion(aDo.getDataVersion());");
|
||||||
method.addBodyLine("record.setCreateTime(aDo.getCreateTime());");
|
method.addBodyLine("record.setCreateTime(aDo.getCreateTime());");
|
||||||
method.addBodyLine("record.setUpdateTime(aDo.getUpdateTime());");
|
method.addBodyLine("record.setUpdateTime(aDo.getUpdateTime());");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"insert\", aDo.getGuid(), new HashMap<>());");
|
method.addBodyLine(" \"insert\", aDo.getGuid(), new HashMap<>());");
|
||||||
}
|
}
|
||||||
@@ -623,7 +666,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateBatchInsertMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, IntrospectedTable introspectedTable) {
|
private void generateBatchInsertMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String mapperFieldName) {
|
||||||
Method method = new Method("batchInsert");
|
Method method = new Method("batchInsert");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -668,14 +711,14 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int count = " + mapperFieldName + ".batchInsert(batch);");
|
method.addBodyLine("int count = " + mapperFieldName + ".batchInsert(batch);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] batch insert " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] batch insert " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("if (count == batch.size()) {");
|
method.addBodyLine("if (count == batch.size()) {");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("for (" + modelClassName + " aDo : batch) {");
|
method.addBodyLine("for (" + modelClassName + " aDo : batch) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"batchInsert\", aDo.getGuid(), new HashMap<>());");
|
method.addBodyLine(" \"batchInsert\", aDo.getGuid(), new HashMap<>());");
|
||||||
@@ -688,8 +731,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateUpdateMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
private void generateUpdateMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
|
||||||
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("update");
|
Method method = new Method("update");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -702,7 +745,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (aDo == null || aDo.getIsDelete() == 1) {");
|
method.addBodyLine("if (aDo == null || aDo.getIsDelete() == 1) {");
|
||||||
method.addBodyLine("throw new Throwable(\"Record not found, " + modelClassName + " GUID:\" + record.getGuid());");
|
method.addBodyLine("throw new Throwable(\"Record not found, " + modelClassName + " GUID:\" + record.getGuid());");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("Map<String, Object[]> changeDiff = new HashMap<>();");
|
method.addBodyLine("Map<String, Object[]> changeDiff = new HashMap<>();");
|
||||||
}
|
}
|
||||||
for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
|
for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
|
||||||
@@ -715,7 +758,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
method.addBodyLine("if (record." + getterMethod + "() != null) {");
|
method.addBodyLine("if (record." + getterMethod + "() != null) {");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (!Objects.equals(record." + getterMethod + "(), aDo." + getterMethod + "())) {");
|
method.addBodyLine("if (!Objects.equals(record." + getterMethod + "(), aDo." + getterMethod + "())) {");
|
||||||
method.addBodyLine("changeDiff.put(\"" + fieldName + "\", new Object[]{aDo." + getterMethod + "(), record." + getterMethod + "()});");
|
method.addBodyLine("changeDiff.put(\"" + fieldName + "\", new Object[]{aDo." + getterMethod + "(), record." + getterMethod + "()});");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -724,7 +767,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
}
|
}
|
||||||
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
|
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
|
||||||
if (isOptimisticLockEnable()) {
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
|
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
|
||||||
method.addBodyLine("if (lockDataVersion == null) {");
|
method.addBodyLine("if (lockDataVersion == null) {");
|
||||||
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
|
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
|
||||||
@@ -746,13 +789,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
String updateMethod = hasBLOBColumns ? "updateByExampleWithBLOBs" : "updateByExample";
|
String updateMethod = hasBLOBColumns ? "updateByExampleWithBLOBs" : "updateByExample";
|
||||||
method.addBodyLine("int update = " + mapperFieldName + "." + updateMethod + "(aDo, updateWhere);");
|
method.addBodyLine("int update = " + mapperFieldName + "." + updateMethod + "(aDo, updateWhere);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] update " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] update " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0 && !changeDiff.isEmpty()) {");
|
method.addBodyLine("if (update > 0 && !changeDiff.isEmpty()) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"update\", aDo.getGuid(), changeDiff);");
|
method.addBodyLine(" \"update\", aDo.getGuid(), changeDiff);");
|
||||||
@@ -762,8 +805,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateUpdateByExampleSelectiveMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
private void generateUpdateByExampleSelectiveMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
|
||||||
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("updateByExampleSelective");
|
Method method = new Method("updateByExampleSelective");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -784,7 +827,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("example = new " + exampleClassName + "();");
|
method.addBodyLine("example = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
|
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
|
||||||
method.addBodyLine("List<" + modelClassName + "> recordList");
|
method.addBodyLine("List<" + modelClassName + "> recordList");
|
||||||
method.addBodyLine(" = " + mapperFieldName + "." + selectByExampleMethod + "(example);");
|
method.addBodyLine(" = " + mapperFieldName + "." + selectByExampleMethod + "(example);");
|
||||||
@@ -807,7 +850,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("diffGroup.put(aDo.getGuid(), changeDiff);");
|
method.addBodyLine("diffGroup.put(aDo.getGuid(), changeDiff);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
}
|
}
|
||||||
if (isOptimisticLockEnable()) {
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
method.addBodyLine("// reset data version, with optimistic locking");
|
method.addBodyLine("// reset data version, with optimistic locking");
|
||||||
method.addBodyLine("record.setDataVersion((int) (new Date().getTime() % 1000));");
|
method.addBodyLine("record.setDataVersion((int) (new Date().getTime() % 1000));");
|
||||||
}
|
}
|
||||||
@@ -821,18 +864,18 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(record, example);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(record, example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] updateByExampleSelective " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] updateByExampleSelective " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine("for (Map.Entry<Long, Map<String, Object[]>> diffEntry : diffGroup.entrySet()) {");
|
method.addBodyLine("for (Map.Entry<Long, Map<String, Object[]>> diffEntry : diffGroup.entrySet()) {");
|
||||||
method.addBodyLine("if (diffEntry.getValue() != null && !diffEntry.getValue().isEmpty()) {");
|
method.addBodyLine("if (diffEntry.getValue() != null && !diffEntry.getValue().isEmpty()) {");
|
||||||
@@ -846,7 +889,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDeleteByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateDeleteByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("deleteById");
|
Method method = new Method("deleteById");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -863,8 +906,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine(exampleClassName + " updateWhere");
|
method.addBodyLine(exampleClassName + " updateWhere");
|
||||||
method.addBodyLine(" = new " + exampleClassName + "();");
|
method.addBodyLine(" = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
if (isOptimisticLockEnable()) {
|
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
||||||
method.addBodyLine("updateWhere.createCriteria()");
|
method.addBodyLine("updateWhere.createCriteria()");
|
||||||
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
||||||
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
||||||
@@ -879,13 +922,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] deleteById " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] deleteById " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"deleteById\", aDo.getGuid(), new HashMap<>());");
|
method.addBodyLine(" \"deleteById\", aDo.getGuid(), new HashMap<>());");
|
||||||
@@ -895,7 +938,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTrashByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateTrashByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("trashById");
|
Method method = new Method("trashById");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -910,8 +953,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
|
|
||||||
method.addBodyLine(exampleClassName + " updateWhere");
|
method.addBodyLine(exampleClassName + " updateWhere");
|
||||||
method.addBodyLine(" = new " + exampleClassName + "();");
|
method.addBodyLine(" = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
if (isOptimisticLockEnable()) {
|
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
||||||
method.addBodyLine("updateWhere.createCriteria()");
|
method.addBodyLine("updateWhere.createCriteria()");
|
||||||
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
||||||
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
||||||
@@ -927,13 +970,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] trashById " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] trashById " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"trashById\", aDo.getGuid(), new HashMap<>());");
|
method.addBodyLine(" \"trashById\", aDo.getGuid(), new HashMap<>());");
|
||||||
@@ -943,7 +986,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRecoverByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateRecoverByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("recoverById");
|
Method method = new Method("recoverById");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -961,8 +1004,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
|
|
||||||
method.addBodyLine(exampleClassName + " updateWhere");
|
method.addBodyLine(exampleClassName + " updateWhere");
|
||||||
method.addBodyLine(" = new " + exampleClassName + "();");
|
method.addBodyLine(" = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
if (isOptimisticLockEnable()) {
|
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
|
||||||
method.addBodyLine("updateWhere.createCriteria()");
|
method.addBodyLine("updateWhere.createCriteria()");
|
||||||
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
||||||
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
||||||
@@ -977,13 +1020,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] recoverById " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] recoverById " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
method.addBodyLine(" \"recoverById\", aDo.getGuid(), new HashMap<>());");
|
method.addBodyLine(" \"recoverById\", aDo.getGuid(), new HashMap<>());");
|
||||||
@@ -993,7 +1036,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDeleteAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateDeleteAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("deleteAll");
|
Method method = new Method("deleteAll");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -1016,7 +1059,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("example = new " + exampleClassName + "();");
|
method.addBodyLine("example = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
||||||
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
||||||
if (isOptimisticLockEnable()) {
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
method.addBodyLine("// reset data version, with optimistic locking");
|
method.addBodyLine("// reset data version, with optimistic locking");
|
||||||
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
||||||
}
|
}
|
||||||
@@ -1026,13 +1069,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] deleteAll " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] deleteAll " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine("for (Long guid : guidList) {");
|
method.addBodyLine("for (Long guid : guidList) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
@@ -1044,7 +1087,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTrashAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateTrashAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("trashAll");
|
Method method = new Method("trashAll");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -1063,7 +1106,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("example = new " + exampleClassName + "();");
|
method.addBodyLine("example = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
||||||
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
||||||
if (isOptimisticLockEnable()) {
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
method.addBodyLine("// reset data version, with optimistic locking");
|
method.addBodyLine("// reset data version, with optimistic locking");
|
||||||
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
||||||
}
|
}
|
||||||
@@ -1074,13 +1117,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] trashAll " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] trashAll " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine("for (Long guid : guidList) {");
|
method.addBodyLine("for (Long guid : guidList) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
@@ -1092,7 +1135,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRecoverAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateRecoverAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("recoverAll");
|
Method method = new Method("recoverAll");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -1111,7 +1154,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("example = new " + exampleClassName + "();");
|
method.addBodyLine("example = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
|
||||||
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
|
||||||
if (isOptimisticLockEnable()) {
|
if (isOptimisticLockEnable(introspectedTable)) {
|
||||||
method.addBodyLine("// reset data version, with optimistic locking");
|
method.addBodyLine("// reset data version, with optimistic locking");
|
||||||
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
|
||||||
}
|
}
|
||||||
@@ -1122,13 +1165,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] recoverAll " + modelClassName + " long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] recoverAll " + modelClassName + " long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
method.addBodyLine(");");
|
method.addBodyLine(");");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable(introspectedTable)) {
|
||||||
method.addBodyLine("if (update > 0) {");
|
method.addBodyLine("if (update > 0) {");
|
||||||
method.addBodyLine("for (Long guid : guidList) {");
|
method.addBodyLine("for (Long guid : guidList) {");
|
||||||
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
|
||||||
@@ -1177,7 +1220,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateGetValidListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
private void generateGetValidListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
|
||||||
String mapperFieldName, boolean hasBLOBColumns) {
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("getValidList");
|
Method method = new Method("getValidList");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
@@ -1198,7 +1241,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("return new ArrayList<>();");
|
method.addBodyLine("return new ArrayList<>();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (findPrimaryKeyTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (findPrimaryKeyTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1209,7 +1252,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list primary key long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list primary key long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + findPrimaryKeyTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + findPrimaryKeyTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1233,7 +1276,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
||||||
}
|
}
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1244,7 +1287,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1254,7 +1297,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateGetTrashListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
private void generateGetTrashListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
|
||||||
String mapperFieldName, boolean hasBLOBColumns) {
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("getTrashList");
|
Method method = new Method("getTrashList");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
@@ -1275,7 +1318,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("return new ArrayList<>();");
|
method.addBodyLine("return new ArrayList<>();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (findPrimaryKeyTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (findPrimaryKeyTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1286,7 +1329,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list primary key long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list primary key long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + findPrimaryKeyTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + findPrimaryKeyTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1310,7 +1353,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
||||||
}
|
}
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1321,7 +1364,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1331,7 +1374,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateCountByValidMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateCountByValidMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("countByValid");
|
Method method = new Method("countByValid");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -1345,7 +1388,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1353,7 +1396,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid count long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid count long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1381,7 +1424,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateCountByTrashMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateCountByTrashMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("countByTrash");
|
Method method = new Method("countByTrash");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -1395,7 +1438,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -1403,7 +1446,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash count long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash count long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.mybatis.generator.api.PluginAdapter;
|
|||||||
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
|
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
|
||||||
import org.mybatis.generator.api.dom.java.*;
|
import org.mybatis.generator.api.dom.java.*;
|
||||||
import org.mybatis.generator.config.Context;
|
import org.mybatis.generator.config.Context;
|
||||||
|
import org.mybatis.generator.config.TableConfiguration;
|
||||||
import org.mybatis.generator.internal.util.StringUtility;
|
import org.mybatis.generator.internal.util.StringUtility;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -71,6 +72,30 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel");
|
||||||
|
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
|
||||||
|
return tableSlowQueryLoggerLevel;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return slowQueryLoggerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
|
||||||
|
try {
|
||||||
|
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
|
||||||
|
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime");
|
||||||
|
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) {
|
||||||
|
return tableSlowQueryLoggerTime;
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
return slowQueryLoggerTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 核心方法:仅为视图表生成 RepoView 代码
|
* 核心方法:仅为视图表生成 RepoView 代码
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +127,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
|
|
||||||
// 3. 生成视图Repo实现类
|
// 3. 生成视图Repo实现类
|
||||||
TopLevelClass repoImpl = generateRepoViewImpl(
|
TopLevelClass repoImpl = generateRepoViewImpl(
|
||||||
|
introspectedTable,
|
||||||
repoImplName,
|
repoImplName,
|
||||||
repoInterfaceName,
|
repoInterfaceName,
|
||||||
domainObjectName,
|
domainObjectName,
|
||||||
@@ -179,6 +205,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
* 生成视图Repo实现类(逻辑不变,仅适配新接口)
|
* 生成视图Repo实现类(逻辑不变,仅适配新接口)
|
||||||
*/
|
*/
|
||||||
private TopLevelClass generateRepoViewImpl(
|
private TopLevelClass generateRepoViewImpl(
|
||||||
|
IntrospectedTable introspectedTable,
|
||||||
String implClassName,
|
String implClassName,
|
||||||
String interfaceName,
|
String interfaceName,
|
||||||
String modelClassName,
|
String modelClassName,
|
||||||
@@ -215,8 +242,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addField(mapperField);
|
implClass.addField(mapperField);
|
||||||
|
|
||||||
generateFindOneMethod(implClass, modelClassName, exampleClassName);
|
generateFindOneMethod(implClass, modelClassName, exampleClassName);
|
||||||
generateGetListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
generateGetListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateCountMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateCountWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateCountWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
||||||
|
|
||||||
return implClass;
|
return implClass;
|
||||||
@@ -268,7 +295,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
/**
|
/**
|
||||||
* 生成getList方法
|
* 生成getList方法
|
||||||
*/
|
*/
|
||||||
private void generateGetListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName, boolean hasBLOBColumns) {
|
private void generateGetListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("getList");
|
Method method = new Method("getList");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -288,7 +315,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
|
||||||
}
|
}
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -299,7 +326,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " view list long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " view list long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -312,7 +339,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
/**
|
/**
|
||||||
* 生成count方法
|
* 生成count方法
|
||||||
*/
|
*/
|
||||||
private void generateCountMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateCountMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("count");
|
Method method = new Method("count");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
@@ -325,7 +352,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
|
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
|
||||||
method.addBodyLine("String exampleString = \"\";");
|
method.addBodyLine("String exampleString = \"\";");
|
||||||
method.addBodyLine("if (example.getWhereString() != null) {");
|
method.addBodyLine("if (example.getWhereString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
|
||||||
@@ -333,7 +360,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
method.addBodyLine("if (example.getOrderByClause() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " view count long time\" +");
|
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " view count long time\" +");
|
||||||
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
method.addBodyLine(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
|
|||||||
Reference in New Issue
Block a user