Compare commits

6 Commits
main ... v1

Author SHA1 Message Date
iqudoo
0cfaea99c4 v1 2026-04-21 02:52:14 +08:00
iqudoo
eea9e5e6ee v1 2026-04-21 02:51:02 +08:00
iqudoo
114f69597b 修复:外部传入的 Example 不会被内部修改,完全无副作用 2026-04-21 00:56:35 +08:00
iqudoo
0281b89803 fix 2026-04-16 21:47:07 +08:00
iqudoo
b4488bf7f3 修复bug 2026-04-16 19:38:36 +08:00
iqudoo
959486fed0 V1 2026-04-16 19:20:44 +08:00
5 changed files with 169 additions and 532 deletions

View File

@@ -145,7 +145,7 @@
<property name="changeLogEnable" value="true"/>
<property name="slowQueryLoggerTime" value="300"/>
<property name="slowQueryLoggerLevel" value="error"/>
<property name="priorityPrimaryKeyOffset" value="100"/>
<property name="optimisticLockEnable" value="true"/>
<property name="ignorePageSize" value="10000"/>
<property name="startPageNum" value="1"/>
<property name="maxPageSize" value="100"/>
@@ -176,7 +176,6 @@
| `changeLogEnable` | 变更日志监听开关 | `false` | 否 |
| `slowQueryLoggerTime` | 慢查询日志时间阈值 | `300` | 否 |
| `slowQueryLoggerLevel` | 慢查询日志类型errorwarndebuginfo | `error` | 否 |
| `priorityPrimaryKeyOffset` | 优先查询主键偏移阈值 | `0` | 否 |
| `ignorePageSize` | 忽略分页阈值 | `10000` | 否 |
| `startPageNum` | 分页开始页码 | `1` | 否 |
| `maxPageSize` | 最大每页数量 | `100` | 否 |

View File

@@ -60,6 +60,10 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
FullyQualifiedJavaType integerType = new FullyQualifiedJavaType("java.lang.Integer");
FullyQualifiedJavaType booleanType = new FullyQualifiedJavaType("java.lang.Boolean");
FullyQualifiedJavaType stringType = new FullyQualifiedJavaType("java.lang.String");
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
String exampleClassName = domainObjectName + "Example";
// 添加 startPageNum、maxPageSize、ignorePageSize 字段
Field maxPageSizeField = ElementTools.generateField(
"maxPageSize",
@@ -312,6 +316,32 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
);
FormatTools.addMethodWithBestPosition(topLevelClass, getWhereString);
Method cloneExample = ElementTools.generateMethod(
"cloneExample",
JavaVisibility.PUBLIC,
topLevelClass.getType()
);
cloneExample = ElementTools.generateMethodBody(
cloneExample,
exampleClassName + " newExample = new " + exampleClassName + "();",
"newExample.rows = this.rows;",
"newExample.offset = this.offset;",
"newExample.maxPageSize = this.maxPageSize;",
"newExample.ignorePageSize = this.ignorePageSize;",
"newExample.startPageNum = startPageNum;",
hasBLOBColumns ? "newExample.withBLOBs = withBLOBs;" : "",
"if (this.getOredCriteria() != null && !this.getOredCriteria().isEmpty()) {",
"for (" + exampleClassName + ".Criteria oldCriteria : this.getOredCriteria()) {",
exampleClassName + ".Criteria newCriteria = newExample.or();",
"newCriteria.getCriteria().addAll(oldCriteria.getCriteria());",
"}",
"}",
"newExample.setOrderByClause(this.getOrderByClause());",
"return newExample;"
);
FormatTools.addMethodWithBestPosition(topLevelClass, cloneExample);
// !!! clear 方法增加 offset 和 rows的清理
boolean hasClear = false;
List<Method> methodList = topLevelClass.getMethods();

View File

