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