V1
This commit is contained in:
@@ -146,6 +146,7 @@
|
|||||||
<property name="slowQueryLoggerTime" value="300"/>
|
<property name="slowQueryLoggerTime" value="300"/>
|
||||||
<property name="slowQueryLoggerLevel" value="error"/>
|
<property name="slowQueryLoggerLevel" value="error"/>
|
||||||
<property name="priorityPrimaryKeyOffset" value="100"/>
|
<property name="priorityPrimaryKeyOffset" value="100"/>
|
||||||
|
<property name="optimisticLockEnable" value="true"/>
|
||||||
<property name="ignorePageSize" value="10000"/>
|
<property name="ignorePageSize" value="10000"/>
|
||||||
<property name="startPageNum" value="1"/>
|
<property name="startPageNum" value="1"/>
|
||||||
<property name="maxPageSize" value="100"/>
|
<property name="maxPageSize" value="100"/>
|
||||||
|
|||||||
Binary file not shown.
@@ -27,6 +27,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
private String changeLogContextClassPackage = "com.iqudoo.platform.application.domain.changeLog";
|
private String changeLogContextClassPackage = "com.iqudoo.platform.application.domain.changeLog";
|
||||||
private String changeLogContextClassName = "ChangeLogContext";
|
private String changeLogContextClassName = "ChangeLogContext";
|
||||||
private String changeLogEnable = "false";
|
private String changeLogEnable = "false";
|
||||||
|
private String optimisticLockEnable = "false";
|
||||||
private String modelPackage = "com.iqudoo.platform.application.database.model";
|
private String modelPackage = "com.iqudoo.platform.application.database.model";
|
||||||
private String mapperPackage = "com.iqudoo.platform.application.database.mapper";
|
private String mapperPackage = "com.iqudoo.platform.application.database.mapper";
|
||||||
private String targetProject = "src/main/java";
|
private String targetProject = "src/main/java";
|
||||||
@@ -61,11 +62,23 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
changeLogContextClassPackage = stringConfig("changeLogContextClassPackage", changeLogContextClassPackage);
|
changeLogContextClassPackage = stringConfig("changeLogContextClassPackage", changeLogContextClassPackage);
|
||||||
changeLogContextClassName = stringConfig("changeLogContextClassName", changeLogContextClassName);
|
changeLogContextClassName = stringConfig("changeLogContextClassName", changeLogContextClassName);
|
||||||
changeLogEnable = stringConfig("changeLogEnable", changeLogEnable);
|
changeLogEnable = stringConfig("changeLogEnable", changeLogEnable);
|
||||||
|
optimisticLockEnable = stringConfig("optimisticLockEnable", optimisticLockEnable);
|
||||||
modelPackage = stringConfig("modelPackage", modelPackage);
|
modelPackage = stringConfig("modelPackage", modelPackage);
|
||||||
mapperPackage = stringConfig("mapperPackage", mapperPackage);
|
mapperPackage = stringConfig("mapperPackage", mapperPackage);
|
||||||
targetProject = stringConfig("targetProject", targetProject);
|
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() {
|
private boolean isChangeLogEnable() {
|
||||||
try {
|
try {
|
||||||
boolean b = Boolean.parseBoolean(changeLogEnable);
|
boolean b = Boolean.parseBoolean(changeLogEnable);
|
||||||
@@ -153,30 +166,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
Interface repositoryInterface = new Interface(facadeRepositoryPackage + "." + interfaceName);
|
Interface repositoryInterface = new Interface(facadeRepositoryPackage + "." + interfaceName);
|
||||||
repositoryInterface.setVisibility(JavaVisibility.PUBLIC);
|
repositoryInterface.setVisibility(JavaVisibility.PUBLIC);
|
||||||
|
|
||||||
// 添加必要的导入(仅保留model和example,移除ModelDataRepository)
|
// 添加必要的导入
|
||||||
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
|
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
|
||||||
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
|
repositoryInterface.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
|
||||||
repositoryInterface.addImportedType(new FullyQualifiedJavaType("java.util.List"));
|
repositoryInterface.addImportedType(new FullyQualifiedJavaType("java.util.List"));
|
||||||
|
repositoryInterface.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"));
|
||||||
|
|
||||||
// 1. trashById
|
// 1. deleteById
|
||||||
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
|
|
||||||
Method deleteByIdMethod = new Method("deleteById");
|
Method deleteByIdMethod = new Method("deleteById");
|
||||||
deleteByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
deleteByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
deleteByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
deleteByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
||||||
@@ -186,7 +182,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
deleteByIdMethod.setAbstract(true);
|
deleteByIdMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(deleteByIdMethod);
|
repositoryInterface.addMethod(deleteByIdMethod);
|
||||||
|
|
||||||
// 4. deleteAll
|
// 2. deleteAll
|
||||||
Method deleteAllMethod = new Method("deleteAll");
|
Method deleteAllMethod = new Method("deleteAll");
|
||||||
deleteAllMethod.setVisibility(JavaVisibility.PUBLIC);
|
deleteAllMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
deleteAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
deleteAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
||||||
@@ -196,124 +192,53 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
deleteAllMethod.setAbstract(true);
|
deleteAllMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(deleteAllMethod);
|
repositoryInterface.addMethod(deleteAllMethod);
|
||||||
|
|
||||||
// 5. recoverById
|
// 3. findById
|
||||||
Method recoverByIdMethod = new Method("recoverById");
|
Method findByIdMethod = new Method("findById");
|
||||||
recoverByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
findByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
recoverByIdMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
findByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
||||||
recoverByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
|
findByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
|
||||||
recoverByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
findByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
recoverByIdMethod.setAbstract(true);
|
findByIdMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(recoverByIdMethod);
|
repositoryInterface.addMethod(findByIdMethod);
|
||||||
|
|
||||||
// 6. recoverAll
|
// 4. findOne
|
||||||
Method recoverAllMethod = new Method("recoverAll");
|
Method findOneMethod = new Method("findOne");
|
||||||
recoverAllMethod.setVisibility(JavaVisibility.PUBLIC);
|
findOneMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
recoverAllMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
findOneMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
||||||
recoverAllMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
findOneMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
recoverAllMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
findOneMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
recoverAllMethod.setAbstract(true);
|
findOneMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(recoverAllMethod);
|
repositoryInterface.addMethod(findOneMethod);
|
||||||
|
|
||||||
// 7. findAnyById
|
// 5. list
|
||||||
Method findAnyByIdMethod = new Method("findAnyById");
|
Method listMethod = new Method("list");
|
||||||
findAnyByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
listMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
findAnyByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
listMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
||||||
findAnyByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
|
listMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
findAnyByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
listMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
findAnyByIdMethod.setAbstract(true);
|
listMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(findAnyByIdMethod);
|
repositoryInterface.addMethod(listMethod);
|
||||||
|
|
||||||
// 8. findValidById
|
// 5. list
|
||||||
Method findValidByIdMethod = new Method("findValidById");
|
Method listWithRowBoundsMethod = new Method("list");
|
||||||
findValidByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
listWithRowBoundsMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
findValidByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
listWithRowBoundsMethod.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
||||||
findValidByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
|
listWithRowBoundsMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
findValidByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
listWithRowBoundsMethod.addParameter(new Parameter(new FullyQualifiedJavaType("org.apache.ibatis.session.RowBounds"), "rowBounds"));
|
||||||
findValidByIdMethod.setAbstract(true);
|
listWithRowBoundsMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
repositoryInterface.addMethod(findValidByIdMethod);
|
listWithRowBoundsMethod.setAbstract(true);
|
||||||
|
repositoryInterface.addMethod(listWithRowBoundsMethod);
|
||||||
|
|
||||||
// 9. findTrashById
|
// 6. count
|
||||||
Method findTrashByIdMethod = new Method("findTrashById");
|
Method countMethod = new Method("count");
|
||||||
findTrashByIdMethod.setVisibility(JavaVisibility.PUBLIC);
|
countMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
findTrashByIdMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
countMethod.setReturnType(new FullyQualifiedJavaType("long"));
|
||||||
findTrashByIdMethod.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "id"));
|
countMethod.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
findTrashByIdMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
countMethod.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
findTrashByIdMethod.setAbstract(true);
|
countMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(findTrashByIdMethod);
|
repositoryInterface.addMethod(countMethod);
|
||||||
|
|
||||||
// 10. findValidOne
|
// 7. insert
|
||||||
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
|
|
||||||
Method insertMethod = new Method("insert");
|
Method insertMethod = new Method("insert");
|
||||||
insertMethod.setVisibility(JavaVisibility.PUBLIC);
|
insertMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
insertMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
insertMethod.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
||||||
@@ -322,16 +247,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
insertMethod.setAbstract(true);
|
insertMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(insertMethod);
|
repositoryInterface.addMethod(insertMethod);
|
||||||
|
|
||||||
// 19. batchInsert
|
// 8. update
|
||||||
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
|
|
||||||
Method updateMethod = new Method("update");
|
Method updateMethod = new Method("update");
|
||||||
updateMethod.setVisibility(JavaVisibility.PUBLIC);
|
updateMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
updateMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
updateMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
||||||
@@ -340,7 +256,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
updateMethod.setAbstract(true);
|
updateMethod.setAbstract(true);
|
||||||
repositoryInterface.addMethod(updateMethod);
|
repositoryInterface.addMethod(updateMethod);
|
||||||
|
|
||||||
// 21. updateByExampleSelective
|
// 9. updateByExampleSelective
|
||||||
Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective");
|
Method updateByExampleSelectiveMethod = new Method("updateByExampleSelective");
|
||||||
updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC);
|
updateByExampleSelectiveMethod.setVisibility(JavaVisibility.PUBLIC);
|
||||||
updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
updateByExampleSelectiveMethod.setReturnType(new FullyQualifiedJavaType("int"));
|
||||||
@@ -390,27 +306,16 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addField(mapperField);
|
implClass.addField(mapperField);
|
||||||
|
|
||||||
// 原有方法生成逻辑(无修改)
|
// 原有方法生成逻辑(无修改)
|
||||||
generateFindAnyByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
generateFindByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
||||||
generateFindValidByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
generateFindOneMethod(implClass, modelClassName, exampleClassName);
|
||||||
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
|
|
||||||
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
|
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
|
||||||
generateBatchInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
|
|
||||||
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
||||||
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
|
||||||
generateDeleteByIdMethod(implClass, modelClassName, mapperFieldName);
|
generateDeleteByIdMethod(implClass, modelClassName, mapperFieldName);
|
||||||
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
||||||
generateTrashByIdMethod(implClass, modelClassName, mapperFieldName);
|
generateListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateTrashAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
|
generateListWithRowBoundsMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
|
||||||
generateRecoverByIdMethod(implClass, modelClassName, mapperFieldName);
|
generateCountMethod(implClass, modelClassName, exampleClassName, 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);
|
|
||||||
|
|
||||||
return implClass;
|
return implClass;
|
||||||
}
|
}
|
||||||
@@ -467,6 +372,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
|
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + modelClassName));
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
|
implClass.addImportedType(new FullyQualifiedJavaType(modelPackage + "." + exampleClassName));
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType(facadeRepositoryPackage + "." + interfaceName));
|
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("org.springframework.stereotype.Repository"));
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType("javax.annotation.Resource"));
|
implClass.addImportedType(new FullyQualifiedJavaType("javax.annotation.Resource"));
|
||||||
implClass.addImportedType(new FullyQualifiedJavaType("org.slf4j.Logger"));
|
implClass.addImportedType(new FullyQualifiedJavaType("org.slf4j.Logger"));
|
||||||
@@ -474,8 +380,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addImportedType(new FullyQualifiedJavaType("java.util.*"));
|
implClass.addImportedType(new FullyQualifiedJavaType("java.util.*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateFindAnyByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
|
private void generateFindByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("findAnyById");
|
Method method = new Method("findById");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
||||||
@@ -499,54 +405,20 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateFindValidByIdMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, String exampleClassName, boolean hasBLOBColumns) {
|
private void generateFindOneMethod(TopLevelClass implClass, String modelClassName, String exampleClassName) {
|
||||||
Method method = new Method("findValidById");
|
Method method = new Method("findOne");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
method.setReturnType(new FullyQualifiedJavaType(modelClassName));
|
||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "guid"));
|
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
method.addBodyLine(modelClassName + " aDo = null;");
|
method.addBodyLine("example.usePage(1, 1);");
|
||||||
method.addBodyLine(exampleClassName + " example");
|
method.addBodyLine("List<" + modelClassName + "> dataList = list(example);");
|
||||||
method.addBodyLine(" = new " + exampleClassName + "();");
|
method.addBodyLine("if (dataList != null && !dataList.isEmpty()) {");
|
||||||
method.addBodyLine("example.createCriteria()");
|
method.addBodyLine("return dataList.get(0);");
|
||||||
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("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("return aDo;");
|
method.addBodyLine("return null;");
|
||||||
|
|
||||||
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;");
|
|
||||||
|
|
||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
@@ -581,7 +453,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method.addBodyLine("aDo.setIsDelete(0);");
|
method.addBodyLine("aDo.setIsDelete(0);");
|
||||||
method.addBodyLine("aDo.setIsHidden(0);");
|
|
||||||
method.addBodyLine("aDo.setDeleteToken(\"VALID\");");
|
method.addBodyLine("aDo.setDeleteToken(\"VALID\");");
|
||||||
method.addBodyLine("aDo.setDataVersion(1);");
|
method.addBodyLine("aDo.setDataVersion(1);");
|
||||||
method.addBodyLine("aDo.setCreateTime(new Date());");
|
method.addBodyLine("aDo.setCreateTime(new Date());");
|
||||||
@@ -604,63 +475,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
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,
|
private void generateUpdateMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
||||||
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
|
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("update");
|
Method method = new Method("update");
|
||||||
@@ -697,13 +511,19 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
}
|
}
|
||||||
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
|
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
|
if (isOptimisticLockEnable()) {
|
||||||
method.addBodyLine("if (lockDataVersion == null) {");
|
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
|
||||||
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
|
method.addBodyLine("if (lockDataVersion == null) {");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
|
||||||
method.addBodyLine("updateWhere.createCriteria()");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
|
method.addBodyLine("updateWhere.createCriteria()");
|
||||||
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
|
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.setDataVersion(aDo.getDataVersion() + 1);");
|
||||||
method.addBodyLine("aDo.setUpdateTime(new Date());");
|
method.addBodyLine("aDo.setUpdateTime(new Date());");
|
||||||
method.addBodyLine("// update data version");
|
method.addBodyLine("// update data version");
|
||||||
@@ -735,7 +555,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
|
|
||||||
// 方法体
|
// 方法体
|
||||||
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
|
|
||||||
method.addBodyLine("List<Long> guidList = " + mapperFieldName);
|
method.addBodyLine("List<Long> guidList = " + mapperFieldName);
|
||||||
@@ -746,7 +566,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("example = new " + exampleClassName + "();");
|
method.addBodyLine("example = new " + exampleClassName + "();");
|
||||||
method.addBodyLine("example.createCriteria()");
|
method.addBodyLine("example.createCriteria()");
|
||||||
method.addBodyLine(" .andIsDeleteEqualTo(0)");
|
method.addBodyLine(" .andIsDeleteEqualTo(0)");
|
||||||
method.addBodyLine(" .andIsHiddenEqualTo(0)");
|
|
||||||
method.addBodyLine(" .andGuidIn(guidList);");
|
method.addBodyLine(" .andGuidIn(guidList);");
|
||||||
if (isChangeLogEnable()) {
|
if (isChangeLogEnable()) {
|
||||||
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
|
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
|
||||||
@@ -775,7 +594,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("record.setDataVersion(100);");
|
method.addBodyLine("record.setDataVersion(100);");
|
||||||
method.addBodyLine("// It is not supported to directly modify the following columns");
|
method.addBodyLine("// It is not supported to directly modify the following columns");
|
||||||
method.addBodyLine("record.setUpdateTime(new Date());");
|
method.addBodyLine("record.setUpdateTime(new Date());");
|
||||||
method.addBodyLine("record.setIsHidden(null);");
|
|
||||||
method.addBodyLine("record.setIsDelete(null);");
|
method.addBodyLine("record.setIsDelete(null);");
|
||||||
method.addBodyLine("record.setDeleteToken(null);");
|
method.addBodyLine("record.setDeleteToken(null);");
|
||||||
method.addBodyLine("record.setCreateTime(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("long"), "id"));
|
||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType("boolean"), "release"));
|
method.addParameter(new Parameter(new FullyQualifiedJavaType("boolean"), "release"));
|
||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
method.addBodyLine(modelClassName + " aDo = findValidById(id);");
|
method.addBodyLine(modelClassName + " aDo = findById(id);");
|
||||||
method.addBodyLine("if (aDo == null) {");
|
method.addBodyLine("if (aDo == null) {");
|
||||||
method.addBodyLine("return 0;");
|
method.addBodyLine("return 0;");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
@@ -824,65 +642,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
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) {
|
private void generateDeleteAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("deleteAll");
|
Method method = new Method("deleteAll");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
@@ -897,7 +656,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
|
method.addBodyLine("return " + mapperFieldName + ".deleteByExample(example);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(1);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("List<Long> guidList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
|
method.addBodyLine("List<Long> guidList = " + mapperFieldName + ".selectPrimaryKeyByExample(example);");
|
||||||
method.addBodyLine("if (guidList.isEmpty()) {");
|
method.addBodyLine("if (guidList.isEmpty()) {");
|
||||||
@@ -921,116 +680,9 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTrashAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
|
||||||
Method method = new Method("trashAll");
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
method.addAnnotation("@Override");
|
Method method = new Method("list");
|
||||||
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,
|
|
||||||
String mapperFieldName, boolean hasBLOBColumns) {
|
|
||||||
Method method = new Method("getValidList");
|
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
||||||
@@ -1038,7 +690,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("List<" + modelClassName + "> result = null;");
|
method.addBodyLine("List<" + modelClassName + "> result = null;");
|
||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
@@ -1105,17 +757,23 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
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) {
|
String mapperFieldName, boolean hasBLOBColumns) {
|
||||||
Method method = new Method("getTrashList");
|
Method method = new Method("list");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
method.setReturnType(new FullyQualifiedJavaType("List<" + modelClassName + ">"));
|
||||||
method.addParameter(new Parameter(new FullyQualifiedJavaType(exampleClassName), "example"));
|
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.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("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(1);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("List<" + modelClassName + "> result = null;");
|
method.addBodyLine("List<" + modelClassName + "> result = null;");
|
||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
@@ -1137,7 +795,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list primary key 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(" \"\\n\\t|-> use time:\" + findPrimaryKeyTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1172,7 +830,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addBodyLine("if (example.getLimitString() != null) {");
|
method.addBodyLine("if (example.getLimitString() != null) {");
|
||||||
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list 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(" \"\\n\\t|-> use time:\" + useTime + \"ms\" +");
|
||||||
method.addBodyLine(" exampleString +");
|
method.addBodyLine(" exampleString +");
|
||||||
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
|
||||||
@@ -1182,8 +840,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
implClass.addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateCountByValidMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
private void generateCountMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
|
||||||
Method method = new Method("countByValid");
|
Method method = new Method("count");
|
||||||
method.addAnnotation("@Override");
|
method.addAnnotation("@Override");
|
||||||
method.setVisibility(JavaVisibility.PUBLIC);
|
method.setVisibility(JavaVisibility.PUBLIC);
|
||||||
method.setReturnType(new FullyQualifiedJavaType("long"));
|
method.setReturnType(new FullyQualifiedJavaType("long"));
|
||||||
@@ -1191,7 +849,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
method.addException(new FullyQualifiedJavaType("Throwable"));
|
method.addException(new FullyQualifiedJavaType("Throwable"));
|
||||||
|
|
||||||
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
method.addBodyLine("for (" + exampleClassName + ".Criteria criteria : example.getOredCriteria()) {");
|
||||||
method.addBodyLine("criteria.andIsDeleteEqualTo(0).andIsHiddenEqualTo(0);");
|
method.addBodyLine("criteria.andIsDeleteEqualTo(0);");
|
||||||
method.addBodyLine("}");
|
method.addBodyLine("}");
|
||||||
method.addBodyLine("long startTime = new Date().getTime();");
|
method.addBodyLine("long startTime = new Date().getTime();");
|
||||||
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
|
||||||
@@ -1215,73 +873,6 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
|
|||||||
implClass.addMethod(method);
|
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) {
|
private String upperFirst(String str) {
|
||||||
if (str == null || str.isEmpty()) {
|
if (str == null || str.isEmpty()) {
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
Reference in New Issue
Block a user