@@ -19,7 +19,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
// 固定配置项
private String slowQueryLoggerTime = "300";
private String slowQueryLoggerLevel = "error";
private String priorityPrimaryKeyOffset = "0";
private String facadeRepositoryPackage = "com.iqudoo.platform.application.facade.repository";
private String domainRepositoryPackage = "com.iqudoo.platform.application.domain.repository";
private String guidGeneratorClass = "com.iqudoo.framework.tape.modules.utils.SnowflakeUtil";
@@ -27,6 +26,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
private String changeLogContextClassPackage = "com.iqudoo.platform.application.domain.changeLog";
private String changeLogContextClassName = "ChangeLogContext";
private String changeLogEnable = "false";
private String optimisticLockEnable = "false";
private String modelPackage = "com.iqudoo.platform.application.database.model";
private String mapperPackage = "com.iqudoo.platform.application.database.mapper";
private String targetProject = "src/main/java";
@@ -53,7 +53,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) {
slowQueryLoggerLevel = "error";
}
priorityPrimaryKeyOffset = stringConfig("priorityPrimaryKeyOffset", priorityPrimaryKeyOffset);
guidGeneratorClass = stringConfig("guidGeneratorClass", guidGeneratorClass);
guidGeneratorCode = stringConfig("guidGeneratorCode", guidGeneratorCode);
facadeRepositoryPackage = stringConfig("facadeRepositoryPackage", facadeRepositoryPackage);
@@ -61,11 +60,23 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
changeLogContextClassPackage = stringConfig("changeLogContextClassPackage", changeLogContextClassPackage);
changeLogContextClassName = stringConfig("changeLogContextClassName", changeLogContextClassName);
changeLogEnable = stringConfig("changeLogEnable", changeLogEnable);
optimisticLockEnable = stringConfig("optimisticLockEnable", optimisticLockEnable);
modelPackage = stringConfig("modelPackage", modelPackage);
mapperPackage = stringConfig("mapperPackage", mapperPackage);
targetProject = stringConfig("targetProject", targetProject);
}
private boolean isOptimisticLockEnable() {
try {
boolean b = Boolean.parseBoolean(optimisticLockEnable);
if (b) {
return true;
}
} catch (Throwable ignored) {
}
return false;
}
private boolean isChangeLogEnable() {
try {
boolean b = Boolean.parseBoolean(changeLogEnable);
@@ -153,30 +164,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
Interface repositoryInterface = new Interface(facadeRepositoryPackage + "." + interfaceName);
repositoryInterface.setVisibility(JavaVisibility.PUBLIC);
// 添加必要的导入仅保留model和example移除ModelDataRepository
// 添加必要的导入
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
repositoryInterface.addImportedType(new FullyQualifiedJavaType("java.util.List"));
repositoryInterface.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"));
// 1. trashById
Method trashByIdMethod = new Method("trashById");
trashByIdMethod.setVisibility(JavaVisibility.PUBLIC);
trashByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
trashByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
trashByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
trashByIdMethod.setAbstract(true);
repositoryInterface.addMethod(trashByIdMethod);
// 2. trashAll
Method trashAllMethod = new Method("trashAll");
trashAllMethod.setVisibility(JavaVisibility.PUBLIC);
trashAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
trashAllMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
trashAllMethod.addException(new FullyQualifiedJavaType("Throwable"));
trashAllMethod.setAbstract(true);
repositoryInterface.addMethod(trashAllMethod);
// 3. deleteById
// 1. deleteById
Method deleteByIdMethod = new Method("deleteById");
deleteByIdMethod.setVisibility(JavaVisibility.PUBLIC);
deleteByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -186,7 +180,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
deleteByIdMethod.setAbstract(true);
repositoryInterface.addMethod(deleteByIdMethod);
// 4. deleteAll
// 2. deleteAll
Method deleteAllMethod = new Method("deleteAll");
deleteAllMethod.setVisibility(JavaVisibility.PUBLIC);
deleteAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -196,124 +190,53 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
deleteAllMethod.setAbstract(true);
repositoryInterface.addMethod(deleteAllMethod);
// 5. recoverById
Method recoverByIdMethod = new Method("recoverById");
recoverByIdMethod.setVisibility(JavaVisibility.PUBLIC);
recoverByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
recoverByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
recoverByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
recoverByIdMethod.setAbstract(true);
repositoryInterface.addMethod(recoverByIdMethod);
// 3. findById
Method findByIdMethod = new Method("findById");
findByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
findByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
findByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findByIdMethod);
// 6. recoverAll
Method recoverAllMethod = new Method("recoverAll");
recoverAllMethod.setVisibility(JavaVisibility.PUBLIC);
recoverAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
recoverAllMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
recoverAllMethod.addException(new FullyQualifiedJavaType("Throwable"));
recoverAllMethod.setAbstract(true);
repositoryInterface.addMethod(recoverAllMethod);
// 4. findOne
Method findOneMethod = new Method("findOne");
findOneMethod.setVisibility(JavaVisibility.PUBLIC);
findOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
findOneMethod.addException(new FullyQualifiedJavaType("Throwable"));
findOneMethod.setAbstract(true);
repositoryInterface.addMethod(findOneMethod);
// 7. findAnyById
Method findAnyByIdMethod = new Method("findAnyById");
findAnyByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findAnyByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findAnyByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
findAnyByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
findAnyByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findAnyByIdMethod);
// 5. list
Method listMethod = new Method("list");
listMethod.setVisibility(JavaVisibility.PUBLIC);
listMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
listMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
listMethod.addException(new FullyQualifiedJavaType("Throwable"));
listMethod.setAbstract(true);
repositoryInterface.addMethod(listMethod);
// 8. findValidById
Method findValidByIdMethod = new Method("findValidById");
findValidByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findValidByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findValidByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
findValidByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
findValidByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findValidByIdMethod);
// 5. list
Method listWithRowBoundsMethod = new Method("list");
listWithRowBoundsMethod.setVisibility(JavaVisibility.PUBLIC);
listWithRowBoundsMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
listWithRowBoundsMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
listWithRowBoundsMethod.addParameter(new Parameter(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"), "rowBounds"));
listWithRowBoundsMethod.addException(new FullyQualifiedJavaType("Throwable"));
listWithRowBoundsMethod.setAbstract(true);
repositoryInterface.addMethod(listWithRowBoundsMethod);
// 9. findTrashById
Method findTrashByIdMethod = new Method("findTrashById");
findTrashByIdMethod.setVisibility(JavaVisibility.PUBLIC);
findTrashByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findTrashByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
findTrashByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
findTrashByIdMethod.setAbstract(true);
repositoryInterface.addMethod(findTrashByIdMethod);
// 6. count
Method countMethod = new Method("count");
countMethod.setVisibility(JavaVisibility.PUBLIC);
countMethod.setReturnType(new FullyQualifiedJavaType("long"));
countMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
countMethod.addException(new FullyQualifiedJavaType("Throwable"));
countMethod.setAbstract(true);
repositoryInterface.addMethod(countMethod);
// 10. findValidOne
Method findValidOneMethod = new Method("findValidOne");
findValidOneMethod.setVisibility(JavaVisibility.PUBLIC);
findValidOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findValidOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
findValidOneMethod.addException(new FullyQualifiedJavaType("Throwable"));
findValidOneMethod.setAbstract(true);
repositoryInterface.addMethod(findValidOneMethod);
// 11. findTrashOne
Method findTrashOneMethod = new Method("findTrashOne");
findTrashOneMethod.setVisibility(JavaVisibility.PUBLIC);
findTrashOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
findTrashOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
findTrashOneMethod.addException(new FullyQualifiedJavaType("Throwable"));
findTrashOneMethod.setAbstract(true);
repositoryInterface.addMethod(findTrashOneMethod);
// 12. getValidList
Method getValidListMethod = new Method("getValidList");
getValidListMethod.setVisibility(JavaVisibility.PUBLIC);
getValidListMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
getValidListMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
getValidListMethod.addException(new FullyQualifiedJavaType("Throwable"));
getValidListMethod.setAbstract(true);
repositoryInterface.addMethod(getValidListMethod);
// 13. getTrashList
Method getTrashListMethod = new Method("getTrashList");
getTrashListMethod.setVisibility(JavaVisibility.PUBLIC);
getTrashListMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
getTrashListMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
getTrashListMethod.addException(new FullyQualifiedJavaType("Throwable"));
getTrashListMethod.setAbstract(true);
repositoryInterface.addMethod(getTrashListMethod);
// 14. countByValid
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
// 7. insert
Method insertMethod = new Method("insert");
insertMethod.setVisibility(JavaVisibility.PUBLIC);
insertMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -322,16 +245,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
insertMethod.setAbstract(true);
repositoryInterface.addMethod(insertMethod);
// 19. batchInsert
Method batchInsertMethod = new Method("batchInsert");
batchInsertMethod.setVisibility(JavaVisibility.PUBLIC);
batchInsertMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
batchInsertMethod.addParameter(new Parameter(new FullyQualifiedJavaType("List<" + modelClassName + ">"), "records"));
batchInsertMethod.addException(new FullyQualifiedJavaType("Throwable"));
batchInsertMethod.setAbstract(true);
repositoryInterface.addMethod(batchInsertMethod);
// 20. update
// 8. update
Method updateMethod = new Method("update");
updateMethod.setVisibility(JavaVisibility.PUBLIC);
updateMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -340,7 +254,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
updateMethod.setAbstract(true);
repositoryInterface.addMethod(updateMethod);
// 21. updateByExampleSelective
// 9. updateByExampleSelective
Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective");
updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC);
updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int"));
@@ -390,27 +304,16 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addField(mapperField);
// 原有方法生成逻辑(无修改)
generateFindAnyByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindValidByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindOneMethod(implClass, modelClassName, exampleClassName);
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
generateBatchInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
generateDeleteByIdMethod(implClass, modelClassName, mapperFieldName);
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateTrashByIdMethod(implClass, modelClassName, mapperFieldName);
generateTrashAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateRecoverByIdMethod(implClass, modelClassName, mapperFieldName);
generateRecoverAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateFindValidOneMethod(implClass, modelClassName, exampleClassName);
generateFindTrashOneMethod(implClass, modelClassName, exampleClassName);
generateGetValidListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateGetTrashListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountByValidMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateCountByValidWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateListWithRowBoundsMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
return implClass;
}
@@ -467,6 +370,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
implClass.addImportedType(new FullyQualifiedJavaType(facadeRepositoryPackage + "." + interfaceName));
implClass.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"));
implClass.addImportedType(new FullyQualifiedJavaType("org.springframework.stereotype.Repository"));
implClass.addImportedType(new FullyQualifiedJavaType("javax.annotation.Resource"));
implClass.addImportedType(new FullyQualifiedJavaType("org.slf4j.Logger"));
@@ -474,8 +378,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addImportedType(new FullyQualifiedJavaType("java.util.*"));
}
private void generateFindAnyByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
Method method = new Method("findAnyById");
private void generateFindByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
Method method = new Method("findById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
@@ -499,54 +403,22 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateFindValidByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
Method method = new Method("findValidById");
private void generateFindOneMethod(TopLevelClass implClass, String modelClassName, String exampleClassName) {
Method method = new Method("findOne");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "guid"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = null;");
method.addBodyLine(exampleClassName + " example");
method.addBodyLine(" = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria()");
method.addBodyLine(" .andIsHiddenEqualTo(0)");
method.addBodyLine(" .andIsDeleteEqualTo(0)");
method.addBodyLine(" .andGuidEqualTo(guid);");
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
method.addBodyLine("List<" + modelClassName + "> recordList");
method.addBodyLine(" = " + mapperFieldName + "." + selectByExampleMethod + "(example);");
method.addBodyLine("if (recordList != null && !recordList.isEmpty()) {");
method.addBodyLine("aDo = recordList.get(0);");
method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("example.usePage(1, 1);");
method.addBodyLine("List<" + modelClassName + "> dataList = list(example);");
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
method.addBodyLine("return dataList.get(0);");
method.addBodyLine("}");
method.addBodyLine("return aDo;");
implClass.addMethod(method);
}
private void generateFindTrashByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
Method method = new Method("findTrashById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "guid"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = null;");
method.addBodyLine(exampleClassName + " example");
method.addBodyLine(" = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria()");
method.addBodyLine(" .andIsHiddenEqualTo(1)");
method.addBodyLine(" .andIsDeleteEqualTo(0)");
method.addBodyLine(" .andGuidEqualTo(guid);");
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
method.addBodyLine("List<" + modelClassName + "> recordList");
method.addBodyLine(" = " + mapperFieldName + "." + selectByExampleMethod + "(example);");
method.addBodyLine("if (recordList != null && !recordList.isEmpty()) {");
method.addBodyLine("aDo = recordList.get(0);");
method.addBodyLine("}");
method.addBodyLine("return aDo;");
method.addBodyLine("return null;");
implClass.addMethod(method);
}
@@ -572,7 +444,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
String setterMethod = "set" + upperFirst(fieldName);
String getterMethod = "get" + upperFirst(fieldName);
if ("guid".equals(fieldName) || "isDelete".equals(fieldName) || "isHidden".equals(fieldName)
if ("guid".equals(fieldName) || "isDelete".equals(fieldName)
|| "deleteToken".equals(fieldName) || "dataVersion".equals(fieldName)
|| "createTime".equals(fieldName) || "updateTime".equals(fieldName)) {
continue;
@@ -581,7 +453,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
}
method.addBodyLine("aDo.setIsDelete(0);");
method.addBodyLine("aDo.setIsHidden(0);");
method.addBodyLine("aDo.setDeleteToken(\"VALID\");");
method.addBodyLine("aDo.setDataVersion(1);");
method.addBodyLine("aDo.setCreateTime(new Date());");
@@ -604,63 +475,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateBatchInsertMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, IntrospectedTable introspectedTable) {
Method method = new Method("batchInsert");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("List<" + modelClassName + ">"), "records"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("if (records == null || records.isEmpty()) {");
method.addBodyLine("return new ArrayList<>();");
method.addBodyLine("}");
method.addBodyLine("List<" + modelClassName + "> batch = new ArrayList<>();");
method.addBodyLine("for (" + modelClassName + " record : records) {");
method.addBodyLine(modelClassName + " aDo = new " + modelClassName + "();");
method.addBodyLine("if (record.getGuid() != null) {");
method.addBodyLine("aDo.setGuid(record.getGuid());");
method.addBodyLine("} else {");
method.addBodyLine("Long guid = " + guidGeneratorCode + ";");
method.addBodyLine("aDo.setGuid(guid);");
method.addBodyLine("}");
for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
String fieldName = column.getJavaProperty();
String setterMethod = "set" + upperFirst(fieldName);
String getterMethod = "get" + upperFirst(fieldName);
if ("guid".equals(fieldName) || "isDelete".equals(fieldName) || "isHidden".equals(fieldName)
|| "deleteToken".equals(fieldName) || "dataVersion".equals(fieldName)
|| "createTime".equals(fieldName) || "updateTime".equals(fieldName)) {
continue;
}
method.addBodyLine("aDo." + setterMethod + "(record." + getterMethod + "());");
}
method.addBodyLine("aDo.setIsDelete(0);");
method.addBodyLine("aDo.setIsHidden(0);");
method.addBodyLine("aDo.setDeleteToken(\"VALID\");");
method.addBodyLine("aDo.setDataVersion(1);");
method.addBodyLine("aDo.setCreateTime(new Date());");
method.addBodyLine("aDo.setUpdateTime(new Date());");
method.addBodyLine("batch.add(aDo);");
method.addBodyLine("}");
method.addBodyLine("int count = " + mapperFieldName + ".batchInsert(batch);");
method.addBodyLine("if (count == batch.size()) {");
if (isChangeLogEnable()) {
method.addBodyLine("for (" + modelClassName + " aDo : batch) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"batchInsert\", aDo.getGuid(), new HashMap<>());");
method.addBodyLine("}");
}
method.addBodyLine("return batch;");
method.addBodyLine("}");
method.addBodyLine("throw new Throwable(\"Batch insert failed, " + modelClassName + " affected: \" + count + \", expected: \" + batch.size());");
implClass.addMethod(method);
}
private void generateUpdateMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
Method method = new Method("update");
@@ -682,7 +496,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
String fieldName = column.getJavaProperty();
String setterMethod = "set" + upperFirst(fieldName);
String getterMethod = "get" + upperFirst(fieldName);
if ("guid".equals(fieldName) || "isDelete".equals(fieldName) || "isHidden".equals(fieldName)
if ("guid".equals(fieldName) || "isDelete".equals(fieldName)
|| "deleteToken".equals(fieldName) || "dataVersion".equals(fieldName)
|| "createTime".equals(fieldName) || "updateTime".equals(fieldName)) {
continue;
@@ -697,6 +511,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("}");
}
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
if (isOptimisticLockEnable()) {
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
method.addBodyLine("if (lockDataVersion == null) {");
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
@@ -704,6 +519,11 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("updateWhere.createCriteria()");
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
} else {
// 不使用乐观锁更新数据
method.addBodyLine("updateWhere.createCriteria()");
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid());");
}
method.addBodyLine("aDo.setDataVersion(aDo.getDataVersion() + 1);");
method.addBodyLine("aDo.setUpdateTime(new Date());");
method.addBodyLine("// update data version");
@@ -734,8 +554,10 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
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(0);");
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("List<Long> guidList = " + mapperFieldName);
@@ -746,7 +568,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria()");
method.addBodyLine(" .andIsDeleteEqualTo(0)");
method.addBodyLine(" .andIsHiddenEqualTo(0)");
method.addBodyLine(" .andGuidIn(guidList);");
if (isChangeLogEnable()) {
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
@@ -759,7 +580,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
String fieldName = column.getJavaProperty();
String setterMethod = "set" + upperFirst(fieldName);
String getterMethod = "get" + upperFirst(fieldName);
if ("guid".equals(fieldName) || "isDelete".equals(fieldName) || "isHidden".equals(fieldName)
if ("guid".equals(fieldName) || "isDelete".equals(fieldName)
|| "deleteToken".equals(fieldName) || "dataVersion".equals(fieldName)
|| "createTime".equals(fieldName) || "updateTime".equals(fieldName)) {
continue;
@@ -775,7 +596,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("record.setDataVersion(100);");
method.addBodyLine("// It is not supported to directly modify the following columns");
method.addBodyLine("record.setUpdateTime(new Date());");
method.addBodyLine("record.setIsHidden(null);");
method.addBodyLine("record.setIsDelete(null);");
method.addBodyLine("record.setDeleteToken(null);");
method.addBodyLine("record.setCreateTime(null);");
@@ -804,7 +624,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("boolean"), "release"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findValidById(id);");
method.addBodyLine(modelClassName + " aDo = findById(id);");
method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
@@ -824,65 +644,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateTrashByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName) {
Method method = new Method("trashById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("int"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findValidById(id);");
method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine("aDo.setIsHidden(1);");
method.addBodyLine("aDo.setDeleteToken(aDo.getGuid() + \"\");");
method.addBodyLine("aDo.setUpdateTime(new Date());");
if (isChangeLogEnable()) {
method.addBodyLine("int update = " + mapperFieldName + ".updateByPrimaryKey(aDo);");
method.addBodyLine("if (update > 0) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"trashById\", aDo.getGuid(), new HashMap<>());");
method.addBodyLine("}");
method.addBodyLine("return update;");
} else {
method.addBodyLine("return " + mapperFieldName + ".updateByPrimaryKey(aDo);");
}
implClass.addMethod(method);
}
private void generateRecoverByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName) {
Method method = new Method("recoverById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("int"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine(modelClassName + " aDo = findTrashById(id);");
method.addBodyLine("if (aDo == null) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine("if (aDo.getIsDelete() == 1) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine("aDo.setIsHidden(0);");
method.addBodyLine("aDo.setDeleteToken(\"VALID\");");
method.addBodyLine("aDo.setUpdateTime(new Date());");
if (isChangeLogEnable()) {
method.addBodyLine("int update = " + mapperFieldName + ".updateByPrimaryKey(aDo);");
method.addBodyLine("if (update > 0) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"recoverById\", aDo.getGuid(), new HashMap<>());");
method.addBodyLine("}");
method.addBodyLine("return update;");
} else {
method.addBodyLine("return " + mapperFieldName + ".updateByPrimaryKey(aDo);");
}
implClass.addMethod(method);
}
private void generateDeleteAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("deleteAll");
method.addAnnotation("@Override");
@@ -896,8 +657,10 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (release) {");
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
method.addBodyLine("}");
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("criteria.andIsDeleteEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("List<Long> guidList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
method.addBodyLine("if (guidList.isEmpty()) {");
@@ -921,129 +684,24 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateTrashAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("trashAll");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("int"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
// 方法体
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("List<Long> guidList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
method.addBodyLine("if (guidList.isEmpty()) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
method.addBodyLine(lowerFirst(modelClassName) + ".setIsHidden(1);");
method.addBodyLine(lowerFirst(modelClassName) + ".setDeleteToken(" + guidGeneratorCode + " + \"\");");
method.addBodyLine(lowerFirst(modelClassName) + ".setUpdateTime(new Date());");
if (isChangeLogEnable()) {
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Long guid : guidList) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"trashAll\", guid, new HashMap<>());");
method.addBodyLine("}");
method.addBodyLine("}");
method.addBodyLine("return update;");
} else {
method.addBodyLine("return " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
}
implClass.addMethod(method);
}
private void generateRecoverAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("recoverAll");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("int"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
// 方法体
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(1);");
method.addBodyLine("}");
method.addBodyLine("List<Long> guidList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
method.addBodyLine("if (guidList.isEmpty()) {");
method.addBodyLine("return 0;");
method.addBodyLine("}");
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
method.addBodyLine(lowerFirst(modelClassName) + ".setIsHidden(0);");
method.addBodyLine(lowerFirst(modelClassName) + ".setDeleteToken(\"VALID\");");
method.addBodyLine(lowerFirst(modelClassName) + ".setUpdateTime(new Date());");
if (isChangeLogEnable()) {
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Long guid : guidList) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"recoverAll\", guid, new HashMap<>());");
method.addBodyLine("}");
method.addBodyLine("}");
method.addBodyLine("return update;");
} else {
method.addBodyLine("return " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
}
implClass.addMethod(method);
}
private void generateFindValidOneMethod(TopLevelClass implClass, String modelClassName, String exampleClassName) {
Method method = new Method("findValidOne");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("example.usePage(1, 1);");
method.addBodyLine("List<" + modelClassName + "> dataList = getValidList(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 generateFindTrashOneMethod(TopLevelClass implClass, String modelClassName, String exampleClassName) {
Method method = new Method("findTrashOne");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addException(new FullyQualifiedJavaType("Throwable"));
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 modelClassName, String exampleClassName,
private void generateListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getValidList");
Method method = new Method("list");
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(0);");
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
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 && example.getOffset() > " + priorityPrimaryKeyOffset + ") {");
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<>();");
@@ -1105,22 +763,30 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateGetTrashListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
private void generateListWithRowBoundsMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getTrashList");
Method method = new Method("list");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
method.addParameter(new Parameter(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"), "rowBounds"));
method.addException(new FullyQualifiedJavaType("Throwable"));
method.addBodyLine("// 兼容原来的写法rowBounds");
method.addBodyLine("if (rowBounds != null) {");
method.addBodyLine("example.limit(rowBounds.getOffset(), rowBounds.getLimit());");
method.addBodyLine("}");
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("criteria.andIsDeleteEqualTo(0);");
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 && example.getOffset() > " + priorityPrimaryKeyOffset + ") {");
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<>();");
@@ -1137,7 +803,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list primary key use long time\" +");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list primary key use long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + findPrimaryKeyTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1172,7 +838,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list use long time\" +");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list use long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1182,16 +848,18 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateCountByValidMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByValid");
private void generateCountMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("count");
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(0);");
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
method.addBodyLine("}");
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
@@ -1215,73 +883,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateCountByValidWithPageMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByValidWithPage");
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 countByValid(example);");
method.addBodyLine("}");
method.addBodyLine("return 0L;");
implClass.addMethod(method);
}
private void generateCountByTrashMethod(TopLevelClass implClass, 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("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 > " + slowQueryLoggerTime + ") {");
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." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash count use long time\" +");
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 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("return 0L;");
implClass.addMethod(method);
}
private String upperFirst(String str) {
if (str == null || str.isEmpty()) {
return str;

View File

@@ -50,8 +50,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
if (!UtilTools.inArray(new String[]{"error", "warn", "debug", "info"}, slowQueryLoggerLevel)) {
slowQueryLoggerLevel = "error";
}
facadeViewRepositoryPackage = stringConfig("facadeRepoviewPackage", facadeViewRepositoryPackage);
domainViewRepositoryPackage = stringConfig("domainRepoviewPackage", domainViewRepositoryPackage);
facadeViewRepositoryPackage = stringConfig("facadeViewRepositoryPackage", facadeViewRepositoryPackage);
domainViewRepositoryPackage = stringConfig("domainViewRepositoryPackage", domainViewRepositoryPackage);
modelPackage = stringConfig("modelPackage", modelPackage);
mapperPackage = stringConfig("mapperPackage", mapperPackage);
targetProject = stringConfig("targetProject", targetProject);
@@ -255,6 +255,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
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 = getList(example);");
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
@@ -276,6 +278,9 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
// 参数名匹配示例(首字母小写)
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("List<" + modelClassName + "> result = null;");
method.addBodyLine("long startTime = new Date().getTime();");
if (hasBLOBColumns) {
@@ -319,6 +324,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
method.addException(new FullyQualifiedJavaType("Throwable"));
// 方法体
method.addBodyLine("// clone new example");
method.addBodyLine("example = example.cloneExample();");
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");