修复:外部传入的 Example 不会被内部修改,完全无副作用
This commit is contained in:
Binary file not shown.
@@ -60,6 +60,10 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
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");
|
||||||
|
|
||||||
|
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
|
||||||
|
String exampleClassName = domainObjectName + "Example";
|
||||||
|
|
||||||
// 添加 startPageNum、maxPageSize、ignorePageSize 字段
|
// 添加 startPageNum、maxPageSize、ignorePageSize 字段
|
||||||
Field maxPageSizeField = ElementTools.generateField(
|
Field maxPageSizeField = ElementTools.generateField(
|
||||||
"maxPageSize",
|
"maxPageSize",
|
||||||
@@ -312,6 +316,32 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
|
|||||||
);
|
);
|
||||||
FormatTools.addMethodWithBestPosition(topLevelClass, getWhereString);
|
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的清理
|
// !!! clear 方法增加 offset 和 rows的清理
|
||||||
boolean hasClear = false;
|
boolean hasClear = false;
|
||||||
List<Method> methodList = topLevelClass.getMethods();
|
List<Method> methodList = topLevelClass.getMethods();
|
||||||
|
|||||||
@@ -413,6 +413,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
|
method.addBodyLine("// clone new example");
|
||||||
|
method.addBodyLine("example = example.cloneExample();");
|
||||||
method.addBodyLine("example.usePage(1, 1);");
|
method.addBodyLine("example.usePage(1, 1);");
|
||||||
method.addBodyLine("List<" + modelClassName + "> dataList = list(example);");
|
method.addBodyLine("List<" + modelClassName + "> dataList = list(example);");
|
||||||
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
|
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
|
||||||
@@ -554,6 +556,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
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("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -655,6 +659,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (release) {");
|
method.addBodyLine("if (release) {");
|
||||||
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
|
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
|
method.addBodyLine("// clone new example");
|
||||||
|
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);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -689,6 +695,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
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("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -772,6 +780,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("example.limit(rowBounds.getOffset(), rowBounds.getLimit());");
|
method.addBodyLine("example.limit(rowBounds.getOffset(), rowBounds.getLimit());");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
|
|
||||||
|
method.addBodyLine("// clone new example");
|
||||||
|
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);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -848,6 +858,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
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("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
|
|||||||
@@ -255,6 +255,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
// 方法体
|
// 方法体
|
||||||
|
method.addBodyLine("// clone new example");
|
||||||
|
method.addBodyLine("example = example.cloneExample();");
|
||||||
method.addBodyLine("example.usePage(1, 1);");
|
method.addBodyLine("example.usePage(1, 1);");
|
||||||
method.addBodyLine("List<" + modelClassName + "> dataList = getList(example);");
|
method.addBodyLine("List<" + modelClassName + "> dataList = getList(example);");
|
||||||
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
|
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.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
|
method.addBodyLine("// clone new example");
|
||||||
|
method.addBodyLine("example = example.cloneExample();");
|
||||||
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();");
|
||||||
if (hasBLOBColumns) {
|
if (hasBLOBColumns) {
|
||||||
@@ -319,6 +324,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
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 startTime = new Date().getTime();");
|
||||||
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
||||||
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
|
||||||
|
|||||||
Reference in New Issue
Block a user