This commit is contained in:
iqudoo
2026-05-23 19:27:01 +08:00
parent 748ebad0c4
commit 88fa1c88dd
4 changed files with 226 additions and 278 deletions

View File

@@ -35,17 +35,11 @@
- `deleteAll({Example} example, boolean release)` - 删除(批量,支持物理删除) - `deleteAll({Example} example, boolean release)` - 删除(批量,支持物理删除)
- `recoverById(long id)` - 从回收站恢复(单个) - `recoverById(long id)` - 从回收站恢复(单个)
- `recoverAll({Example} example)` - 从回收站恢复(批量) - `recoverAll({Example} example)` - 从回收站恢复(批量)
- `findAnyById(long id)` - 查找(不区分有效/回收站) - `findById(long id)` - 根据主键查询数据
- `findValidById(long id)` - 查找有效记录(单个) - `findOne({Example} example)` - 查找单条数据
- `findTrashById(long id)` - 查找回收站记录(单个) - `getList({Example} example)` - 获取多条数据
- `findValidOne({Example} example)` - 查找有效记录(单个,支持条件) - `count({Example} example)` - 统计记录数
- `findTrashOne({Example} example)` - 查找回收站记录(单个,支持条件) - `countByWithPage({Example} example)` - 统计分页记录数
- `getValidList({Example} example)` - 获取有效记录列表(支持分页)
- `getTrashList({Example} example)` - 获取回收站记录列表(支持分页)
- `countByValid({Example} example)` - 统计有效记录数
- `countByValidWithPage({Example} example)` - 统计分页有效记录数
- `countByTrash({Example} example)` - 统计回收站记录数
- `countByTrashWithPage({Example} example)` - 统计分页回收站记录数
- `insert({Model} record)` - 插入记录(自动生成 GUID、设置默认值 - `insert({Model} record)` - 插入记录(自动生成 GUID、设置默认值
- `batchInsert(List<{Model}> records)` - 批量插入记录(自动生成 GUID、设置默认值 - `batchInsert(List<{Model}> records)` - 批量插入记录(自动生成 GUID、设置默认值
- `updateByExampleSelective({Model} record, {Example} example)` - 按条件更新记录 - `updateByExampleSelective({Model} record, {Example} example)` - 按条件更新记录
@@ -55,9 +49,8 @@
为视图表生成 RepoView 层代码: 为视图表生成 RepoView 层代码:
- **接口位置**: `{facadeRepoviewPackage}.I{TableName}Repo` - **接口位置**: `{facadeViewRepositoryPackage}.I{TableName}Repo`
- **实现类位置**: `{domainRepoviewPackage}.{TableName}RepoImpl` - **实现类位置**: `{domainViewRepositoryPackage}.{TableName}RepoImpl`
- **视图表识别**: 仅处理包含 `viewKeyWords` 关键字的表
**生成的方法** **生成的方法**
@@ -77,6 +70,7 @@
- `ignorePageSize` - 忽略分页数量(默认 10000每页数量大于10000时忽略分页 - `ignorePageSize` - 忽略分页数量(默认 10000每页数量大于10000时忽略分页
- `maxPageSize` - 最大每页数量(默认 100 - `maxPageSize` - 最大每页数量(默认 100
- `withBLOBs` - 是否返回BLOBs列的数据 - `withBLOBs` - 是否返回BLOBs列的数据
- `resultType` - 返回数据格式any, trash, valid默认
**添加的方法** **添加的方法**
@@ -85,6 +79,13 @@
- `usePage(int pageNum, int pageSize)` - 使用页码和每页数量(自动计算 offset - `usePage(int pageNum, int pageSize)` - 使用页码和每页数量(自动计算 offset
- `setWithBLOBs(boolean withBLOBs)` - 设置是否返回BLOBs列的数据 - `setWithBLOBs(boolean withBLOBs)` - 设置是否返回BLOBs列的数据
- `isWithBLOBs()` - 是否返回BLOBs列的数据 - `isWithBLOBs()` - 是否返回BLOBs列的数据
- `setResultType(String type)` - 设置返回值的类型
- `resultAny()` - 不区分
- `isResultAny()` - 查询不区分
- `resultTrash()` - 回收站
- `isResultTrash()` - 查询回收站
- `resultValid()` - 有效数据
- `isResultValid()` - 查询有效数据
- `getPageNum()` - 获取当前页码 - `getPageNum()` - 获取当前页码
- `getPageSize()` - 获取当前每页数量 - `getPageSize()` - 获取当前每页数量
- `getOffset()` - 获取当前分页limit的offset - `getOffset()` - 获取当前分页limit的offset

View File

@@ -101,6 +101,8 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
@Override @Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
topLevelClass.addImportedType(new FullyQualifiedJavaType("java.util.Objects"));
FullyQualifiedJavaType integerType = new FullyQualifiedJavaType("java.lang.Integer"); FullyQualifiedJavaType integerType = new FullyQualifiedJavaType("java.lang.Integer");
FullyQualifiedJavaType booleanType = new FullyQualifiedJavaType("java.lang.Boolean"); FullyQualifiedJavaType booleanType = new FullyQualifiedJavaType("java.lang.Boolean");
FullyQualifiedJavaType stringType = new FullyQualifiedJavaType("java.lang.String"); FullyQualifiedJavaType stringType = new FullyQualifiedJavaType("java.lang.String");
@@ -108,6 +110,18 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName(); String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
String exampleClassName = domainObjectName + "Example"; String exampleClassName = domainObjectName + "Example";
if (!ElementTools.isViewTable(introspectedTable)) {
// any, trash, valid
Field resultType = ElementTools.generateField(
"resultType",
JavaVisibility.PROTECTED,
stringType,
"null"
);
topLevelClass.addField(resultType);
}
// 添加 startPageNum、maxPageSize、ignorePageSize 字段 // 添加 startPageNum、maxPageSize、ignorePageSize 字段
Field maxPageSizeField = ElementTools.generateField( Field maxPageSizeField = ElementTools.generateField(
"maxPageSize", "maxPageSize",
@@ -188,6 +202,99 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
Method mGetStartPageNum = ElementTools.generateGetterMethod(startPageNumField); Method mGetStartPageNum = ElementTools.generateGetterMethod(startPageNumField);
FormatTools.addMethodWithBestPosition(topLevelClass, mGetStartPageNum); FormatTools.addMethodWithBestPosition(topLevelClass, mGetStartPageNum);
if (!ElementTools.isViewTable(introspectedTable)) {
// setResultType
Method setResultType = ElementTools.generateMethod(
"setResultType",
JavaVisibility.PUBLIC,
topLevelClass.getType(),
new Parameter(stringType, "type")
);
setResultType = ElementTools.generateMethodBody(
setResultType,
"this.resultType = type;",
"return this;"
);
FormatTools.addMethodWithBestPosition(topLevelClass, setResultType);
// resultValid
Method resultValid = ElementTools.generateMethod(
"resultValid",
JavaVisibility.PUBLIC,
topLevelClass.getType()
);
resultValid = ElementTools.generateMethodBody(
resultValid,
"this.resultType = \"valid\";",
"return this;"
);
FormatTools.addMethodWithBestPosition(topLevelClass, resultValid);
// isResultValid
Method isResultValid = ElementTools.generateMethod(
"isResultValid",
JavaVisibility.PUBLIC,
booleanType
);
isResultValid = ElementTools.generateMethodBody(
isResultValid,
"return !this.isResultAny() && !this.isResultTrash();"
);
FormatTools.addMethodWithBestPosition(topLevelClass, isResultValid);
// resultTrash
Method resultTrash = ElementTools.generateMethod(
"resultTrash",
JavaVisibility.PUBLIC,
topLevelClass.getType()
);
resultTrash = ElementTools.generateMethodBody(
resultTrash,
"this.resultType = \"trash\";",
"return this;"
);
FormatTools.addMethodWithBestPosition(topLevelClass, resultTrash);
// isResultTrash
Method isResultTrash = ElementTools.generateMethod(
"isResultTrash",
JavaVisibility.PUBLIC,
booleanType
);
isResultTrash = ElementTools.generateMethodBody(
isResultTrash,
"return Objects.equals(this.resultType, \"trash\");"
);
FormatTools.addMethodWithBestPosition(topLevelClass, isResultTrash);
// resultAny
Method resultAny = ElementTools.generateMethod(
"resultAny",
JavaVisibility.PUBLIC,
topLevelClass.getType()
);
resultAny = ElementTools.generateMethodBody(
resultAny,
"this.resultType = \"any\";",
"return this;"
);
FormatTools.addMethodWithBestPosition(topLevelClass, resultAny);
// isResultAny
Method isResultAny = ElementTools.generateMethod(
"isResultAny",
JavaVisibility.PUBLIC,
booleanType
);
isResultAny = ElementTools.generateMethodBody(
isResultAny,
"return Objects.equals(this.resultType, \"any\");"
);
FormatTools.addMethodWithBestPosition(topLevelClass, isResultAny);
}
// 提供几个快捷方法 // 提供几个快捷方法
Method setLimitByRows = ElementTools.generateMethod( Method setLimitByRows = ElementTools.generateMethod(
"limit", "limit",
@@ -203,6 +310,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByRows); FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByRows);
// setLimitByOffsetRows
Method setLimitByOffsetRows = ElementTools.generateMethod( Method setLimitByOffsetRows = ElementTools.generateMethod(
"limit", "limit",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -218,6 +326,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetRows); FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetRows);
// limitOffset
Method setLimitByOffsetOnly = ElementTools.generateMethod( Method setLimitByOffsetOnly = ElementTools.generateMethod(
"limitOffset", "limitOffset",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -233,6 +342,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetOnly); FormatTools.addMethodWithBestPosition(topLevelClass, setLimitByOffsetOnly);
// usePage
Method usePage = ElementTools.generateMethod( Method usePage = ElementTools.generateMethod(
"usePage", "usePage",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -256,7 +366,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, usePage); FormatTools.addMethodWithBestPosition(topLevelClass, usePage);
// 计算获取当前页码 // getPageNum 计算获取当前页码
Method getPageNum = ElementTools.generateMethod( Method getPageNum = ElementTools.generateMethod(
"getPageNum", "getPageNum",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -270,7 +380,8 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
"return this.offset / this.rows + this.startPageNum;" "return this.offset / this.rows + this.startPageNum;"
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getPageNum); FormatTools.addMethodWithBestPosition(topLevelClass, getPageNum);
// 计算获取当前每页数量
// getPageSize 计算获取当前每页数量
Method getPageSize = ElementTools.generateMethod( Method getPageSize = ElementTools.generateMethod(
"getPageSize", "getPageSize",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -285,6 +396,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getPageSize); FormatTools.addMethodWithBestPosition(topLevelClass, getPageSize);
// getRows
Method getRows = ElementTools.generateMethod( Method getRows = ElementTools.generateMethod(
"getRows", "getRows",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -296,6 +408,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getRows); FormatTools.addMethodWithBestPosition(topLevelClass, getRows);
// getOffset
Method getOffset = ElementTools.generateMethod( Method getOffset = ElementTools.generateMethod(
"getOffset", "getOffset",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -307,6 +420,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getOffset); FormatTools.addMethodWithBestPosition(topLevelClass, getOffset);
// getLimitString
Method getLimitString = ElementTools.generateMethod( Method getLimitString = ElementTools.generateMethod(
"getLimitString", "getLimitString",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -325,6 +439,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getLimitString); FormatTools.addMethodWithBestPosition(topLevelClass, getLimitString);
// getWhereString
Method getWhereString = ElementTools.generateMethod( Method getWhereString = ElementTools.generateMethod(
"getWhereString", "getWhereString",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -360,6 +475,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
); );
FormatTools.addMethodWithBestPosition(topLevelClass, getWhereString); FormatTools.addMethodWithBestPosition(topLevelClass, getWhereString);
// cloneExample
Method cloneExample = ElementTools.generateMethod( Method cloneExample = ElementTools.generateMethod(
"cloneExample", "cloneExample",
JavaVisibility.PUBLIC, JavaVisibility.PUBLIC,
@@ -372,7 +488,8 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
"newExample.offset = this.offset;", "newExample.offset = this.offset;",
"newExample.maxPageSize = this.maxPageSize;", "newExample.maxPageSize = this.maxPageSize;",
"newExample.ignorePageSize = this.ignorePageSize;", "newExample.ignorePageSize = this.ignorePageSize;",
"newExample.startPageNum = startPageNum;", "newExample.startPageNum = this.startPageNum;",
!ElementTools.isViewTable(introspectedTable) ? "newExample.resultType = this.resultType;" : "",
hasBLOBColumns ? "newExample.withBLOBs = withBLOBs;" : "", hasBLOBColumns ? "newExample.withBLOBs = withBLOBs;" : "",
"if (this.getOredCriteria() != null && !this.getOredCriteria().isEmpty()) {", "if (this.getOredCriteria() != null && !this.getOredCriteria().isEmpty()) {",
"for (" + exampleClassName + ".Criteria oldCriteria : this.getOredCriteria()) {", "for (" + exampleClassName + ".Criteria oldCriteria : this.getOredCriteria()) {",
@@ -392,6 +509,9 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
if (method.getName().equals("clear")) { if (method.getName().equals("clear")) {
method.addBodyLine("rows = null;"); method.addBodyLine("rows = null;");
method.addBodyLine("offset = null;"); method.addBodyLine("offset = null;");
if (!ElementTools.isViewTable(introspectedTable)) {
method.addBodyLine("resultType = null;");
}
hasClear = true; hasClear = true;
} }
} }
@@ -404,7 +524,8 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
clear = ElementTools.generateMethodBody( clear = ElementTools.generateMethodBody(
clear, clear,
"rows = null;", "rows = null;",
"offset = null;" "offset = null;",
!ElementTools.isViewTable(introspectedTable) ? "resultType = null;" : ""
); );
FormatTools.addMethodWithBestPosition(topLevelClass, clear); FormatTools.addMethodWithBestPosition(topLevelClass, clear);
} }
@@ -464,9 +585,6 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
batchInsert.setVisibility(JavaVisibility.PUBLIC); batchInsert.setVisibility(JavaVisibility.PUBLIC);
batchInsert.setReturnType(FullyQualifiedJavaType.getIntInstance()); batchInsert.setReturnType(FullyQualifiedJavaType.getIntInstance());
batchInsert.addParameter(recordsParam); batchInsert.addParameter(recordsParam);
interfaceObj.addImportedType(new FullyQualifiedJavaType("java.util.List"));
interfaceObj.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param"));
interfaceObj.addMethod(batchInsert); interfaceObj.addMethod(batchInsert);
} }
@@ -512,8 +630,12 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
if (introspectedTable.getTargetRuntime() != IntrospectedTable.TargetRuntime.MYBATIS3) { if (introspectedTable.getTargetRuntime() != IntrospectedTable.TargetRuntime.MYBATIS3) {
return super.clientGenerated(interfaceObj, introspectedTable); return super.clientGenerated(interfaceObj, introspectedTable);
} }
interfaceObj.addImportedType(new FullyQualifiedJavaType("java.util.List"));
interfaceObj.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Param"));
addBatchInsertClientMethod(interfaceObj, introspectedTable); addBatchInsertClientMethod(interfaceObj, introspectedTable);
if (introspectedTable.getPrimaryKeyColumns().size() <= 0) {
if (introspectedTable.getPrimaryKeyColumns().isEmpty()) {
return super.clientGenerated(interfaceObj, introspectedTable); return super.clientGenerated(interfaceObj, introspectedTable);
} }
// 获取主键列类型 // 获取主键列类型

View File

@@ -254,7 +254,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
findAnyByIdMethod.setAbstract(true); findAnyByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findAnyByIdMethod); repositoryInterface.addMethod(findAnyByIdMethod);
// 8. findValidById // 7. findValidById
Method findValidByIdMethod = new Method("findValidById"); Method findValidByIdMethod = new Method("findValidById");
findValidByIdMethod.setVisibility(JavaVisibility.PUBLIC); findValidByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findValidByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName)); findValidByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -263,7 +263,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
findValidByIdMethod.setAbstract(true); findValidByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findValidByIdMethod); repositoryInterface.addMethod(findValidByIdMethod);
// 9. findTrashById // 7. findTrashById
Method findTrashByIdMethod = new Method("findTrashById"); Method findTrashByIdMethod = new Method("findTrashById");
findTrashByIdMethod.setVisibility(JavaVisibility.PUBLIC); findTrashByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findTrashByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName)); findTrashByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -272,79 +272,43 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
findTrashByIdMethod.setAbstract(true); findTrashByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findTrashByIdMethod); repositoryInterface.addMethod(findTrashByIdMethod);
// 10. findValidOne // 8. findOne
Method findValidOneMethod = new Method("findValidOne"); Method findOneMethod = new Method("findOne");
findValidOneMethod.setVisibility(JavaVisibility.PUBLIC); findOneMethod.setVisibility(JavaVisibility.PUBLIC);
findValidOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName)); findOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findValidOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example")); findOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
findValidOneMethod.addException(new FullyQualifiedJavaType("Throwable")); findOneMethod.addException(new FullyQualifiedJavaType("Throwable"));
findValidOneMethod.setAbstract(true); findOneMethod.setAbstract(true);
repositoryInterface.addMethod(findValidOneMethod); repositoryInterface.addMethod(findOneMethod);
// 11. findTrashOne // 9. getList
Method findTrashOneMethod = new Method("findTrashOne"); Method getListMethod = new Method("getList");
findTrashOneMethod.setVisibility(JavaVisibility.PUBLIC); getListMethod.setVisibility(JavaVisibility.PUBLIC);
findTrashOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName)); getListMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
findTrashOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example")); getListMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
findTrashOneMethod.addException(new FullyQualifiedJavaType("Throwable")); getListMethod.addException(new FullyQualifiedJavaType("Throwable"));
findTrashOneMethod.setAbstract(true); getListMethod.setAbstract(true);
repositoryInterface.addMethod(findTrashOneMethod); repositoryInterface.addMethod(getListMethod);
// 12. getValidList // 10. count
Method getValidListMethod = new Method("getValidList"); Method countMethod = new Method("count");
getValidListMethod.setVisibility(JavaVisibility.PUBLIC); countMethod.setVisibility(JavaVisibility.PUBLIC);
getValidListMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">")); countMethod.setReturnType(new FullyQualifiedJavaType("long"));
getValidListMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example")); countMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
getValidListMethod.addException(new FullyQualifiedJavaType("Throwable")); countMethod.addException(new FullyQualifiedJavaType("Throwable"));
getValidListMethod.setAbstract(true); countMethod.setAbstract(true);
repositoryInterface.addMethod(getValidListMethod); repositoryInterface.addMethod(countMethod);
// 13. getTrashList // 11. countWithPage
Method getTrashListMethod = new Method("getTrashList"); Method countWithPageMethod = new Method("countWithPage");
getTrashListMethod.setVisibility(JavaVisibility.PUBLIC); countWithPageMethod.setVisibility(JavaVisibility.PUBLIC);
getTrashListMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">")); countWithPageMethod.setReturnType(new FullyQualifiedJavaType("long"));
getTrashListMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example")); countWithPageMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
getTrashListMethod.addException(new FullyQualifiedJavaType("Throwable")); countWithPageMethod.addException(new FullyQualifiedJavaType("Throwable"));
getTrashListMethod.setAbstract(true); countWithPageMethod.setAbstract(true);
repositoryInterface.addMethod(getTrashListMethod); repositoryInterface.addMethod(countWithPageMethod);
// 14. countByValid // 12. insert
Method countByValidMethod = new Method("countByValid");
countByValidMethod.setVisibility(JavaVisibility.PUBLIC);
countByValidMethod.setReturnType(new FullyQualifiedJavaType("long"));
countByValidMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
countByValidMethod.addException(new FullyQualifiedJavaType("Throwable"));
countByValidMethod.setAbstract(true);
repositoryInterface.addMethod(countByValidMethod);
// 15. countByValidWithPage
Method countByValidWithPageMethod = new Method("countByValidWithPage");
countByValidWithPageMethod.setVisibility(JavaVisibility.PUBLIC);
countByValidWithPageMethod.setReturnType(new FullyQualifiedJavaType("long"));
countByValidWithPageMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
countByValidWithPageMethod.addException(new FullyQualifiedJavaType("Throwable"));
countByValidWithPageMethod.setAbstract(true);
repositoryInterface.addMethod(countByValidWithPageMethod);
// 16. countByTrash
Method countByTrashMethod = new Method("countByTrash");
countByTrashMethod.setVisibility(JavaVisibility.PUBLIC);
countByTrashMethod.setReturnType(new FullyQualifiedJavaType("long"));
countByTrashMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
countByTrashMethod.addException(new FullyQualifiedJavaType("Throwable"));
countByTrashMethod.setAbstract(true);
repositoryInterface.addMethod(countByTrashMethod);
// 17. countByTrashWithPage
Method countByTrashWithPageMethod = new Method("countByTrashWithPage");
countByTrashWithPageMethod.setVisibility(JavaVisibility.PUBLIC);
countByTrashWithPageMethod.setReturnType(new FullyQualifiedJavaType("long"));
countByTrashWithPageMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
countByTrashWithPageMethod.addException(new FullyQualifiedJavaType("Throwable"));
countByTrashWithPageMethod.setAbstract(true);
repositoryInterface.addMethod(countByTrashWithPageMethod);
// 18. insert
Method insertMethod = new Method("insert"); Method insertMethod = new Method("insert");
insertMethod.setVisibility(JavaVisibility.PUBLIC); insertMethod.setVisibility(JavaVisibility.PUBLIC);
insertMethod.setReturnType(new FullyQualifiedJavaType(modelClassName)); insertMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -353,7 +317,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
insertMethod.setAbstract(true); insertMethod.setAbstract(true);
repositoryInterface.addMethod(insertMethod); repositoryInterface.addMethod(insertMethod);
// 19. batchInsert // 13. batchInsert
Method batchInsertMethod = new Method("batchInsert"); Method batchInsertMethod = new Method("batchInsert");
batchInsertMethod.setVisibility(JavaVisibility.PUBLIC); batchInsertMethod.setVisibility(JavaVisibility.PUBLIC);
batchInsertMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">")); batchInsertMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
@@ -362,7 +326,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
batchInsertMethod.setAbstract(true); batchInsertMethod.setAbstract(true);
repositoryInterface.addMethod(batchInsertMethod); repositoryInterface.addMethod(batchInsertMethod);
// 20. update // 14. update
Method updateMethod = new Method("update"); Method updateMethod = new Method("update");
updateMethod.setVisibility(JavaVisibility.PUBLIC); updateMethod.setVisibility(JavaVisibility.PUBLIC);
updateMethod.setReturnType(new FullyQualifiedJavaType("int")); updateMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -371,7 +335,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
updateMethod.setAbstract(true); updateMethod.setAbstract(true);
repositoryInterface.addMethod(updateMethod); repositoryInterface.addMethod(updateMethod);
// 21. updateByExampleSelective // 15. updateByExampleSelective
Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective"); Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective");
updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC); updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC);
updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int")); updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -436,14 +400,10 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
generateTrashAllMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName); generateTrashAllMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateRecoverByIdMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName); generateRecoverByIdMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateRecoverAllMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName); generateRecoverAllMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateFindValidOneMethod(implClass, tableName, modelClassName, exampleClassName); generateFindOneMethod(implClass, tableName, modelClassName, exampleClassName);
generateFindTrashOneMethod(implClass, tableName, modelClassName, exampleClassName); generateGetListMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateGetValidListMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns); generateCountMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateGetTrashListMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns); generateCountWithPageMethod(implClass, tableName, modelClassName, exampleClassName, mapperFieldName);
generateCountByValidMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountByValidWithPageMethod(implClass, tableName, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashMethod(implClass, tableName, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashWithPageMethod(implClass, tableName, modelClassName, exampleClassName, mapperFieldName);
return implClass; return implClass;
} }
@@ -877,7 +837,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id")); method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("boolean"), "release")); method.addParameter(new Parameter(new FullyQualifiedJavaType("boolean"), "release"));
method.addException(new FullyQualifiedJavaType("Throwable")); method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findValidById(id);"); method.addBodyLine(modelClassName + " aDo = findAnyById(id);");
method.addBodyLine("if (aDo == null) {"); method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;"); method.addBodyLine("return 0;");
method.addBodyLine("}"); method.addBodyLine("}");
@@ -927,10 +887,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id")); method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addException(new FullyQualifiedJavaType("Throwable")); method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findValidById(id);"); method.addBodyLine(modelClassName + " aDo = findAnyById(id);");
method.addBodyLine("if (aDo == null) {"); method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;"); method.addBodyLine("return 0;");
method.addBodyLine("}"); method.addBodyLine("}");
method.addBodyLine("if (aDo.getIsHidden() == 1) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine(exampleClassName + " updateWhere"); method.addBodyLine(exampleClassName + " updateWhere");
method.addBodyLine(" = new " + exampleClassName + "();"); method.addBodyLine(" = new " + exampleClassName + "();");
@@ -976,11 +939,11 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id")); method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addException(new FullyQualifiedJavaType("Throwable")); method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findTrashById(id);"); method.addBodyLine(modelClassName + " aDo = findAnyById(id);");
method.addBodyLine("if (aDo == null) {"); method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;"); method.addBodyLine("return 0;");
method.addBodyLine("}"); method.addBodyLine("}");
method.addBodyLine("if (aDo.getIsDelete() == 1) {"); method.addBodyLine("if (aDo.getIsHidden() == 0) {");
method.addBodyLine("return 0;"); method.addBodyLine("return 0;");
method.addBodyLine("}"); method.addBodyLine("}");
@@ -1176,8 +1139,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method); implClass.addMethod(method);
} }
private void generateFindValidOneMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName) { private void generateFindOneMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName) {
Method method = new Method("findValidOne"); Method method = new Method("findOne");
method.addAnnotation("@Override"); method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC); method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName)); method.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -1187,7 +1150,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("// clone new example"); method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();"); method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("example.usePage(1, 1);"); method.addBodyLine("example.usePage(1, 1);");
method.addBodyLine("List<" + modelClassName + "> dataList = getValidList(example);"); method.addBodyLine("List<" + modelClassName + "> dataList = getList(example);");
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {"); method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
method.addBodyLine("return dataList.get(0);"); method.addBodyLine("return dataList.get(0);");
method.addBodyLine("}"); method.addBodyLine("}");
@@ -1196,29 +1159,9 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method); implClass.addMethod(method);
} }
private void generateFindTrashOneMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName) { private void generateGetListMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
Method method = new Method("findTrashOne"); String mapperFieldName, boolean hasBLOBColumns) {
method.addAnnotation("@Override"); Method method = new Method("getList");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("example.usePage(1, 1);");
method.addBodyLine("List<" + modelClassName + "> dataList = getTrashList(example);");
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
method.addBodyLine("return dataList.get(0);");
method.addBodyLine("}");
method.addBodyLine("return null;");
implClass.addMethod(method);
}
private void generateGetValidListMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getValidList");
method.addAnnotation("@Override"); method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC); method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">")); method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
@@ -1228,7 +1171,15 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("// clone new example"); method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();"); method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {"); method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);"); method.addBodyLine("if (example.isResultTrash()) {");
method.addBodyLine("criteria.andIsHiddenEqualTo(1)");
method.addBodyLine(" .andIsDeleteEqualTo(0);");
method.addBodyLine("} else if (example.isResultValid()) {");
method.addBodyLine("criteria.andIsHiddenEqualTo(0)");
method.addBodyLine(" .andIsDeleteEqualTo(0);");
method.addBodyLine("} else {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("}"); method.addBodyLine("}");
method.addBodyLine("List<" + modelClassName + "> result = null;"); method.addBodyLine("List<" + modelClassName + "> result = null;");
method.addBodyLine("long startTime = new Date().getTime();"); method.addBodyLine("long startTime = new Date().getTime();");
@@ -1250,7 +1201,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." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list primary key long time\" +"); method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " list primary key long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +"); method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + findPrimaryKeyTime + \"ms\" +"); method.addBodyLine(" \"\\n\\t|-> use time: \" + findPrimaryKeyTime + \"ms\" +");
method.addBodyLine(" exampleString +"); method.addBodyLine(" exampleString +");
@@ -1286,7 +1237,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." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list long time\" +"); method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " list long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +"); method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +"); method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +"); method.addBodyLine(" exampleString +");
@@ -1297,89 +1248,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method); implClass.addMethod(method);
} }
private void generateGetTrashListMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, private void generateCountMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
String mapperFieldName, boolean hasBLOBColumns) { Method method = new Method("count");
Method method = new Method("getTrashList");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(1);");
method.addBodyLine("}");
method.addBodyLine("List<" + modelClassName + "> result = null;");
method.addBodyLine("long startTime = new Date().getTime();");
if (hasBLOBColumns) {
method.addBodyLine("if (example.getRows() != null && example.getOffset() != null) {");
method.addBodyLine("List<Long> primaryKeyList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
method.addBodyLine("if (primaryKeyList == null || primaryKeyList.isEmpty()) {");
method.addBodyLine("return new ArrayList<>();");
method.addBodyLine("}");
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
method.addBodyLine("if (findPrimaryKeyTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
method.addBodyLine("}");
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list primary key long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + findPrimaryKeyTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
method.addBodyLine("// reset start time");
method.addBodyLine("startTime = new Date().getTime();");
method.addBodyLine("String oldOrderByClause = example.getOrderByClause();");
method.addBodyLine("Boolean withBLOBsFlag = example.isWithBLOBs();");
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria().andGuidIn(primaryKeyList);");
method.addBodyLine("example.setOrderByClause(oldOrderByClause);");
method.addBodyLine("example.setWithBLOBs(withBLOBsFlag);");
method.addBodyLine("}");
method.addBodyLine("if (example.isWithBLOBs()) {");
method.addBodyLine("result = " + mapperFieldName + ".selectByExampleWithBLOBs(example);");
method.addBodyLine("} else {");
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
method.addBodyLine("}");
} else {
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
}
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
method.addBodyLine("}");
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
method.addBodyLine("return result;");
implClass.addMethod(method);
}
private void generateCountByValidMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByValid");
method.addAnnotation("@Override"); method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC); method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("long")); method.setReturnType(new FullyQualifiedJavaType("long"));
@@ -1389,7 +1259,15 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("// clone new example"); method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();"); method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {"); method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);"); method.addBodyLine("if (example.isResultTrash()) {");
method.addBodyLine("criteria.andIsHiddenEqualTo(1)");
method.addBodyLine(" .andIsDeleteEqualTo(0);");
method.addBodyLine("} else if (example.isResultValid()) {");
method.addBodyLine("criteria.andIsHiddenEqualTo(0)");
method.addBodyLine(" .andIsDeleteEqualTo(0);");
method.addBodyLine("} else {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("}"); method.addBodyLine("}");
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);");
@@ -1402,7 +1280,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." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid count long time\" +"); method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " count long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +"); method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +"); method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +"); method.addBodyLine(" exampleString +");
@@ -1414,8 +1292,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method); implClass.addMethod(method);
} }
private void generateCountByValidWithPageMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName, String mapperFieldName) { private void generateCountWithPageMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByValidWithPage"); Method method = new Method("countWithPage");
method.addAnnotation("@Override"); method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC); method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("long")); method.setReturnType(new FullyQualifiedJavaType("long"));
@@ -1424,60 +1302,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("// When not paginated, the count query returns 0 to avoid unnecessary queries"); method.addBodyLine("// When not paginated, the count query returns 0 to avoid unnecessary queries");
method.addBodyLine("if (example.getRows() != null && example.getOffset() != null) {"); method.addBodyLine("if (example.getRows() != null && example.getOffset() != null) {");
method.addBodyLine("return countByValid(example);"); method.addBodyLine("return count(example);");
method.addBodyLine("}");
method.addBodyLine("return 0L;");
implClass.addMethod(method);
}
private void generateCountByTrashMethod(TopLevelClass implClass, String tableName, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByTrash");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("long"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(1);");
method.addBodyLine("}");
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
method.addBodyLine("}");
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash count long time\" +");
method.addBodyLine(" \"\\n\\t|-> table name: " + tableName + "\" +");
method.addBodyLine(" \"\\n\\t|-> use time: \" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
method.addBodyLine("return count;");
implClass.addMethod(method);
}
private void generateCountByTrashWithPageMethod(TopLevelClass implClass, String tableName, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByTrashWithPage");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("long"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("// When not paginated, the count query returns 0 to avoid unnecessary queries");
method.addBodyLine("if (example.getRows() != null && example.getOffset() != null) {");
method.addBodyLine("return countByTrash(example);");
method.addBodyLine("}"); method.addBodyLine("}");
method.addBodyLine("return 0L;"); method.addBodyLine("return 0L;");