This commit is contained in:
iqudoo
2026-04-16 19:20:44 +08:00
parent c048da1faf
commit 959486fed0
3 changed files with 113 additions and 521 deletions

View File

@@ -146,6 +146,7 @@
<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"/>

View File

@@ -27,6 +27,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";
@@ -61,11 +62,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 +166,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 +182,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 +192,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 +247,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 +256,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 +306,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 +372,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 +380,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 +405,20 @@ 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("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);
}
@@ -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");
@@ -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");
@@ -735,7 +555,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
// 方法体
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 +566,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";
@@ -775,7 +594,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 +622,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 +642,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");
@@ -897,7 +656,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
method.addBodyLine("}");
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,116 +680,9 @@ 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 + ">"));
@@ -1038,7 +690,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addException(new FullyQualifiedJavaType("Throwable"));
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();");
@@ -1105,17 +757,23 @@ 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("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();");
@@ -1137,7 +795,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 +830,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,8 +840,8 @@ 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"));
@@ -1191,7 +849,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addException(new FullyQualifiedJavaType("Throwable"));
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 +873,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;