From 29945567cf935bea596c838ed8acd88912f2df0e Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Tue, 24 Sep 2019 15:29:17 +0800 Subject: [PATCH] backup --- .../hsweb-authorization-api/pom.xml | 8 +- .../web/authorization/Authentication.java | 6 +- .../authorization/AuthenticationHolder.java | 36 +- .../AuthenticationInitializeService.java | 2 +- .../authorization/AuthenticationManager.java | 8 +- .../AuthenticationPredicate.java | 10 - .../authorization/AuthenticationSupplier.java | 6 +- .../CompositeAuthentication.java | 91 +++ .../AuthorizeDefinitionInitializedEvent.java | 2 +- .../AbstractAuthorizationEvent.java | 2 +- .../AuthorizationBeforeEvent.java | 2 +- .../AuthorizationDecodeEvent.java | 2 +- .../event => events}/AuthorizationEvent.java | 2 +- .../AuthorizationExitEvent.java | 2 +- .../AuthorizationFailedEvent.java | 2 +- .../AuthorizationInitializeEvent.java | 2 +- .../AuthorizationSuccessEvent.java | 2 +- .../AuthorizingHandleBeforeEvent.java | 2 +- .../token/ThirdPartAuthenticationManager.java | 3 +- .../UserTokenAuthenticationSupplier.java | 32 +- .../token/event/UserTokenChangedEvent.java | 2 +- .../token/event/UserTokenCreatedEvent.java | 2 +- .../token/event/UserTokenRemovedEvent.java | 2 +- .../authorization/AuthenticationTests.java | 31 +- .../hsweb-authorization-basic/pom.xml | 2 +- .../handler/DefaultAuthorizingHandler.java | 2 +- .../handler/UserAllowPermissionHandler.java | 2 +- .../basic/web/AuthorizationController.java | 3 +- .../authorization/basic/web/UserOnSignIn.java | 5 +- .../basic/web/UserOnSignOut.java | 2 +- .../UserAllowPermissionHandlerTest.groovy | 2 +- .../hsweb-authorization-jwt/pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-authorization-oauth2-client/pom.xml | 2 +- .../hsweb-authorization-oauth2-core/pom.xml | 2 +- .../hsweb-authorization-oauth2/pom.xml | 2 +- hsweb-authorization/pom.xml | 2 +- hsweb-boost/hsweb-boost-aop/pom.xml | 2 +- hsweb-boost/hsweb-boost-excel/pom.xml | 2 +- hsweb-boost/hsweb-boost-ftp/pom.xml | 2 +- hsweb-boost/pom.xml | 2 +- hsweb-commons/hsweb-commons-bean/pom.xml | 2 +- .../hsweb-commons-controller/pom.xml | 2 +- .../web/controller/CreateController.java | 16 +- hsweb-commons/hsweb-commons-crud/pom.xml | 35 ++ .../web/crud/entity/PagerResult.java | 64 ++ .../web/crud/entity/QueryParamEntity.java | 140 +++++ .../web/crud/entity/TermExpressionParser.java | 184 ++++++ .../service/DefaultReactiveCrudService.java | 16 + .../web/crud/service/ReactiveCrudService.java | 72 +++ .../hsweb-commons-dao-api/pom.xml | 2 +- .../hsweb-commons-dao-mybatis/README.md | 224 ------- .../hsweb-commons-dao-mybatis/pom.xml | 93 --- .../dao/mybatis/EnumDictHandlerRegister.java | 158 ----- .../dao/mybatis/MyBatisAutoConfiguration.java | 125 ---- .../mybatis/MybatisDaoAutoConfiguration.java | 98 ---- .../web/dao/mybatis/MybatisEntityFactory.java | 40 -- .../dao/mybatis/MybatisMapperCustomizer.java | 13 - .../web/dao/mybatis/MybatisProperties.java | 153 ----- .../web/dao/mybatis/MybatisUtils.java | 42 -- .../mybatis/builder/EasyOrmSqlBuilder.java | 546 ------------------ .../dao/mybatis/builder/InsertSqlBuilder.java | 54 -- .../web/dao/mybatis/builder/SqlBuilder.java | 28 - .../dao/mybatis/builder/SqlParamParser.java | 70 --- .../web/dao/mybatis/builder/TypeUtils.java | 38 -- .../dao/mybatis/builder/UpdateSqlBuilder.java | 59 -- .../builder/jpa/JpaAnnotationParser.java | 194 ------- ...micDataSourceSqlSessionFactoryBuilder.java | 30 - .../DynamicSpringManagedTransaction.java | 207 ------- .../dynamic/DynamicSqlSessionFactory.java | 150 ----- .../dao/mybatis/handler/JsonArrayHandler.java | 88 --- .../dao/mybatis/handler/JsonMapHandler.java | 85 --- .../dao/mybatis/handler/JsonSetHandler.java | 86 --- .../handler/NumberBooleanTypeHandler.java | 49 -- .../mapper/AbstractSqlTermCustomizer.java | 65 --- .../dao/mybatis/mapper/ChangedTermValue.java | 20 - .../dao/mybatis/mapper/SqlTermCustomizer.java | 13 - .../TreeStructureSqlTermCustomizer.java | 85 --- .../mapper/dict/DictInTermTypeMapper.java | 130 ----- .../mapper/dict/DictTermTypeMapper.java | 103 ---- .../web/dao/mybatis/plgins/pager/Pager.java | 83 --- .../plgins/pager/PagerInterceptor.java | 79 --- .../spring-configuration-metadata.json | 151 ----- .../main/resources/META-INF/spring.factories | 3 - .../dao/mybatis/mappers/basic/BasicMapper.xml | 123 ---- .../hswebframework/web/dao/crud/DataType.java | 18 - .../web/dao/crud/NestEntity.java | 17 - .../web/dao/crud/TestApplication.java | 49 -- .../hswebframework/web/dao/crud/TestCrud.java | 106 ---- .../hswebframework/web/dao/crud/TestDao.java | 13 - .../web/dao/crud/TestEntity.java | 53 -- .../mybatis/builder/SqlParamParserTest.java | 74 --- .../dao/mybatis/builder/TestQueryEntity.java | 20 - .../mybatis/builder/jpa/AbstractEntity.java | 20 - .../builder/jpa/JpaAnnotationParserTest.java | 25 - .../dao/mybatis/builder/jpa/TestEntity.java | 29 - .../src/test/resources/application.yml | 26 - .../hswebframework/web/dao/test/TestDao.xml | 82 --- hsweb-commons/hsweb-commons-dao/pom.xml | 2 +- hsweb-commons/hsweb-commons-entity/pom.xml | 2 +- .../web/commons/entity/TreeSupportEntity.java | 2 +- hsweb-commons/hsweb-commons-model/pom.xml | 2 +- .../hsweb-commons-service-api/pom.xml | 2 +- .../hsweb-commons-service-oauth2/pom.xml | 31 - .../oauth2/AbstractOAuth2CrudService.java | 59 -- .../web/service/oauth2/OAuth2CrudService.java | 8 - .../service/oauth2/OAuth2DeleteService.java | 10 - .../service/oauth2/OAuth2InsertService.java | 11 - .../oauth2/OAuth2QueryByEntityService.java | 32 - .../service/oauth2/OAuth2QueryService.java | 36 -- .../service/oauth2/OAuth2ServiceSupport.java | 33 -- .../service/oauth2/OAuth2UpdateService.java | 24 - .../AbstractOAuth2CrudServiceTests.java | 175 ------ .../web/service/oauth2/MockOAuth2Request.java | 111 ---- .../service/oauth2/MockOAuth2Response.java | 66 --- .../web/service/oauth2/TestEntity.java | 20 - .../web/service/oauth2/TestEntityService.java | 13 - .../hsweb-commons-service-simple/pom.xml | 13 +- hsweb-commons/hsweb-commons-service/pom.xml | 3 +- hsweb-commons/hsweb-commons-utils/pom.xml | 6 +- .../hswebframework/web/context/Context.java | 15 + .../web/context/ContextKey.java | 32 + .../web/context/ContextUtils.java | 53 ++ .../web/context/MapContext.java | 33 ++ .../web/HttpParameterConverterTests.java | 2 +- hsweb-commons/pom.xml | 3 +- .../hsweb-concurrent-async-job/README.md | 24 - .../hsweb-concurrent-async-job/pom.xml | 54 -- .../web/async/AsyncJobException.java | 41 -- .../web/async/AsyncJobService.java | 13 - .../AsyncJobServiceAutoConfiguration.java | 47 -- .../web/async/BatchAsyncJobContainer.java | 22 - .../async/SpringTransactionSupportJob.java | 55 -- .../SpringTransactionSupportJobWrapper.java | 24 - .../TransactionBatchAsyncJobContainer.java | 136 ----- .../TransactionSupportAsyncJobService.java | 30 - .../web/async/TransactionSupportJob.java | 20 - .../async/TransactionSupportJobWrapper.java | 19 - .../main/resources/META-INF/spring.factories | 3 - .../src/test/resources/application.yml | 18 - .../hsweb-concurrent-cache/pom.xml | 44 -- .../FixUseSupperClassAutoConfiguration.java | 22 - .../cache/monitor/MonitorSupportCache.java | 22 - .../FixUseSupperClassAnnotationParser.java | 296 ---------- ...ixUseSupperClassCacheAnnotationParser.java | 17 - ...FixUseSupperClassCacheOperationSource.java | 193 ------- ...pperClassFallbackCacheOperationSource.java | 198 ------- .../main/resources/META-INF/spring.factories | 3 - .../hsweb-concurrent-counter-api/pom.xml | 46 -- .../counter/AbstractBoomFilterManager.java | 25 - .../counter/AbstractCounterManager.java | 25 - .../web/concurrent/counter/BloomFilter.java | 19 - .../counter/BloomFilterManager.java | 6 - .../web/concurrent/counter/Counter.java | 42 -- .../counter/CounterAutoConfiguration.java | 28 - .../concurrent/counter/CounterManager.java | 27 - .../counter/GuavaBloomFilterManager.java | 32 - .../web/concurrent/counter/SimpleCounter.java | 50 -- .../counter/SimpleCounterManager.java | 11 - .../main/resources/META-INF/spring.factories | 3 - .../counter/GuavaBloomFilterManagerTest.java | 25 - .../hsweb-concurrent-counter-redis/pom.xml | 31 - .../redis/RedisBloomFilterManager.java | 31 - .../redis/RedisCounterAutoConfiguration.java | 32 - .../web/counter/redis/RedissonCounter.java | 58 -- .../counter/redis/RedissonCounterManager.java | 27 - .../main/resources/META-INF/spring.factories | 3 - .../hsweb-concurrent-counter/pom.xml | 39 -- .../hsweb-concurrent-lock-api/pom.xml | 23 - .../concurrent/lock/AbstractLockManager.java | 43 -- .../web/concurrent/lock/LockManager.java | 32 - .../concurrent/lock/SimpleLockManager.java | 27 - .../web/concurrent/lock/annotation/Lock.java | 65 --- .../concurrent/lock/annotation/ReadLock.java | 64 -- .../concurrent/lock/annotation/WriteLock.java | 75 --- .../web/concurrent/lok/SimpleLockTests.java | 79 --- .../hsweb-concurrent-lock-redis/pom.xml | 34 -- .../lock/redis/RedissonLockManager.java | 31 - .../lock/redis/RedissonLockTest.java | 102 ---- .../hsweb-concurrent-lock-starter/pom.xml | 49 -- .../lock/starter/AopLockAdvisor.java | 107 ---- .../starter/LockManagerAutoConfiguration.java | 27 - .../lock/starter/LockProcessor.java | 128 ---- .../RedisLockManagerAutoConfiguration.java | 24 - .../main/resources/META-INF/spring.factories | 4 - .../lock/starter/LockAnnotationTest.java | 79 --- .../concurrent/lock/starter/LockService.java | 58 -- .../lock/starter/TestApplication.java | 35 -- .../src/test/resources/application.yml | 12 - .../hsweb-concurrent-lock/pom.xml | 40 -- .../hsweb-concurrent-rate-limiter-api/pom.xml | 23 - .../AbstractRateLimiterManager.java | 26 - .../concurrent/GuavaRateLimiterManager.java | 27 - .../web/concurrent/RateLimiter.java | 17 - .../web/concurrent/RateLimiterManager.java | 12 - .../concurrent/annotation/RateLimiter.java | 39 -- .../GuavaRateLimiterManagerTest.java | 28 - .../pom.xml | 52 -- .../web/concurent/RateLimiterAopAdvisor.java | 69 --- .../RateLimiterAutoConfiguration.java | 30 - .../main/resources/META-INF/spring.factories | 3 - .../RateLimiterAopAdvisorTest.groovy | 48 -- .../web/concurent/TestApplication.java | 11 - .../web/concurent/TestService.java | 30 - .../hsweb-concurrent-rate-limiter/pom.xml | 20 - hsweb-concurrent/pom.xml | 42 -- hsweb-core/pom.xml | 4 +- hsweb-datasource/hsweb-datasource-api/pom.xml | 2 +- hsweb-datasource/hsweb-datasource-jta/pom.xml | 2 +- hsweb-datasource/hsweb-datasource-web/pom.xml | 2 +- hsweb-datasource/pom.xml | 2 +- .../hsweb-access-logging-aop/pom.xml | 2 +- .../hsweb-access-logging-api/pom.xml | 2 +- hsweb-logging/pom.xml | 2 +- .../hsweb-spring-boot-starter/pom.xml | 2 +- hsweb-starter/pom.xml | 2 +- .../hsweb-system-authorization-api/pom.xml | 2 +- .../hsweb-system-authorization-local/pom.xml | 2 +- .../simple/SimpleAuthenticationManager.java | 1 - .../SimpleAuthorizationSettingService.java | 6 +- .../pom.xml | 2 +- .../hsweb-system-authorization-web/pom.xml | 2 +- .../hsweb-system-authorization/pom.xml | 2 +- .../hsweb-system-config-api/pom.xml | 2 +- .../hsweb-system-config-local/pom.xml | 2 +- .../hsweb-system-config-starter/pom.xml | 2 +- .../hsweb-system-config-web/pom.xml | 2 +- hsweb-system/hsweb-system-config/pom.xml | 2 +- .../hsweb-system-dashboard-api/pom.xml | 2 +- .../hsweb-system-dashboard-local/pom.xml | 2 +- .../hsweb-system-dashboard-starter/pom.xml | 2 +- .../hsweb-system-dashboard-web/pom.xml | 2 +- hsweb-system/hsweb-system-dashboard/pom.xml | 2 +- .../hsweb-system-database-manager-api/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-system-database-manager-web/pom.xml | 2 +- .../hsweb-system-database-manager/pom.xml | 2 +- .../hsweb-system-datasource-api/pom.xml | 2 +- .../hsweb-system-datasource-local/pom.xml | 2 +- .../hsweb-system-datasource-starter/pom.xml | 2 +- .../hsweb-system-datasource-web/pom.xml | 2 +- hsweb-system/hsweb-system-datasource/pom.xml | 2 +- hsweb-system/hsweb-system-dev-tools/pom.xml | 2 +- .../hsweb-system-dictionary-api/pom.xml | 2 +- .../hsweb-system-dictionary-local/pom.xml | 2 +- .../hsweb-system-dictionary-starter/pom.xml | 2 +- .../hsweb-system-dictionary-web/pom.xml | 2 +- hsweb-system/hsweb-system-dictionary/pom.xml | 2 +- .../hsweb-system-dynamic-form-api/pom.xml | 2 +- .../hsweb-system-dynamic-form-local/pom.xml | 2 +- .../hsweb-system-dynamic-form-starter/pom.xml | 2 +- .../hsweb-system-dynamic-form-web/pom.xml | 2 +- .../hsweb-system-dynamic-form/pom.xml | 2 +- .../hsweb-system-file-api/pom.xml | 2 +- .../hsweb-system-file-local/pom.xml | 2 +- .../hsweb-system-file-oauth2/pom.xml | 2 +- .../hsweb-system-file-starter/pom.xml | 2 +- .../hsweb-system-file-web/pom.xml | 2 +- hsweb-system/hsweb-system-file/pom.xml | 2 +- .../hsweb-system-oauth2-client-api/pom.xml | 2 +- .../hsweb-system-oauth2-client-local/pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-system-oauth2-client-web/pom.xml | 2 +- .../hsweb-system-oauth2-client/pom.xml | 2 +- .../hsweb-system-oauth2-server-local/pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-system-oauth2-server-web/pom.xml | 2 +- .../hsweb-system-oauth2-server/pom.xml | 2 +- .../hsweb-system-organizational-api/pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-system-organizational-local/pom.xml | 2 +- .../pom.xml | 2 +- .../hsweb-system-organizational-web/pom.xml | 2 +- .../hsweb-system-organizational/pom.xml | 2 +- .../hsweb-system-schedule-api/pom.xml | 2 +- .../hsweb-system-schedule-local/pom.xml | 2 +- .../hsweb-system-schedule-starter/pom.xml | 2 +- .../hsweb-system-schedule-web/pom.xml | 2 +- hsweb-system/hsweb-system-schedule/pom.xml | 2 +- .../hsweb-system-script-api/pom.xml | 2 +- .../hsweb-system-script-local/pom.xml | 2 +- .../hsweb-system-script-starter/pom.xml | 2 +- .../hsweb-system-script-web/pom.xml | 2 +- hsweb-system/hsweb-system-script/pom.xml | 2 +- .../hsweb-system-template-api/pom.xml | 2 +- .../hsweb-system-template-local/pom.xml | 2 +- .../hsweb-system-template-starter/pom.xml | 2 +- .../hsweb-system-template-web/pom.xml | 2 +- hsweb-system/hsweb-system-template/pom.xml | 2 +- .../hsweb-system-workflow-local/pom.xml | 2 +- .../hsweb-system-workflow-starter/pom.xml | 2 +- hsweb-system/hsweb-system-workflow/pom.xml | 2 +- hsweb-system/pom.xml | 2 +- hsweb-tests/pom.xml | 2 +- .../hsweb-thirdparty-ueditor/pom.xml | 2 +- hsweb-thirdparty/pom.xml | 2 +- pom.xml | 57 +- 298 files changed, 986 insertions(+), 8380 deletions(-) create mode 100644 hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/CompositeAuthentication.java rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AbstractAuthorizationEvent.java (97%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationBeforeEvent.java (94%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationDecodeEvent.java (95%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationEvent.java (93%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationExitEvent.java (95%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationFailedEvent.java (96%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationInitializeEvent.java (79%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizationSuccessEvent.java (97%) rename hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/{listener/event => events}/AuthorizingHandleBeforeEvent.java (95%) create mode 100644 hsweb-commons/hsweb-commons-crud/pom.xml create mode 100644 hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/PagerResult.java create mode 100644 hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/QueryParamEntity.java create mode 100644 hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/TermExpressionParser.java create mode 100644 hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/DefaultReactiveCrudService.java create mode 100644 hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/ReactiveCrudService.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/README.md delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/pom.xml delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/EnumDictHandlerRegister.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MyBatisAutoConfiguration.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisDaoAutoConfiguration.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisEntityFactory.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisMapperCustomizer.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisProperties.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisUtils.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/InsertSqlBuilder.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlBuilder.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParser.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/TypeUtils.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/UpdateSqlBuilder.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParser.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSpringManagedTransaction.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSqlSessionFactory.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonArrayHandler.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonMapHandler.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonSetHandler.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/NumberBooleanTypeHandler.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/AbstractSqlTermCustomizer.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/ChangedTermValue.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/SqlTermCustomizer.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/TreeStructureSqlTermCustomizer.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictInTermTypeMapper.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictTermTypeMapper.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/Pager.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/PagerInterceptor.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring-configuration-metadata.json delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/basic/BasicMapper.xml delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/DataType.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/NestEntity.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestApplication.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestCrud.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestDao.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestEntity.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParserTest.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/TestQueryEntity.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/AbstractEntity.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParserTest.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/TestEntity.java delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/application.yml delete mode 100644 hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/org/hswebframework/web/dao/test/TestDao.xml delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2CrudService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2DeleteService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2InsertService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryByEntityService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2UpdateService.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Request.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Response.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntity.java delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntityService.java create mode 100644 hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/Context.java create mode 100644 hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextKey.java create mode 100644 hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextUtils.java create mode 100644 hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/MapContext.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/README.md delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobException.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobService.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobServiceAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/BatchAsyncJobContainer.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJob.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJobWrapper.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionBatchAsyncJobContainer.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportAsyncJobService.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJob.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJobWrapper.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/test/resources/application.yml delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/FixUseSupperClassAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/monitor/MonitorSupportCache.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassAnnotationParser.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheAnnotationParser.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheOperationSource.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassFallbackCacheOperationSource.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-cache/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractBoomFilterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractCounterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/Counter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/test/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManagerTest.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisBloomFilterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisCounterAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-counter/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/AbstractLockManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/LockManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/SimpleLockManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/Lock.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/ReadLock.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/WriteLock.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/test/java/org/hswebframework/web/concurrent/lok/SimpleLockTests.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/main/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/test/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockTest.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/AopLockAdvisor.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockManagerAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockProcessor.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/RedisLockManagerAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockAnnotationTest.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockService.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/TestApplication.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/resources/application.yml delete mode 100644 hsweb-concurrent/hsweb-concurrent-lock/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/AbstractRateLimiterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/GuavaRateLimiterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiterManager.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/annotation/RateLimiter.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/test/java/org/hswebframework/web/concurrent/GuavaRateLimiterManagerTest.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/pom.xml delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAopAdvisor.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAutoConfiguration.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/resources/META-INF/spring.factories delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/RateLimiterAopAdvisorTest.groovy delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestApplication.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestService.java delete mode 100644 hsweb-concurrent/hsweb-concurrent-rate-limiter/pom.xml delete mode 100644 hsweb-concurrent/pom.xml diff --git a/hsweb-authorization/hsweb-authorization-api/pom.xml b/hsweb-authorization/hsweb-authorization-api/pom.xml index d7bdc7e7e..2373bb980 100644 --- a/hsweb-authorization/hsweb-authorization-api/pom.xml +++ b/hsweb-authorization/hsweb-authorization-api/pom.xml @@ -5,7 +5,7 @@ hsweb-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 @@ -36,6 +36,12 @@ spring-webmvc true + + + io.projectreactor + reactor-test + test + io.swagger swagger-annotations diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java index 273ff77db..f5e259b5f 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java @@ -17,6 +17,8 @@ package org.hswebframework.web.authorization; +import reactor.core.publisher.Mono; + import java.io.Serializable; import java.util.*; @@ -50,8 +52,8 @@ public interface Authentication extends Serializable { * @see Optional * @see AuthenticationHolder */ - static Optional current() { - return Optional.ofNullable(AuthenticationHolder.get()); + static Mono current() { + return AuthenticationHolder.get(); } /** diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationHolder.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationHolder.java index 3d2285264..80d5ad4a8 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationHolder.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationHolder.java @@ -19,6 +19,8 @@ package org.hswebframework.web.authorization; import org.hswebframework.web.ThreadLocalUtils; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; @@ -26,6 +28,7 @@ import java.util.Objects; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Function; +import java.util.stream.Collectors; /** * 权限获取器,用于静态方式获取当前登录用户的权限信息. @@ -45,31 +48,23 @@ import java.util.function.Function; public final class AuthenticationHolder { private static final List suppliers = new ArrayList<>(); - private static final String CURRENT_USER_ID_KEY = Authentication.class.getName() + "_current_id"; - private static final ReadWriteLock lock = new ReentrantReadWriteLock(); - private static Authentication get(Function function) { - lock.readLock().lock(); - try { - return suppliers.stream() - .map(function) - .filter(Objects::nonNull) - .findFirst() - .orElse(null); - } finally { - lock.readLock().unlock(); - } + private static Mono get(Function> function) { + + return Flux.concat(suppliers.stream() + .map(function) + .collect(Collectors.toList())) + .reduceWith(CompositeAuthentication::new, CompositeAuthentication::merge) + .filter(CompositeAuthentication::isNotEmpty) + .map(Authentication.class::cast); } /** * @return 当前登录的用户权限信息 */ - public static Authentication get() { - String currentId = ThreadLocalUtils.get(CURRENT_USER_ID_KEY); - if (currentId != null) { - return get(currentId); - } + public static Mono get() { + return get(AuthenticationSupplier::get); } @@ -79,7 +74,7 @@ public final class AuthenticationHolder { * @param userId 用户ID * @return 权限信息 */ - public static Authentication get(String userId) { + public static Mono get(String userId) { return get(supplier -> supplier.get(userId)); } @@ -97,7 +92,4 @@ public final class AuthenticationHolder { } } - public static void setCurrentUserId(String id) { - ThreadLocalUtils.put(AuthenticationHolder.CURRENT_USER_ID_KEY, id); - } } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationInitializeService.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationInitializeService.java index ead0aa821..99c66aff5 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationInitializeService.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationInitializeService.java @@ -18,7 +18,7 @@ package org.hswebframework.web.authorization; -import org.hswebframework.web.authorization.listener.event.AuthorizationInitializeEvent; +import org.hswebframework.web.authorization.events.AuthorizationInitializeEvent; /** * 授权信息初始化服务接口,使用该接口初始化用的权限信息 diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationManager.java index b2edd552d..547760ffb 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationManager.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationManager.java @@ -18,6 +18,8 @@ package org.hswebframework.web.authorization; +import reactor.core.publisher.Mono; + import java.io.Serializable; import java.util.Map; @@ -36,7 +38,7 @@ public interface AuthenticationManager { * @param request 授权请求 * @return 授权成功则返回用户权限信息 */ - Authentication authenticate(AuthenticationRequest request); + Mono authenticate(AuthenticationRequest request); /** * 根据用户ID获取权限信息 @@ -44,7 +46,7 @@ public interface AuthenticationManager { * @param userId 用户ID * @return 权限信息 */ - Authentication getByUserId(String userId); + Mono getByUserId(String userId); /** * 同步授权信息,在调用了{@link Authentication#setAttribute(String, Serializable)}或者 @@ -56,5 +58,5 @@ public interface AuthenticationManager { * @param authentication 要同步的权限信息 * @return 同步后的权限信息 */ - Authentication sync(Authentication authentication); + Mono sync(Authentication authentication); } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationPredicate.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationPredicate.java index ccbb83d98..3702669b6 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationPredicate.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationPredicate.java @@ -44,17 +44,7 @@ public interface AuthenticationPredicate extends Predicate { return (t) -> test(t) || other.test(t); } - default boolean test() { - return Authentication.current() - .map(this::test) - .orElse(false); - } - default void assertHas() { - if (!test()) { - throw new AccessDenyException(); - } - } default void assertHas(Authentication authentication) { if (!test(authentication)) { diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationSupplier.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationSupplier.java index 353e92ac0..ad24c570d 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationSupplier.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationSupplier.java @@ -17,6 +17,8 @@ package org.hswebframework.web.authorization; +import reactor.core.publisher.Mono; + import java.util.function.Supplier; /** @@ -25,6 +27,6 @@ import java.util.function.Supplier; * @see Authentication * @see AuthenticationHolder */ -public interface AuthenticationSupplier extends Supplier { - Authentication get(String userId); +public interface AuthenticationSupplier extends Supplier> { + Mono get(String userId); } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/CompositeAuthentication.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/CompositeAuthentication.java new file mode 100644 index 000000000..c6b6d2baf --- /dev/null +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/CompositeAuthentication.java @@ -0,0 +1,91 @@ +package org.hswebframework.web.authorization; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class CompositeAuthentication implements Authentication { + + private Map userAuthentication = new ConcurrentHashMap<>(); + + private String currentUser; + + public boolean isEmpty() { + return userAuthentication.isEmpty(); + } + + public boolean isNotEmpty() { + return !isEmpty(); + } + + + @Override + public User getUser() { + + return userAuthentication + .get(currentUser) + .getUser(); + } + + @Override + public List getRoles() { + return userAuthentication.values() + .stream() + .map(Authentication::getRoles) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + @Override + public List getPermissions() { + return userAuthentication.values() + .stream() + .map(Authentication::getPermissions) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + @Override + public Optional getAttribute(String name) { + return userAuthentication.values() + .stream() + .map(a -> a.getAttribute(name)) + .filter(Optional::isPresent) + .findAny() + .flatMap(Function.identity()); + } + + @Override + public void setAttribute(String name, Serializable object) { + + } + + @Override + public void setAttributes(Map attributes) { + + } + + @Override + public T removeAttributes(String name) { + return null; + } + + @Override + public Map getAttributes() { + return null; + } + + public CompositeAuthentication merge(Authentication authentication) { + String userId = authentication.getUser().getId(); + if (currentUser == null) { + currentUser = userId; + } + userAuthentication.put(userId, authentication); + return this; + } +} diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java index 5937c6bdf..2c3b14ccc 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/AuthorizeDefinitionInitializedEvent.java @@ -1,6 +1,6 @@ package org.hswebframework.web.authorization.define; -import org.hswebframework.web.authorization.listener.event.AuthorizationEvent; +import org.hswebframework.web.authorization.events.AuthorizationEvent; import org.springframework.context.ApplicationEvent; import java.util.List; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AbstractAuthorizationEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AbstractAuthorizationEvent.java similarity index 97% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AbstractAuthorizationEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AbstractAuthorizationEvent.java index 907c81f41..61e9d9483 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AbstractAuthorizationEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AbstractAuthorizationEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import org.springframework.context.ApplicationEvent; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationBeforeEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationBeforeEvent.java similarity index 94% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationBeforeEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationBeforeEvent.java index 1c7672bd8..eac0e52ef 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationBeforeEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationBeforeEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import java.util.function.Function; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationDecodeEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationDecodeEvent.java similarity index 95% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationDecodeEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationDecodeEvent.java index ecd860087..9ee6ae170 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationDecodeEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationDecodeEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import java.util.function.Function; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationEvent.java similarity index 93% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationEvent.java index b3964080c..506fa4006 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; /** * 授权事件 diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationExitEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationExitEvent.java similarity index 95% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationExitEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationExitEvent.java index 5874ba914..3e620cd74 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationExitEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationExitEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import org.hswebframework.web.authorization.Authentication; import org.springframework.context.ApplicationEvent; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationFailedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationFailedEvent.java similarity index 96% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationFailedEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationFailedEvent.java index cef33618a..cf1f019f8 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationFailedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationFailedEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import java.util.function.Function; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationInitializeEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationInitializeEvent.java similarity index 79% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationInitializeEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationInitializeEvent.java index 37a412242..6144f6c5f 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationInitializeEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationInitializeEvent.java @@ -1,4 +1,4 @@ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationSuccessEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationSuccessEvent.java similarity index 97% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationSuccessEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationSuccessEvent.java index 700a5033c..578935256 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizationSuccessEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizationSuccessEvent.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import org.hswebframework.web.authorization.Authentication; import org.springframework.context.ApplicationEvent; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizingHandleBeforeEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizingHandleBeforeEvent.java similarity index 95% rename from hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizingHandleBeforeEvent.java rename to hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizingHandleBeforeEvent.java index 1b6767567..3eb6d2876 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/listener/event/AuthorizingHandleBeforeEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/events/AuthorizingHandleBeforeEvent.java @@ -1,4 +1,4 @@ -package org.hswebframework.web.authorization.listener.event; +package org.hswebframework.web.authorization.events; import org.hswebframework.web.authorization.define.AuthorizingContext; import org.hswebframework.web.authorization.define.HandleType; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java index 3af1b8f21..2c347c7f7 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java @@ -1,6 +1,7 @@ package org.hswebframework.web.authorization.token; import org.hswebframework.web.authorization.Authentication; +import reactor.core.publisher.Mono; /** * @author zhouhao @@ -19,6 +20,6 @@ public interface ThirdPartAuthenticationManager { * @param userId 用户ID * @return 权限信息 */ - Authentication getByUserId(String userId); + Mono getByUserId(String userId); } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java index b4e4f1099..7b61fe23e 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java @@ -1,15 +1,16 @@ package org.hswebframework.web.authorization.token; -import org.hswebframework.web.ThreadLocalUtils; import org.hswebframework.web.authorization.Authentication; import org.hswebframework.web.authorization.AuthenticationManager; import org.hswebframework.web.authorization.AuthenticationSupplier; +import org.hswebframework.web.context.ContextKey; +import org.hswebframework.web.context.ContextUtils; import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Mono; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; /** * @author zhouhao @@ -32,14 +33,14 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { } @Override - public Authentication get(String userId) { + public Mono get(String userId) { if (userId == null) { return null; } return get(this.defaultAuthenticationManager, userId); } - protected Authentication get(ThirdPartAuthenticationManager authenticationManager, String userId) { + protected Mono get(ThirdPartAuthenticationManager authenticationManager, String userId) { if (null == userId) { return null; } @@ -49,7 +50,7 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { return authenticationManager.getByUserId(userId); } - protected Authentication get(AuthenticationManager authenticationManager, String userId) { + protected Mono get(AuthenticationManager authenticationManager, String userId) { if (null == userId) { return null; } @@ -59,19 +60,14 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { return authenticationManager.getByUserId(userId); } - protected UserToken getCurrentUserToken() { - return UserTokenHolder.currentToken(); - } - @Override - public Authentication get() { - return ThreadLocalUtils.get(Authentication.class.getName(), () -> - Optional.ofNullable(getCurrentUserToken()) - .filter(UserToken::validate) //验证token,如果不是正常状态,将会抛出异常 - .map(token -> - get(thirdPartAuthenticationManager - .get(token.getType()), token.getUserId()) - ) - .orElse(null)); + public Mono get() { + return ContextUtils.currentContext() + .flatMap(context -> + context.get(ContextKey.of(UserToken.class)) + .filter(UserToken::validate) + .map(token -> get(thirdPartAuthenticationManager.get(token.getType()), token.getUserId())) + .orElseGet(Mono::empty)); + } } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenChangedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenChangedEvent.java index f943b1c25..2606c4b9b 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenChangedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenChangedEvent.java @@ -1,6 +1,6 @@ package org.hswebframework.web.authorization.token.event; -import org.hswebframework.web.authorization.listener.event.AuthorizationEvent; +import org.hswebframework.web.authorization.events.AuthorizationEvent; import org.hswebframework.web.authorization.token.UserToken; import org.springframework.context.ApplicationEvent; diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenCreatedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenCreatedEvent.java index 439d7bbfa..98dcc0ada 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenCreatedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenCreatedEvent.java @@ -1,7 +1,7 @@ package org.hswebframework.web.authorization.token.event; import org.hswebframework.web.authorization.token.UserToken; -import org.hswebframework.web.authorization.listener.event.AuthorizationEvent; +import org.hswebframework.web.authorization.events.AuthorizationEvent; import org.springframework.context.ApplicationEvent; public class UserTokenCreatedEvent extends ApplicationEvent implements AuthorizationEvent { diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenRemovedEvent.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenRemovedEvent.java index 5b17f2e33..00f977bf3 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenRemovedEvent.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/event/UserTokenRemovedEvent.java @@ -1,6 +1,6 @@ package org.hswebframework.web.authorization.token.event; -import org.hswebframework.web.authorization.listener.event.AuthorizationEvent; +import org.hswebframework.web.authorization.events.AuthorizationEvent; import org.hswebframework.web.authorization.token.UserToken; import org.springframework.context.ApplicationEvent; diff --git a/hsweb-authorization/hsweb-authorization-api/src/test/java/org/hswebframework/web/authorization/AuthenticationTests.java b/hsweb-authorization/hsweb-authorization-api/src/test/java/org/hswebframework/web/authorization/AuthenticationTests.java index dac3632d9..793203148 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/test/java/org/hswebframework/web/authorization/AuthenticationTests.java +++ b/hsweb-authorization/hsweb-authorization-api/src/test/java/org/hswebframework/web/authorization/AuthenticationTests.java @@ -1,17 +1,23 @@ package org.hswebframework.web.authorization; import org.hswebframework.web.authorization.builder.AuthenticationBuilder; +import org.hswebframework.web.authorization.exception.AccessDenyException; import org.hswebframework.web.authorization.exception.UnAuthorizedException; import org.hswebframework.web.authorization.simple.builder.SimpleAuthenticationBuilder; import org.hswebframework.web.authorization.simple.builder.SimpleDataAccessConfigBuilderFactory; import org.hswebframework.web.authorization.token.*; +import org.hswebframework.web.context.ContextKey; +import org.hswebframework.web.context.ContextUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; import java.util.Collections; import java.util.Set; +import static org.hswebframework.web.context.ContextUtils.*; import static org.junit.Assert.*; public class AuthenticationTests { @@ -54,7 +60,7 @@ public class AuthenticationTests { assertEquals(authentication.getPermissions().size(), 1); assertTrue(authentication.hasPermission("user-manager")); assertTrue(authentication.hasPermission("user-manager", "get")); - assertTrue(!authentication.hasPermission("user-manager", "delete")); + assertFalse(authentication.hasPermission("user-manager", "delete")); boolean has = AuthenticationPredicate.has("permission:user-manager") .or(AuthenticationPredicate.role("admin-role")) @@ -95,21 +101,21 @@ public class AuthenticationTests { //初始化权限管理器,用于获取用户的权限信息 AuthenticationManager authenticationManager = new AuthenticationManager() { @Override - public Authentication authenticate(AuthenticationRequest request) { + public Mono authenticate(AuthenticationRequest request) { return null; } @Override - public Authentication getByUserId(String userId) { + public Mono getByUserId(String userId) { if (userId.equals("admin")) { - return authentication; + return Mono.just(authentication); } - return null; + return Mono.empty(); } @Override - public Authentication sync(Authentication authentication) { - return authentication; + public Mono sync(Authentication authentication) { + return Mono.just(authentication); } }; AuthenticationHolder.addSupplier(new UserTokenAuthenticationSupplier(authenticationManager)); @@ -117,11 +123,16 @@ public class AuthenticationTests { //绑定用户token UserTokenManager userTokenManager = new DefaultUserTokenManager(); UserToken token = userTokenManager.signIn("test", "token-test", "admin", -1); - UserTokenHolder.setCurrent(token); //获取当前登录用户 - Authentication current = Authentication.current().orElseThrow(UnAuthorizedException::new); - Assert.assertEquals(current.getUser().getId(), "admin"); + Authentication + .current() + .map(Authentication::getUser) + .map(User::getId) + .subscriberContext(acceptContext(ctx->ctx.put(ContextKey.of(UserToken.class),token))) + .as(StepVerifier::create) + .expectNext("admin") + .verifyComplete(); } diff --git a/hsweb-authorization/hsweb-authorization-basic/pom.xml b/hsweb-authorization/hsweb-authorization-basic/pom.xml index 1f5bb409b..c7da67311 100644 --- a/hsweb-authorization/hsweb-authorization-basic/pom.xml +++ b/hsweb-authorization/hsweb-authorization-basic/pom.xml @@ -5,7 +5,7 @@ hsweb-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/DefaultAuthorizingHandler.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/DefaultAuthorizingHandler.java index 080d3e23a..83c40cc59 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/DefaultAuthorizingHandler.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/DefaultAuthorizingHandler.java @@ -14,7 +14,7 @@ import org.hswebframework.web.authorization.define.AuthorizeDefinition; import org.hswebframework.web.authorization.define.AuthorizingContext; import org.hswebframework.web.authorization.define.HandleType; import org.hswebframework.web.authorization.exception.AccessDenyException; -import org.hswebframework.web.authorization.listener.event.AuthorizingHandleBeforeEvent; +import org.hswebframework.web.authorization.events.AuthorizingHandleBeforeEvent; import org.hswebframework.web.boost.aop.context.MethodInterceptorContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandler.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandler.java index 68df503aa..68a573a88 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandler.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandler.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.Setter; import org.hswebframework.web.authorization.define.AuthorizingContext; import org.hswebframework.web.authorization.define.HandleType; -import org.hswebframework.web.authorization.listener.event.AuthorizingHandleBeforeEvent; +import org.hswebframework.web.authorization.events.AuthorizingHandleBeforeEvent; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.event.EventListener; import org.springframework.util.AntPathMatcher; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizationController.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizationController.java index 5112a3e1c..9236369ed 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizationController.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizationController.java @@ -25,7 +25,7 @@ import org.hswebframework.web.WebUtil; import org.hswebframework.web.authorization.Authentication; import org.hswebframework.web.authorization.AuthenticationManager; import org.hswebframework.web.authorization.annotation.Authorize; -import org.hswebframework.web.authorization.listener.event.*; +import org.hswebframework.web.authorization.events.*; import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest; import org.hswebframework.web.controller.message.ResponseMessage; import org.hswebframework.web.logging.AccessLogger; @@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Map; -import java.util.Objects; import java.util.function.Function; import static org.hswebframework.web.controller.message.ResponseMessage.ok; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java index 927ba1117..b59b1f5e4 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java @@ -1,6 +1,7 @@ package org.hswebframework.web.authorization.basic.web; -import org.hswebframework.web.authorization.listener.event.AuthorizationSuccessEvent; +import org.hswebframework.web.authorization.events.AuthorizationEvent; +import org.hswebframework.web.authorization.events.AuthorizationSuccessEvent; import org.hswebframework.web.authorization.token.UserToken; import org.hswebframework.web.authorization.token.UserTokenHolder; import org.hswebframework.web.authorization.token.UserTokenManager; @@ -15,7 +16,7 @@ import java.util.List; * * @author zhouhao * @see org.springframework.context.ApplicationEvent - * @see org.hswebframework.web.authorization.listener.event.AuthorizationEvent + * @see AuthorizationEvent * @see UserTokenManager * @see UserTokenGenerator * @since 3.0 diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignOut.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignOut.java index 8da1b9e1c..5f186f827 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignOut.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignOut.java @@ -1,6 +1,6 @@ package org.hswebframework.web.authorization.basic.web; -import org.hswebframework.web.authorization.listener.event.AuthorizationExitEvent; +import org.hswebframework.web.authorization.events.AuthorizationExitEvent; import org.hswebframework.web.authorization.token.UserToken; import org.hswebframework.web.authorization.token.UserTokenHolder; import org.hswebframework.web.authorization.token.UserTokenManager; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/test/groovy/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandlerTest.groovy b/hsweb-authorization/hsweb-authorization-basic/src/test/groovy/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandlerTest.groovy index f809f2568..b39a291c0 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/test/groovy/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandlerTest.groovy +++ b/hsweb-authorization/hsweb-authorization-basic/src/test/groovy/org/hswebframework/web/authorization/basic/handler/UserAllowPermissionHandlerTest.groovy @@ -7,7 +7,7 @@ import org.hswebframework.web.authorization.basic.define.EmptyAuthorizeDefinitio import org.hswebframework.web.authorization.define.AuthorizeDefinition import org.hswebframework.web.authorization.define.AuthorizingContext import org.hswebframework.web.authorization.define.HandleType -import org.hswebframework.web.authorization.listener.event.AuthorizingHandleBeforeEvent +import org.hswebframework.web.authorization.events.AuthorizingHandleBeforeEvent import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest import org.hswebframework.web.boost.aop.context.MethodInterceptorContext import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder diff --git a/hsweb-authorization/hsweb-authorization-jwt/pom.xml b/hsweb-authorization/hsweb-authorization-jwt/pom.xml index d5cc9432c..340cd0550 100644 --- a/hsweb-authorization/hsweb-authorization-jwt/pom.xml +++ b/hsweb-authorization/hsweb-authorization-jwt/pom.xml @@ -5,7 +5,7 @@ hsweb-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml index b028a49f2..c0a213684 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml +++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-auth-server/pom.xml @@ -23,7 +23,7 @@ hsweb-authorization-oauth2 org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml index 811623df1..989c2da7b 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml +++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/pom.xml @@ -23,7 +23,7 @@ hsweb-authorization-oauth2 org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-core/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-core/pom.xml index c1ca252d4..134ac0c8d 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-core/pom.xml +++ b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-core/pom.xml @@ -23,7 +23,7 @@ hsweb-authorization-oauth2 org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/hsweb-authorization-oauth2/pom.xml b/hsweb-authorization/hsweb-authorization-oauth2/pom.xml index be69ed90a..269eba54a 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/pom.xml +++ b/hsweb-authorization/hsweb-authorization-oauth2/pom.xml @@ -5,7 +5,7 @@ hsweb-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-authorization/pom.xml b/hsweb-authorization/pom.xml index 9022e8084..da9195fc7 100644 --- a/hsweb-authorization/pom.xml +++ b/hsweb-authorization/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-boost/hsweb-boost-aop/pom.xml b/hsweb-boost/hsweb-boost-aop/pom.xml index 52617141a..faf8900ca 100644 --- a/hsweb-boost/hsweb-boost-aop/pom.xml +++ b/hsweb-boost/hsweb-boost-aop/pom.xml @@ -23,7 +23,7 @@ hsweb-boost org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-boost/hsweb-boost-excel/pom.xml b/hsweb-boost/hsweb-boost-excel/pom.xml index 95243d88c..ac333e968 100644 --- a/hsweb-boost/hsweb-boost-excel/pom.xml +++ b/hsweb-boost/hsweb-boost-excel/pom.xml @@ -5,7 +5,7 @@ hsweb-boost org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-boost/hsweb-boost-ftp/pom.xml b/hsweb-boost/hsweb-boost-ftp/pom.xml index 00f533916..c83d79250 100644 --- a/hsweb-boost/hsweb-boost-ftp/pom.xml +++ b/hsweb-boost/hsweb-boost-ftp/pom.xml @@ -5,7 +5,7 @@ hsweb-boost org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-boost/pom.xml b/hsweb-boost/pom.xml index 6333fc5eb..90bb6d9f2 100644 --- a/hsweb-boost/pom.xml +++ b/hsweb-boost/pom.xml @@ -23,7 +23,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-commons/hsweb-commons-bean/pom.xml b/hsweb-commons/hsweb-commons-bean/pom.xml index 903211e4d..2b7c6dc58 100644 --- a/hsweb-commons/hsweb-commons-bean/pom.xml +++ b/hsweb-commons/hsweb-commons-bean/pom.xml @@ -5,7 +5,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-commons/hsweb-commons-controller/pom.xml b/hsweb-commons/hsweb-commons-controller/pom.xml index 0ddebbc17..0f0efd6f1 100644 --- a/hsweb-commons/hsweb-commons-controller/pom.xml +++ b/hsweb-commons/hsweb-commons-controller/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CreateController.java b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CreateController.java index 7836ef130..526467352 100644 --- a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CreateController.java +++ b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CreateController.java @@ -65,19 +65,19 @@ public interface CreateController { if (entity instanceof RecordCreationEntity) { RecordCreationEntity creationEntity = (RecordCreationEntity) entity; creationEntity.setCreateTimeNow(); - creationEntity.setCreatorId(Authentication.current() - .map(Authentication::getUser) - .map(User::getId) - .orElse(null)); +// creationEntity.setCreatorId(Authentication.current() +// .map(Authentication::getUser) +// .map(User::getId) +// .orElse(null)); } //修改人和修改时间 if (entity instanceof RecordModifierEntity) { RecordModifierEntity creationEntity = (RecordModifierEntity) entity; creationEntity.setModifyTimeNow(); - creationEntity.setModifierId(Authentication.current() - .map(Authentication::getUser) - .map(User::getId) - .orElse(null)); +// creationEntity.setModifierId(Authentication.current() +// .map(Authentication::getUser) +// .map(User::getId) +// .orElse(null)); } return ok(getService().insert(entity)); } diff --git a/hsweb-commons/hsweb-commons-crud/pom.xml b/hsweb-commons/hsweb-commons-crud/pom.xml new file mode 100644 index 000000000..6ba479877 --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/pom.xml @@ -0,0 +1,35 @@ + + + + hsweb-commons + org.hswebframework.web + 4.0.0-SNAPSHOT + + 4.0.0 + + hsweb-commons-crud + + + + + io.projectreactor + reactor-core + + + + org.hswebframework + hsweb-easy-orm-rdb + + + + org.springframework + spring-tx + + + + + + + \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/PagerResult.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/PagerResult.java new file mode 100644 index 000000000..cbd5e336e --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/PagerResult.java @@ -0,0 +1,64 @@ +/* + * + * * Copyright 2019 http://www.hswebframework.org + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package org.hswebframework.web.crud.entity; + + +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +public class PagerResult { + private static final long serialVersionUID = -6171751136953308027L; + + public static PagerResult empty() { + return new PagerResult<>(0, new ArrayList<>()); + } + + public static PagerResult of(int total, List list) { + return new PagerResult<>(total, list); + } + + public static PagerResult of(int total, List list, QueryParamEntity entity) { + PagerResult pagerResult = new PagerResult<>(total, list); + pagerResult.setPageIndex(entity.getThinkPageIndex()); + pagerResult.setPageSize(entity.getPageSize()); + return pagerResult; + } + + private int pageIndex; + + private int pageSize; + + private int total; + + private List data; + + public PagerResult() { + } + + public PagerResult(int total, List data) { + this.total = total; + this.data = data; + } + +} diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/QueryParamEntity.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/QueryParamEntity.java new file mode 100644 index 000000000..4a2c17669 --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/QueryParamEntity.java @@ -0,0 +1,140 @@ +package org.hswebframework.web.crud.entity; + +import lombok.Getter; +import org.hswebframework.ezorm.core.NestConditional; +import org.hswebframework.ezorm.core.dsl.Query; +import org.hswebframework.ezorm.core.param.QueryParam; +import org.hswebframework.ezorm.core.param.Term; +import org.hswebframework.ezorm.core.param.TermType; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +/** + * 查询参数实体,使用easyorm进行动态查询参数构建
+ * 可通过静态方法创建:
+ * 如: + * + * QueryParamEntity.of("id",id); + * + * + * @author zhouhao + * @see QueryParam + * @since 3.0 + */ +public class QueryParamEntity extends QueryParam { + + private static final long serialVersionUID = 8097500947924037523L; + + @Getter + private String termExpression; + + /** + * 创建一个空的查询参数实体,该实体无任何参数. + * + * @return 无条件的参数实体 + */ + public static QueryParamEntity of() { + return new QueryParamEntity(); + } + + + /** + * @see this#of(String, Object) + */ + public static QueryParamEntity of(String field, Object value) { + return of().and(field, TermType.eq, value); + } + + /** + * @since 3.0.4 + */ + public static Query newQuery() { + return Query.of(new QueryParamEntity()); + } + + /** + * @since 3.0.4 + */ + public Query toQuery() { + return Query.of(this); + } + + /** + * 将已有的条件包装到一个嵌套的条件里,并返回一个Query对象.例如: + *
+     *     entity.toNestQuery().and("userId",userId);
+     * 
+ *

+ * 原有条件: name=? or type=? + *

+ * 执行后条件: (name=? or type=?) and userId=? + * + * @see this#toNestQuery(Consumer) + * @since 3.0.4 + */ + public Query toNestQuery() { + return toNestQuery(null); + } + + /** + * 将已有的条件包装到一个嵌套的条件里,并返回一个Query对象.例如: + *

+     *     entity.toNestQuery(query->query.and("userId",userId));
+     * 
+ *

+ * 原有条件: name=? or type=? + *

+ * 执行后条件: userId=? (name=? or type=?) + * + * @param before 在包装之前执行,将条件包装到已有条件之前 + * @since 3.0.4 + */ + public Query toNestQuery(Consumer> before) { + List terms = getTerms(); + setTerms(new ArrayList<>()); + Query query = toQuery(); + if (null != before) { + before.accept(query); + } + return query + .nest() + .each(terms, NestConditional::accept) + .end(); + } + + /** + * 设置条件表达式,可以通过表达式的方式快速构建查询条件. 表达式是类似sql条件的语法,如: + *

+     *     name is 测试 and age gte 10
+     * 
+ *
+     *     name is 测试 and (age gt 10 or age lte 90 )
+     * 
+ * + * @param termExpression 表达式 + * @see 3.0.5 + */ + public void setTermExpression(String termExpression) { + this.termExpression = termExpression; + setTerms(TermExpressionParser.parse(termExpression)); + } + + @Override + public List getTerms() { + List terms = super.getTerms(); + if (CollectionUtils.isEmpty(terms) && StringUtils.hasText(termExpression)) { + setTerms(terms = TermExpressionParser.parse(termExpression)); + } + return terms; + } + + public QueryParamEntity noPaging() { + setPaging(false); + return this; + } + +} diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/TermExpressionParser.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/TermExpressionParser.java new file mode 100644 index 000000000..b6a931b7a --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/entity/TermExpressionParser.java @@ -0,0 +1,184 @@ +package org.hswebframework.web.crud.entity; + +import org.hswebframework.ezorm.core.NestConditional; +import org.hswebframework.ezorm.core.dsl.Query; +import org.hswebframework.ezorm.core.param.Term; +import org.hswebframework.ezorm.core.param.TermType; + +import java.util.Arrays; +import java.util.List; + +/** + * 动态条件表达式解析器 + * name=测试 and age=test + */ +public class TermExpressionParser { + + public static List parse(String expression) { + Query conditional = QueryParamEntity.newQuery(); + + NestConditional nest = null; + + // 字符容器 + char[] buf = new char[128]; + // 记录词项的长度, Arrays.copyOf使用 + byte len = 0; + // 空格数量? + byte spaceLen = 0; + // 当前列 + char[] currentColumn = null; + // 当前列对应的值 + char[] currentValue = null; + // 当前条件类型 eq btw in ... + String currentTermType = null; + // 当前链接类型 and / or + String currentType = "and"; + // 是否是引号, 单引号 / 双引号 + byte quotationMarks = 0; + // 表达式字符数组 + char[] all = expression.toCharArray(); + + for (char c : all) { + + if (c == '\'' || c == '"') { + if (quotationMarks != 0) { + // 碰到(结束的)单/双引号, 标志归零, 跳过 + quotationMarks = 0; + continue; + } + // 碰到(开始的)单/双引号, 做记录, 跳过 + quotationMarks++; + continue; + } else if (c == '(') { + nest = (nest == null ? + (currentType.equals("or") ? conditional.orNest() : conditional.nest()) : + (currentType.equals("or") ? nest.orNest() : nest.nest())); + len = 0; + continue; + } else if (c == ')') { + if (nest == null) { + continue; + } + if (null != currentColumn) { + currentValue = Arrays.copyOf(buf, len); + nest.accept(new String(currentColumn), convertTermType(currentTermType), new String(currentValue)); + currentColumn = null; + currentTermType = null; + } + Object end = nest.end(); + nest = end instanceof NestConditional ? ((NestConditional) end) : null; + len = 0; + spaceLen++; + continue; + } else if (c == '=' || c == '>' || c == '<') { + if (currentTermType != null) { + currentTermType += String.valueOf(c); + //spaceLen--; + } else { + currentTermType = String.valueOf(c); + } + + if (currentColumn == null) { + currentColumn = Arrays.copyOf(buf, len); + } + spaceLen++; + len = 0; + continue; + } else if (c == ' ') { + if (len == 0) { + continue; + } + if (quotationMarks != 0) { + // 如果当前字符是空格,并且前面迭代时碰到过单/双引号, 不处理并且添加到buf中 + buf[len++] = c; + continue; + } + spaceLen++; + if (currentColumn == null && (spaceLen == 1 || spaceLen % 5 == 0)) { + currentColumn = Arrays.copyOf(buf, len); + len = 0; + continue; + } + if (null != currentColumn) { + if (null == currentTermType) { + currentTermType = new String(Arrays.copyOf(buf, len)); + len = 0; + continue; + } + currentValue = Arrays.copyOf(buf, len); + if (nest != null) { + nest.accept(new String(currentColumn), convertTermType(currentTermType), new String(currentValue)); + } else { + conditional.accept(new String(currentColumn), convertTermType(currentTermType), new String(currentValue)); + } + currentColumn = null; + currentTermType = null; + len = 0; + continue; + } else if (len == 2 || len == 3) { + String type = new String(Arrays.copyOf(buf, len)); + if (type.equalsIgnoreCase("or")) { + currentType = "or"; + if (nest != null) { + nest.or(); + } else { + conditional.or(); + } + len = 0; + continue; + } else if (type.equalsIgnoreCase("and")) { + currentType = "and"; + if (nest != null) { + nest.and(); + } else { + conditional.and(); + } + len = 0; + continue; + } else { + currentColumn = Arrays.copyOf(buf, len); + len = 0; + spaceLen++; + } + } else { + currentColumn = Arrays.copyOf(buf, len); + len = 0; + spaceLen++; + } + continue; + } + + buf[len++] = c; + } + if (null != currentColumn) { + currentValue = Arrays.copyOf(buf, len); + if (nest != null) { + nest.accept(new String(currentColumn), convertTermType(currentTermType), new String(currentValue)); + } else { + conditional.accept(new String(currentColumn), convertTermType(currentTermType), new String(currentValue)); + } + } + return conditional.getParam().getTerms(); + } + + private static String convertTermType(String termType) { + if (termType == null) { + return TermType.eq; + } + switch (termType) { + case "=": + return TermType.eq; + case ">": + return TermType.gt; + case "<": + return TermType.lt; + case ">=": + return TermType.gte; + case "<=": + return TermType.lte; + default: + return termType; + } + + } +} diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/DefaultReactiveCrudService.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/DefaultReactiveCrudService.java new file mode 100644 index 000000000..3873a3051 --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/DefaultReactiveCrudService.java @@ -0,0 +1,16 @@ +package org.hswebframework.web.crud.service; + +import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository; +import org.springframework.beans.factory.annotation.Autowired; + +public class DefaultReactiveCrudService implements ReactiveCrudService { + + @Autowired + private ReactiveRepository repository; + + @Override + public ReactiveRepository getRepository() { + return repository; + } + +} diff --git a/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/ReactiveCrudService.java b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/ReactiveCrudService.java new file mode 100644 index 000000000..136ca6059 --- /dev/null +++ b/hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/service/ReactiveCrudService.java @@ -0,0 +1,72 @@ +package org.hswebframework.web.crud.service; + +import org.hswebframework.ezorm.core.param.QueryParam; +import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository; +import org.hswebframework.ezorm.rdb.mapping.defaults.SaveResult; +import org.hswebframework.web.crud.entity.PagerResult; +import org.reactivestreams.Publisher; +import org.springframework.transaction.annotation.Transactional; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Collections; + +public interface ReactiveCrudService { + + ReactiveRepository getRepository(); + + @Transactional(readOnly = true) + default Mono findById(Mono publisher) { + return getRepository().findById(publisher); + } + + @Transactional(readOnly = true) + default Flux findById(Flux publisher) { + return publisher.flatMap(e -> findById(Mono.just(e))); + } + + @Transactional + default Mono save(Publisher entityPublisher) { + return getRepository() + .save(entityPublisher); + } + + @Transactional + default Mono deleteById(Publisher idPublisher) { + return getRepository() + .deleteById(idPublisher); + } + + @Transactional(readOnly = true) + default Flux query(Mono queryParamMono) { + return queryParamMono + .flatMapMany(param -> getRepository() + .createQuery() + .setParam(param) + .fetch()); + } + + @Transactional(readOnly = true) + default Mono> queryPager(Mono queryParamMono) { + return count(queryParamMono) + .zipWhen(total -> { + if (total == 0) { + return Mono.just(Collections.emptyList()); + } + return queryParamMono + .map(QueryParam::clone) + .flatMap(q -> query(Mono.just(q.rePaging(total))).collectList()); + }, PagerResult::of); + } + + @Transactional(readOnly = true) + default Mono count(Mono queryParamMono) { + return queryParamMono + .flatMap(param -> getRepository() + .createQuery() + .setParam(param) + .count()); + } + + +} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml index 004071f18..5d2da427e 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml @@ -23,7 +23,7 @@ hsweb-commons-dao org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/README.md b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/README.md deleted file mode 100644 index 3d8c0bc2b..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/README.md +++ /dev/null @@ -1,224 +0,0 @@ -# 基于mybatis的通用crud实现 - -使用myabtis和easy-orm对`hsweb-commons-dao-api`进行了实现,提供动态条件对crud支持. - -# 使用 -在pom.xml中引入: - -```xml - - org.hswebframework.web - hsweb-commons-dao-mybatis - ${hsweb.framework.version} - -``` - -# 配置 -application.yml - -```yaml -mybatis: - # 扫描myabtis mapper xml的路径 - mapper-locations: classpath*:com/company/app/**/*Mapper.xml - # 这里需要配置扫描枚举,才能支持对实现了EnumDict接口的枚举进行序列化和反序列化 - type-handlers-package: com.company.app.enums - # 是否开启动态数据源,开启后才能支持在同一个dao中切换数据源 - dynamic-datasource: false - # 排除扫描xml配置,用于需要拓展无法修改的mapper xml时,通过此配置不加载对应的xml,然后通过mapper-locations配置加载新的xml. - mapper-location-excludes: classpath*:com/company/app/x/y/*Mapper.xml -``` - -# 使用通用Mapper XMl - -目前仅支持xml的方式,例如: - -```xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -``` - -⚠️注意:query(count),update,delete方法的参数目前仅实现了: - -`org.hswebframework.web.commons.entity.param.QueryParamEntity` - -`org.hswebframework.web.commons.entity.param.UpdateParamEntity` - -`org.hswebframework.web.commons.entity.param.DeleteParamEntity` - -因此在实际调用都时候,目前只能接收对应以上参数. -但是在接口中仍然使用`org.hswebframework.web.commons.entity.Entity`作为参数,用于预留给以后提供更多都参数实现. - -# 动态条件 -此模块使用hsweb-easyorm项目来进行动态SQL条件的生成,主要是通过:在上述的`**ParamEntity`类中的属性 `List terms;` -进行处理,`Term`为一个SQL条件,例如一个简单的嵌套条件: -```text - [{ - column:"name", - termType:"eq", #SQL条件类型 = - value:"张三", - terms:[ - { - column:"address", - termType:"like", //SQL条件类型 like - value:"北京%" - }, - { - column:"address", - type:"or" //和前面的条件成or关系,如果不指定,默认为and - termType:"like", //SQL条件类型 like - value:"上海%" - } - ] - }] -``` -对应的sql条件为: where name = ? and (address like ? or address lke ?) - -条件构造方式看上去过于复杂? 可以使用DSL方式的构建工具类:`org.hswebframework.ezorm.core.dsl.Query`来进行构建. -在[hsweb-commons-service-api](../../hsweb-commons-service/hsweb-commons-service-api)模块也会提供便捷的条件创建方式. - -如果参数来自客户端请求,可封装一个通用的js进行构建, 你可以在前端放心的构建参数,所有的条件都使用参数化预编译的方式拼接SQL,不存在SQL注入问题. - -## 默认支持的动态条件列表 -| termType | 对应SQL | 说明 | -| ------------- |:-------------:| ----| -|eq|=?| 等于| -|not |!=?| 不等于| -|gt|>?| 大于| -|gte|>= ?| 大于等于| -|lt|< ?| 小于| -|lte| <= ?| 小于等于| -|like|like ?| 模糊匹配,如果需要统配符,请自行拼接value,如: value+"%" | -|nlike|not like ?| 同like | -|in|in(?,?)| value 可使用半角逗号(,)分隔,或者数组或者`Collection`接口的实现 | -|nin|not in(?,?)| value 可使用半角逗号(,)分隔,或者数组或者`Collection`接口的实现 | -|isnull| is null | value为任意不为空的值即可 | -|notnull| not null | value为任意不为空的值即可 | -|empty| ='' | value为任意不为空的值即可 | -|nempty| !='' | value为任意不为空的值即可 | -|bwt|between ? and ? | value 可使用半角逗号(,)分隔,或者使用数组或者Collection接口的实现| -|nbwt|not between ? and ? | value 可使用半角逗号(,)分隔,或者使用数组或者Collection接口的实现| - -## 拓展动态条件 -在某些需要自定义查询条件的场景,比如关联条件,可通过实现`SqlTermCustomer`接口并注入到spring来进行自定义SQL条件的拼接, -例如: -```java -//AbstractSqlTermCustomer提供了一些便利的方法 -@org.springframework.stereotype.Component -public class MyTerm extends AbstractSqlTermCustomer{ - - @Override - public String getTermType() { - //对应Term参数中的属性termType - return "my-term"; - } - - @Override - public Dialect[] forDialect() { - //对特定对数据库类型生效,返回null时对全部支持对数据库类型生效 - return null; - } - - - @Override - public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - //当传入了my-term条件对时候,会调用此方法进行拼接 - //对传入对参数进行转换,此步骤为必须的 - ChangedTermValue termValue =createChangedValue(term); - - //转换参数,将参数转为集合,以支持in查询. - List idList = BoostTermTypeMapper.convertList(column, termValue.getOld()); - - SqlAppender appender= new SqlAppender(); - - appender.add(createColumnName(column,tableAlias),"in (select id from my_table where t_id"); - - //根据参数的数量,构造对应的=或者in条件 - Object newValue= appendCondition(idList,wherePrefix,appender); - - appender.add(")"); - //设置新的值到条件中 - termValue.setValue(newValue); - - return appender; - } -} -``` - -使用: 在查询的时候,将`Term`的`termType`属性值设置为`my-term`即可. diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/pom.xml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/pom.xml deleted file mode 100644 index 9feebe34c..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - hsweb-commons-dao - org.hswebframework.web - 3.0.10-SNAPSHOT - ../pom.xml - - 4.0.0 - - hsweb-commons-dao-mybatis - - 通用增删改查-通用Dao的mybatis实现 - - - - org.hswebframework.web - hsweb-commons-dao-api - ${project.version} - - - org.hswebframework.web - hsweb-core - ${project.version} - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 1.1.1 - - - org.hswebframework.web - hsweb-datasource-api - ${project.version} - - - org.hibernate.javax.persistence - hibernate-jpa-2.1-api - 1.0.0.Final - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - com.alibaba - druid - 1.0.26 - test - - - - - - - - com.h2database - h2 - test - - - org.glassfish - javax.el - test - - - - \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/EnumDictHandlerRegister.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/EnumDictHandlerRegister.java deleted file mode 100644 index 4d5659712..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/EnumDictHandlerRegister.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.hswebframework.web.dao.mybatis; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.type.JdbcType; -import org.apache.ibatis.type.MappedJdbcTypes; -import org.apache.ibatis.type.TypeHandler; -import org.apache.ibatis.type.TypeHandlerRegistry; -import org.hswebframework.web.dict.EnumDict; -import org.hswebframework.web.dict.defaults.DefaultDictDefineRepository; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.core.type.classreading.CachingMetadataReaderFactory; -import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.util.ClassUtils; - -import java.io.IOException; -import java.lang.reflect.Array; -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -import static org.springframework.util.StringUtils.tokenizeToStringArray; - -@Slf4j -public class EnumDictHandlerRegister { - - static TypeHandlerRegistry typeHandlerRegistry; - - private static MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(); - - private static ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); - - - public static void register(String packages) { - register(tokenizeToStringArray(packages, - ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)); - } - - @SuppressWarnings("all") - public static void register(String[] packages) { - if (typeHandlerRegistry == null) { - log.error("请在spring容器初始化后再调用此方法!"); - return; - } - for (String basePackage : packages) { - String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + - ClassUtils.convertClassNameToResourcePath(basePackage) + "/**/*.class"; - try { - Resource[] resources = resourcePatternResolver.getResources(packageSearchPath); - for (Resource resource : resources) { - try { - MetadataReader reader = metadataReaderFactory.getMetadataReader(resource); - Class enumType = Class.forName(reader.getClassMetadata().getClassName()); - if (enumType.isEnum() && EnumDict.class.isAssignableFrom(enumType)) { - log.debug("register enum dict:{}", enumType); - DefaultDictDefineRepository.registerDefine(DefaultDictDefineRepository.parseEnumDict(enumType)); - //注册枚举类型 - typeHandlerRegistry.register(enumType, new EnumDictHandler(enumType)); - - //注册枚举数组类型 - typeHandlerRegistry.register(Array.newInstance(enumType, 0).getClass(), new EnumDictArrayHandler(enumType)); - } - } catch (Exception | Error ignore) { - - } - } - } catch (IOException e) { - log.warn("register enum dict error", e); - } - } - } - - @Getter - @Setter - @AllArgsConstructor - @MappedJdbcTypes({JdbcType.NUMERIC, JdbcType.TINYINT, JdbcType.INTEGER, JdbcType.BIGINT}) - static class EnumDictArrayHandler implements TypeHandler { - - private Class type; - - @Override - public void setParameter(PreparedStatement ps, int i, Object[] parameter, JdbcType jdbcType) throws SQLException { - T[] ts = ((T[]) parameter); - ps.setLong(i, EnumDict.toMask(ts)); - } - - @Override - public Object[] getResult(ResultSet rs, String columnName) throws SQLException { - return toArray(rs.getLong(columnName)); - } - - @Override - public Object[] getResult(ResultSet rs, int columnIndex) throws SQLException { - return toArray(rs.getLong(columnIndex)); - } - - @Override - public Object[] getResult(CallableStatement cs, int columnIndex) throws SQLException { - return toArray(cs.getLong(columnIndex)); - } - - private Object[] toArray(Long value) { - if (null == value) { - return null; - } - List ts = EnumDict.getByMask(getType(), value); - return ts.toArray((Object[]) Array.newInstance(type, ts.size())); - } - } - - @Getter - @Setter - @AllArgsConstructor - @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.BIT, - JdbcType.BOOLEAN, JdbcType.NUMERIC, - JdbcType.TINYINT, JdbcType.INTEGER, - JdbcType.BIGINT, JdbcType.DECIMAL, - JdbcType.CHAR}) - static class EnumDictHandler implements TypeHandler { - - private Class type; - - @Override - public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { - if (parameter == null) { - ps.setNull(i, jdbcType.TYPE_CODE); - } else { - ps.setObject(i, parameter.getValue()); - } - } - - @Override - public T getResult(ResultSet rs, String columnName) throws SQLException { - Object val = rs.getObject(columnName); - return EnumDict.findByValue(getType(), val).orElse(null); - } - - @Override - public T getResult(ResultSet rs, int columnIndex) throws SQLException { - Object val = rs.getObject(columnIndex); - return EnumDict.findByValue(getType(), val).orElse(null); - } - - @Override - public T getResult(CallableStatement cs, int columnIndex) throws SQLException { - Object val = cs.getObject(columnIndex); - return EnumDict.findByValue(getType(), val).orElse(null); - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MyBatisAutoConfiguration.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MyBatisAutoConfiguration.java deleted file mode 100644 index 072f7d455..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MyBatisAutoConfiguration.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis; - -import org.apache.ibatis.mapping.DatabaseIdProvider; -import org.apache.ibatis.plugin.Interceptor; -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.session.TransactionIsolationLevel; -import org.apache.ibatis.transaction.Transaction; -import org.hswebframework.web.commons.entity.factory.EntityFactory; -import org.hswebframework.web.dao.mybatis.builder.EasyOrmSqlBuilder; -import org.hswebframework.web.dao.mybatis.dynamic.DynamicDataSourceSqlSessionFactoryBuilder; -import org.hswebframework.web.dao.mybatis.dynamic.DynamicSpringManagedTransaction; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; -import org.mybatis.spring.transaction.SpringManagedTransactionFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.ResourceLoader; -import org.springframework.util.StringUtils; - -import javax.sql.DataSource; - -@Configuration -@EnableConfigurationProperties(MybatisProperties.class) -public class MyBatisAutoConfiguration { - - @Autowired(required = false) - private Interceptor[] interceptors; - - @Autowired - private ResourceLoader resourceLoader = new DefaultResourceLoader(); - - @Autowired(required = false) - private DatabaseIdProvider databaseIdProvider; - - @Autowired(required = false) - private EntityFactory entityFactory; - - @Bean - @Primary - @ConfigurationProperties(prefix = MybatisProperties.MYBATIS_PREFIX) - public MybatisProperties mybatisProperties() { - return new MybatisProperties(); - } - - @Bean(name = "sqlSessionFactory") - @Primary - public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { - SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); - MybatisProperties mybatisProperties = this.mybatisProperties(); - if (null != entityFactory) { - factory.setObjectFactory(new MybatisEntityFactory(entityFactory)); - } - factory.setVfs(SpringBootVFS.class); - if (mybatisProperties().isDynamicDatasource()) { - factory.setSqlSessionFactoryBuilder(new DynamicDataSourceSqlSessionFactoryBuilder()); - factory.setTransactionFactory(new SpringManagedTransactionFactory() { - @Override - public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) { - return new DynamicSpringManagedTransaction(); - } - }); - } - factory.setDataSource(dataSource); - if (StringUtils.hasText(mybatisProperties.getConfigLocation())) { - factory.setConfigLocation(this.resourceLoader.getResource(mybatisProperties - .getConfigLocation())); - } - if (mybatisProperties.getConfiguration() != null) { - factory.setConfiguration(mybatisProperties.getConfiguration()); - } - if (this.interceptors != null && this.interceptors.length > 0) { - factory.setPlugins(this.interceptors); - } - if (this.databaseIdProvider != null) { - factory.setDatabaseIdProvider(this.databaseIdProvider); - } - factory.setTypeAliasesPackage(mybatisProperties.getTypeAliasesPackage()); - String typeHandlers = "org.hswebframework.web.dao.mybatis.handler"; - if (mybatisProperties.getTypeHandlersPackage() != null) { - typeHandlers = typeHandlers + ";" + mybatisProperties.getTypeHandlersPackage(); - } - factory.setTypeHandlersPackage(typeHandlers); - factory.setMapperLocations(mybatisProperties.resolveMapperLocations()); - - SqlSessionFactory sqlSessionFactory = factory.getObject(); - MybatisUtils.sqlSession = sqlSessionFactory; - - EnumDictHandlerRegister.typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry(); - EnumDictHandlerRegister.register("org.hswebframework.web;" + mybatisProperties.getTypeHandlersPackage()); - - try { - Class.forName("javax.persistence.Table"); - EasyOrmSqlBuilder.getInstance().useJpa = mybatisProperties.isUseJpa(); - } catch (@SuppressWarnings("all") Exception ignore) { - } - EasyOrmSqlBuilder.getInstance().entityFactory = entityFactory; - - return sqlSessionFactory; - } - - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisDaoAutoConfiguration.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisDaoAutoConfiguration.java deleted file mode 100644 index c0033fda8..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisDaoAutoConfiguration.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis; - -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.hswebframework.web.dao.Dao; -import org.hswebframework.web.dao.mybatis.mapper.SqlTermCustomizer; -import org.hswebframework.web.dao.mybatis.mapper.dict.DictInTermTypeMapper; -import org.hswebframework.web.dao.mybatis.mapper.dict.DictTermTypeMapper; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import java.util.Arrays; -import java.util.List; - -@Configuration -@ComponentScan("org.hswebframework.web.dao.mybatis") -@MapperScan(value = "org.hswebframework.web.dao" - , markerInterface = Dao.class - , sqlSessionFactoryRef = "sqlSessionFactory") -@AutoConfigureAfter(MyBatisAutoConfiguration.class) -@EnableConfigurationProperties(MybatisProperties.class) -public class MybatisDaoAutoConfiguration { - @Bean - public DictTermTypeMapper dictTermTypeMapper() { - return new DictTermTypeMapper(false); - } - - @Bean - public DictTermTypeMapper dictNotTermTypeMapper() { - return new DictTermTypeMapper(true); - } - - @Bean - public DictInTermTypeMapper dictInTermTypeMapper() { - return new DictInTermTypeMapper(false); - } - - @Bean - public DictInTermTypeMapper dictNotInTermTypeMapper() { - return new DictInTermTypeMapper(true); - } - - @Bean - public BeanPostProcessor sqlTermCustomizerRegister() { - - List dialects = Arrays.asList( - Dialect.H2 - , Dialect.MYSQL - , Dialect.ORACLE - , Dialect.POSTGRES - , Dialect.MSSQL); - - return new BeanPostProcessor() { - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof SqlTermCustomizer) { - SqlTermCustomizer customizer = ((SqlTermCustomizer) bean); - if (customizer.forDialect() != null) { - for (Dialect dialect : customizer.forDialect()) { - dialect.setTermTypeMapper(customizer.getTermType(), customizer); - } - } else { - dialects.forEach(dialect -> dialect.setTermTypeMapper(customizer.getTermType(), customizer)); - } - } - return bean; - } - }; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisEntityFactory.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisEntityFactory.java deleted file mode 100644 index 495710efa..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisEntityFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.hswebframework.web.dao.mybatis; - -import org.apache.ibatis.reflection.factory.DefaultObjectFactory; -import org.hswebframework.web.commons.entity.factory.EntityFactory; - -import java.util.*; - -/** - * 使用EntityFactory来拓展mybatis实体 - * - * @author zhouhao - */ -public class MybatisEntityFactory extends DefaultObjectFactory { - - private static final long serialVersionUID = -7388760632000329910L; - - private transient EntityFactory entityFactory; - - public MybatisEntityFactory(EntityFactory entityFactory) { - this.entityFactory = entityFactory; - } - - @Override - protected Class resolveInterface(Class type) { - Class classToCreate; - if (type == List.class || type == Collection.class || type == Iterable.class) { - classToCreate = ArrayList.class; - } else if (type == Map.class) { - classToCreate = HashMap.class; - } else if (type == SortedSet.class) { // issue #510 Collections Support - classToCreate = TreeSet.class; - } else if (type == Set.class) { - classToCreate = HashSet.class; - } else { - // entity interface - classToCreate = entityFactory.getInstanceType(type); - } - return classToCreate; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisMapperCustomizer.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisMapperCustomizer.java deleted file mode 100644 index 14f969a08..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisMapperCustomizer.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.hswebframework.web.dao.mybatis; - -/** - * 排除不需要加载的mapper.xml - * - * @author zhouhao - * @since 3.0 - */ -public interface MybatisMapperCustomizer { - String[] getExcludes(); - - String[] getIncludes(); -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisProperties.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisProperties.java deleted file mode 100644 index 1fd4d85dd..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisProperties.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis; - -import org.hswebframework.web.datasource.DataSourceHolder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; - -import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; - -/** - * mybatis配置,继承官方配置类,增加一些属性以拓展更多功能 - *
    - *
  • 是否启用动态数据源{@link this#dynamicDatasource}
  • - *
  • 可设置不加载的配置{@link this#mapperLocationExcludes}
  • - *
- * - * @author zhouhao - * @see org.mybatis.spring.boot.autoconfigure.MybatisProperties - * @since 3.0 - */ -public class MybatisProperties extends org.mybatis.spring.boot.autoconfigure.MybatisProperties { - /** - * 默认支持的hsweb mapper - */ - private static final String defaultMapperLocation = "classpath*:org/hswebframework/web/dao/mybatis/mappers/**/*.xml"; - /** - * 是否启用动态数据源 - * 启用后调用{@link DataSourceHolder#switcher()},mybatis也会进行数据源切换 - * - * @see DataSourceHolder#switcher() - */ - private boolean dynamicDatasource = false; - /** - * 排除加载的mapper.xml - * 想自定义mapper并覆盖原始mapper的场景下,通过设置此属性来排除配置文件。 - * 排除使用{@link Resource#getURL()#toString()}进行对比 - */ - private String[] mapperLocationExcludes = null; - /** - * 使用jpa注解来解析表结构,动态生成查询条件 - */ - private boolean useJpa = true; - - private List mybatisMappers; - - @Autowired(required = false) - public void setMybatisMappers(List mybatisMappers) { - this.mybatisMappers = mybatisMappers; - } - - public String[] getMapperLocationExcludes() { - return mapperLocationExcludes; - } - - public void setMapperLocationExcludes(String[] mapperLocationExcludes) { - this.mapperLocationExcludes = mapperLocationExcludes; - } - - public boolean isDynamicDatasource() { - return dynamicDatasource; - } - - public void setDynamicDatasource(boolean dynamicDatasource) { - this.dynamicDatasource = dynamicDatasource; - } - - public void setUseJpa(boolean useJpa) { - this.useJpa = useJpa; - } - - public boolean isUseJpa() { - return useJpa; - } - - @Override - public Resource[] resolveMapperLocations() { - Map resources = new HashMap<>(); - Set locations; - - if (this.getMapperLocations() == null) { - locations = new HashSet<>(); - } else { - locations = Arrays.stream(getMapperLocations()).collect(Collectors.toSet()); - } - - locations.add(defaultMapperLocation); - - if (mybatisMappers != null) { - mybatisMappers.stream() - .map(MybatisMapperCustomizer::getIncludes) - .flatMap(Arrays::stream) - .forEach(locations::add); - } - - for (String mapperLocation : locations) { - Resource[] mappers; - try { - mappers = new PathMatchingResourcePatternResolver().getResources(mapperLocation); - for (Resource mapper : mappers) { - resources.put(mapper.getURL().toString(), mapper); - } - } catch (IOException e) { - } - } - Set excludes = new HashSet<>(); - if (mybatisMappers != null) { - mybatisMappers.stream() - .map(MybatisMapperCustomizer::getExcludes) - .flatMap(Arrays::stream) - .forEach(excludes::add); - } - if (mapperLocationExcludes != null && mapperLocationExcludes.length > 0) { - for (String exclude : mapperLocationExcludes) { - excludes.add(exclude); - } - } - PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); - //排除不需要的配置 - for (String mapperLocationExclude : excludes) { - try { - Resource[] excludesMappers = resourcePatternResolver.getResources(mapperLocationExclude); - for (Resource excludesMapper : excludesMappers) { - resources.remove(excludesMapper.getURL().toString()); - } - } catch (IOException e) { - } - } - Resource[] mapperLocations = new Resource[resources.size()]; - mapperLocations = resources.values().toArray(mapperLocations); - return mapperLocations; - } - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisUtils.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisUtils.java deleted file mode 100644 index 7daf31415..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MybatisUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis; - -import org.apache.ibatis.mapping.ResultMap; -import org.apache.ibatis.session.SqlSessionFactory; - -import java.util.concurrent.CountDownLatch; - -/** - * @since 2.0 - */ -public class MybatisUtils { - volatile static SqlSessionFactory sqlSession; - - public static ResultMap getResultMap(String id) { - return getSqlSession().getConfiguration().getResultMap(id); - } - - public static SqlSessionFactory getSqlSession() { - if (sqlSession == null) { - throw new UnsupportedOperationException("sqlSession is null"); - } - return sqlSession; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java deleted file mode 100644 index b819435d3..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java +++ /dev/null @@ -1,546 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.builder; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.PropertyUtilsBean; -import org.apache.ibatis.mapping.ResultMap; -import org.apache.ibatis.mapping.ResultMapping; -import org.hswebframework.ezorm.core.ValueConverter; -import org.hswebframework.ezorm.core.param.*; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.meta.RDBDatabaseMetaData; -import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData; -import org.hswebframework.ezorm.rdb.meta.converter.BooleanValueConverter; -import org.hswebframework.ezorm.rdb.meta.converter.DateTimeConverter; -import org.hswebframework.ezorm.rdb.meta.converter.NumberValueConverter; -import org.hswebframework.ezorm.rdb.render.Sql; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.SqlRender; -import org.hswebframework.ezorm.rdb.render.dialect.*; -import org.hswebframework.ezorm.rdb.render.support.simple.CommonSqlRender; -import org.hswebframework.ezorm.rdb.render.support.simple.SimpleWhereSqlBuilder; -import org.hswebframework.web.BusinessException; -import org.hswebframework.web.bean.FastBeanCopier; -import org.hswebframework.web.commons.entity.Entity; -import org.hswebframework.web.commons.entity.factory.EntityFactory; -import org.hswebframework.web.dao.mybatis.builder.jpa.JpaAnnotationParser; -import org.hswebframework.web.dao.mybatis.handler.NumberBooleanTypeHandler; -import org.hswebframework.web.dao.mybatis.plgins.pager.Pager; -import org.hswebframework.web.dao.mybatis.MybatisUtils; -import org.hswebframework.utils.StringUtils; -import org.hswebframework.web.datasource.DataSourceHolder; -import org.hswebframework.web.datasource.DatabaseType; - -import java.sql.JDBCType; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - - -/** - * 使用easyorm 动态构建 sql - * - * @author zhouhao - * @since 2.0 - */ -@Slf4j -public class EasyOrmSqlBuilder { - - public volatile boolean useJpa = false; - - public EntityFactory entityFactory; - - private static final EasyOrmSqlBuilder instance = new EasyOrmSqlBuilder(); - protected static final Map simpleName = new HashMap<>(); - - protected PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils(); - - public static EasyOrmSqlBuilder getInstance() { - return instance; - } - - private EasyOrmSqlBuilder() { - } - - static { - simpleName.put(Integer.class, "int"); - simpleName.put(Byte.class, "byte"); - simpleName.put(Double.class, "double"); - simpleName.put(Float.class, "float"); - simpleName.put(Boolean.class, "boolean"); - simpleName.put(Long.class, "long"); - simpleName.put(Short.class, "short"); - simpleName.put(Character.class, "char"); - simpleName.put(String.class, "string"); - simpleName.put(int.class, "int"); - simpleName.put(double.class, "double"); - simpleName.put(float.class, "float"); - simpleName.put(boolean.class, "boolean"); - simpleName.put(long.class, "long"); - simpleName.put(short.class, "short"); - simpleName.put(char.class, "char"); - simpleName.put(byte.class, "byte"); - } - - public static String getJavaType(Class type) { - String javaType = simpleName.get(type); - if (javaType == null) { - javaType = type.getName(); - } - return javaType; - } - - public static final RDBDatabaseMetaData mysql = new MysqlMeta(); - public static final RDBDatabaseMetaData oracle = new OracleMeta(); - public static final RDBDatabaseMetaData h2 = new H2Meta(); - public static final RDBDatabaseMetaData postgresql = new PGMeta(); - public static final RDBDatabaseMetaData mssql = new MSSQLMeta(); - - private final ConcurrentMap> metaCache = new ConcurrentHashMap<>(); - - public RDBDatabaseMetaData getActiveDatabase() { - DatabaseType type = DataSourceHolder.currentDatabaseType(); - switch (type) { - case mysql: - return mysql; - case oracle: - return oracle; - case postgresql: - return postgresql; - case h2: - return h2; - case jtds_sqlserver: - case sqlserver: - return mssql; - default: - log.warn("不支持的数据库类型:[{}]", type); - return h2; - } - } - - private String getRealTableName(String tableName) { - - String newTable = DataSourceHolder.tableSwitcher().getTable(tableName); - - if (!tableName.equals(newTable)) { - log.debug("use new table [{}] for [{}]", newTable, tableName); - } - return newTable; - - } - - private List createColumn(String prefix, String columnName, ResultMapping resultMapping) { - List metaData = new ArrayList<>(); - if (resultMapping.getNestedQueryId() == null) { - - if (resultMapping.getNestedResultMapId() != null) { - ResultMap nests = MybatisUtils.getResultMap(resultMapping.getNestedResultMapId()); - Set resultMappings = new HashSet<>(nests.getResultMappings()); - resultMappings.addAll(nests.getIdResultMappings()); - for (ResultMapping mapping : resultMappings) { - metaData.addAll(createColumn(resultMapping.getProperty(), - org.springframework.util.StringUtils.hasText(resultMapping.getColumn()) - ? resultMapping.getColumn() - : resultMapping.getProperty(), - mapping)); - } - return metaData; - } - - JDBCType jdbcType = JDBCType.VARCHAR; - try { - jdbcType = JDBCType.valueOf(resultMapping.getJdbcType().name()); - } catch (Exception e) { - log.warn("can not parse jdbcType:{}", resultMapping.getJdbcType()); - } - RDBColumnMetaData column = new RDBColumnMetaData(); - column.setJdbcType(jdbcType); - column.setName(org.springframework.util.StringUtils.hasText(columnName) - ? columnName.concat(".").concat(resultMapping.getColumn()) : resultMapping.getColumn()); - - if (resultMapping.getTypeHandler() != null) { - column.setProperty("typeHandler", resultMapping.getTypeHandler().getClass().getName()); - } - if (!StringUtils.isNullOrEmpty(resultMapping.getProperty())) { - column.setAlias(org.springframework.util.StringUtils.hasText(prefix) - ? prefix.concat(".").concat(resultMapping.getProperty()) : resultMapping.getProperty()); - - } - column.setJavaType(resultMapping.getJavaType()); - column.setProperty("resultMapping", resultMapping); - metaData.add(column); - } - return metaData; - } - - protected RDBTableMetaData createMeta(String tableName, String resultMapId) { -// tableName = getRealTableName(tableName); - RDBDatabaseMetaData active = getActiveDatabase(); - String cacheKey = tableName.concat("-").concat(resultMapId); - Map cache = metaCache.computeIfAbsent(active, k -> new ConcurrentHashMap<>()); - - RDBTableMetaData cached = cache.get(cacheKey); - if (cached != null) { - return cached; - } - - RDBTableMetaData rdbTableMetaData = new RDBTableMetaData() { - @Override - public String getName() { - //动态切换表名 - return getRealTableName(tableName); - } - }; - ResultMap resultMaps = MybatisUtils.getResultMap(resultMapId); - rdbTableMetaData.setName(tableName); - rdbTableMetaData.setDatabaseMetaData(active); - - List resultMappings = new ArrayList<>(resultMaps.getResultMappings()); - resultMappings.addAll(resultMaps.getIdResultMappings()); - - resultMappings.stream() - .map(mapping -> this.createColumn(null, null, mapping)) - .flatMap(Collection::stream) - .forEach(rdbTableMetaData::addColumn); - - if (useJpa) { - Class type = entityFactory == null ? resultMaps.getType() : entityFactory.getInstanceType(resultMaps.getType()); - RDBTableMetaData parseResult = JpaAnnotationParser.parseMetaDataFromEntity(type); - if (parseResult != null) { - for (RDBColumnMetaData columnMetaData : parseResult.getColumns()) { - if (rdbTableMetaData.findColumn(columnMetaData.getName()) == null) { - columnMetaData = columnMetaData.clone(); - columnMetaData.setProperty("fromJpa", true); - rdbTableMetaData.addColumn(columnMetaData); - } - } - } - } - for (RDBColumnMetaData column : rdbTableMetaData.getColumns()) { - //时间 - if (column.getJdbcType() == JDBCType.DATE || column.getJdbcType() == JDBCType.TIMESTAMP) { - ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) { - @Override - public Object getData(Object value) { - if (value instanceof Number) { - return new Date(((Number) value).longValue()); - } - return super.getData(value); - } - }; - column.setValueConverter(dateConvert); - } else if (column.getJavaType() == boolean.class || column.getJavaType() == Boolean.class) { - column.setValueConverter(new BooleanValueConverter(column.getJdbcType())); - column.setProperty("typeHandler", NumberBooleanTypeHandler.class.getName()); - } else if (TypeUtils.isNumberType(column)) { //数字 - //数字 - column.setValueConverter(new NumberValueConverter(column.getJavaType())); - } - } - cache.put(cacheKey, rdbTableMetaData); - return rdbTableMetaData; - } - - public String buildUpdateFields(String resultMapId, String tableName, UpdateParam param) { - Pager.reset(); - param.excludes("id"); - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - RDBDatabaseMetaData databaseMetaDate = getActiveDatabase(); - Dialect dialect = databaseMetaDate.getDialect(); - CommonSqlRender render = (CommonSqlRender) databaseMetaDate.getRenderer(SqlRender.TYPE.SELECT); - List columns = render.parseOperationField(tableMetaData, param); - SqlAppender appender = new SqlAppender(); - Object data = param.getData(); - Map mapData = FastBeanCopier.copy(data, HashMap::new); - - columns.forEach(column -> { - - RDBColumnMetaData columnMetaData = column.getRDBColumnMetaData(); - if (columnMetaData == null) { - return; - } - if (columnMetaData.getName().contains(".")) { - return; - } - if (columnMetaData.getProperty("read-only").isTrue()) { - return; - } - Object value = mapData.get(columnMetaData.getAlias()); - - if (value == null) { - return; - } - - if (value instanceof Sql) { - appender.add(",", encodeColumn(dialect, columnMetaData.getName()), "=", ((Sql) value).getSql()); - } else { - value = columnMetaData.getValueConverter().getData(value); - - if (columnMetaData.getOptionConverter() != null) { - value = columnMetaData.getOptionConverter().converterData(value); - } - - mapData.put(columnMetaData.getAlias(), value); - - String typeHandler = columnMetaData.getProperty("typeHandler").getValue(); - - appender.add(",", encodeColumn(dialect, columnMetaData.getName()) - , "=", "#{data.", columnMetaData.getAlias(), - ",javaType=", EasyOrmSqlBuilder.getJavaType(columnMetaData.getJavaType()), - ",jdbcType=", columnMetaData.getJdbcType(), - typeHandler != null ? ",typeHandler=" + typeHandler : "", - "}"); - } - }); - if (!appender.isEmpty()) { - appender.removeFirst(); - } else { - throw new UnsupportedOperationException("没有列被修改"); - } - return appender.toString(); - } - - public String encodeColumn(Dialect dialect, String field) { - if (field.contains(".")) { - String[] tmp = field.split("[.]"); - return tmp[0] + "." + dialect.getQuoteStart() + (dialect.columnToUpperCase() ? (tmp[1].toUpperCase()) : tmp[1]) + dialect.getQuoteEnd(); - } else { - return dialect.getQuoteStart() + (dialect.columnToUpperCase() ? (field.toUpperCase()) : field) + dialect.getQuoteEnd(); - } - } - - public String buildInsertSql(String resultMapId, String tableName, Object param) { - Pager.reset(); - InsertParam insertParam; - if (param instanceof InsertParam) { - insertParam = ((InsertParam) param); - } else { - insertParam = new InsertParam<>(param); - } - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - SqlRender render = tableMetaData.getDatabaseMetaData().getRenderer(SqlRender.TYPE.INSERT); - return render.render(tableMetaData, insertParam).getSql(); - } - - public String buildUpdateSql(String resultMapId, String tableName, UpdateParam param) { - Pager.reset(); - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - SqlRender render = tableMetaData.getDatabaseMetaData().getRenderer(SqlRender.TYPE.UPDATE); - return render.render(tableMetaData, param).getSql(); - } - - public String buildSelectFields(String resultMapId, String tableName, Object arg) { - QueryParam param = null; - if (arg instanceof QueryParam) { - param = ((QueryParam) arg); - if (param.isPaging()) { - if (Pager.get() == null) { - Pager.doPaging(param.getPageIndex(), param.getPageSize()); - } - } else { - Pager.reset(); - } - } - if (param == null) { - return "*"; - } - - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - RDBDatabaseMetaData databaseMetaDate = getActiveDatabase(); - Dialect dialect = databaseMetaDate.getDialect(); - CommonSqlRender render = (CommonSqlRender) databaseMetaDate.getRenderer(SqlRender.TYPE.SELECT); - List columns = render.parseOperationField(tableMetaData, param); - SqlAppender appender = new SqlAppender(); - columns.forEach(column -> { - RDBColumnMetaData columnMetaData = column.getRDBColumnMetaData(); - if (columnMetaData == null) { - return; - } - String cname = columnMetaData.getName(); - if (!cname.contains(".")) { - cname = tableMetaData.getName().concat(".").concat(cname); - } - boolean isJpa = columnMetaData.getProperty("fromJpa", false).isTrue(); - - appender.add(",", encodeColumn(dialect, cname) - , " AS " - , dialect.getQuoteStart() - , isJpa ? columnMetaData.getAlias() : columnMetaData.getName() - , dialect.getQuoteEnd()); - }); - param.getIncludes().remove("*"); - if (appender.isEmpty()) { - return "*"; - } - appender.removeFirst(); - return appender.toString(); - } - - public String buildOrder(String resultMapId, String tableName, Object arg) { - QueryParam param = null; - if (arg instanceof QueryParam) { - param = ((QueryParam) arg); - } - if (param == null) { - return ""; - } - - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - SqlAppender appender = new SqlAppender(" order by "); - param.getSorts() - .forEach(sort -> { - RDBColumnMetaData column = tableMetaData.getColumn(sort.getName()); - if (column == null) { - column = tableMetaData.findColumn(sort.getName()); - } - if (column == null) { - return; - } - String cname = column.getName(); - if (!cname.contains(".")) { - cname = tableMetaData.getName().concat(".").concat(cname); - } - appender.add(encodeColumn(tableMetaData.getDatabaseMetaData().getDialect(), cname), " ", sort.getOrder(), ","); - }); - if (appender.isEmpty()) { - return ""; - } - appender.removeLast(); - return appender.toString(); - } - - public String buildWhereForUpdate(String resultMapId, String tableName, List terms) { - String where = buildWhere(resultMapId, tableName, terms); - if (where.trim().isEmpty()) { - throw new BusinessException("禁止执行无条件的更新操作"); - } - return where; - } - - public String buildWhereForUpdate(String resultMapId, String tableName, Object param) { - String where = buildWhere(resultMapId, tableName, param); - if (where.trim().isEmpty()) { - throw new BusinessException("禁止执行无条件的更新操作"); - } - return where; - } - - public String buildWhere(String resultMapId, String tableName, Object param) { - List terms; - if (param instanceof Param) { - terms = ((Param) param).getTerms(); - } else if (param instanceof Entity) { - terms = SqlParamParser.parseQueryParam(param).getTerms(); - } else { - terms = new ArrayList<>(); - } - if (param instanceof QueryParam) { - QueryParam queryParam = ((QueryParam) param); - if (queryParam.isPaging()) { - if (Pager.get() == null) { - Pager.doPaging(queryParam.getPageIndex(), queryParam.getPageSize()); - } - } else { - Pager.reset(); - } - } - return buildWhere(resultMapId, tableName, terms); - } - - public String buildWhere(String resultMapId, String tableName, List terms) { - RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId); - RDBDatabaseMetaData databaseMetaDate = getActiveDatabase(); - SimpleWhereSqlBuilder builder = new SimpleWhereSqlBuilder() { - @Override - public Dialect getDialect() { - return databaseMetaDate.getDialect(); - } - }; - SqlAppender appender = new SqlAppender(); - builder.buildWhere(tableMetaData, "", terms, appender, new HashSet<>()); - return appender.toString(); - } - - static class MysqlMeta extends MysqlRDBDatabaseMetaData { - MysqlMeta() { - super(); - renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder()); - renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.MYSQL)); - } - - @Override - public String getDatabaseName() { - return DataSourceHolder.databaseSwitcher().currentDatabase(); - } - } - - static class OracleMeta extends OracleRDBDatabaseMetaData { - OracleMeta() { - super(); - renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder()); - renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.ORACLE)); - } - - @Override - public String getDatabaseName() { - return DataSourceHolder.databaseSwitcher().currentDatabase(); - } - } - - static class H2Meta extends H2RDBDatabaseMetaData { - H2Meta() { - super(); - renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder()); - renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.H2)); - } - - @Override - public String getDatabaseName() { - return DataSourceHolder.databaseSwitcher().currentDatabase(); - } - } - - static class PGMeta extends PGRDBDatabaseMetaData { - PGMeta() { - super(); - renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder()); - renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.POSTGRES)); - } - - @Override - public String getDatabaseName() { - return DataSourceHolder.databaseSwitcher().currentDatabase(); - } - } - - static class MSSQLMeta extends MSSQLRDBDatabaseMetaData { - MSSQLMeta() { - super(); - renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder()); - renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.MSSQL)); - } - - @Override - public String getDatabaseName() { - return DataSourceHolder.databaseSwitcher().currentDatabase(); - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/InsertSqlBuilder.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/InsertSqlBuilder.java deleted file mode 100644 index cc6a7476f..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/InsertSqlBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.builder; - -import org.hswebframework.ezorm.core.param.InsertParam; -import org.hswebframework.ezorm.rdb.executor.SQL; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.support.simple.SimpleInsertSqlRender; - -/** - * @author zhouhao - */ -public class InsertSqlBuilder extends SimpleInsertSqlRender { - @Override - public SQL render(RDBTableMetaData metaData, InsertParam param) { - RDBTableMetaData metaDataNew = metaData.clone(); - metaDataNew.setDatabaseMetaData(metaData.getDatabaseMetaData()); - metaDataNew.getColumns().stream() - .filter(column -> column.getName().contains(".")) - .map(RDBColumnMetaData::getName) - .forEach(metaDataNew::removeColumn); - return super.render(metaDataNew, param); - } - - @Override - protected SqlAppender getParamString(String prefix, String paramName, RDBColumnMetaData rdbColumnMetaData) { - String typeHandler = rdbColumnMetaData.getProperty("typeHandler") - .getValue(); - - return new SqlAppender().add("#{", paramName, - ",javaType=", EasyOrmSqlBuilder.getJavaType(rdbColumnMetaData.getJavaType()), - ",jdbcType=", rdbColumnMetaData.getJdbcType(), - typeHandler != null ? ",typeHandler=" + typeHandler : "", - "}"); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlBuilder.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlBuilder.java deleted file mode 100644 index 70fe1f167..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.builder; - -/** - * @author zhouhao - */ -public class SqlBuilder { - public static final Object current() { - return EasyOrmSqlBuilder.getInstance(); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParser.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParser.java deleted file mode 100644 index 073552d9d..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParser.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder; - -import org.hswebframework.ezorm.core.dsl.Query; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.utils.StringUtils; -import org.hswebframework.web.bean.FastBeanCopier; -import org.hswebframework.web.commons.entity.Entity; -import org.hswebframework.web.commons.entity.param.QueryParamEntity; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; - -/** - * @author zhouhao - * @since 3.0 - */ -public class SqlParamParser { - - public static QueryParamEntity parseQueryParam(Object param) { - return new QueryParamParser().parse(param).get(); - } - - private static class QueryParamParser { - private Query query = Query.empty(new QueryParamEntity()); - - private BiConsumer consumer = (k, v) -> { - if (k.endsWith("$or")) { - k = k.substring(0, k.length() - 3); - query.or(k, v); - } else { - query.and(k, v); - } - }; - - private QueryParamParser parse(Object obj) { - if (obj instanceof Map) { - ((Map) obj).forEach((k, v) -> { - String key = String.valueOf(k); - if ("pageIndex".equals(key)) { - query.getParam().setPageIndex(StringUtils.toInt(v)); - } - if ("pageSize".equals(key)) { - query.getParam().setPageSize(StringUtils.toInt(v)); - } - if (v != null) { - if (v instanceof Entity || v instanceof Map) { - List terms = new QueryParamParser().parse(v).get().getTerms(); - Term term = new Term(); - term.setType(key.equalsIgnoreCase("or") ? Term.Type.or : Term.Type.and); - term.setTerms(terms); - query.getParam().getTerms().add(term); - } else { - consumer.accept(String.valueOf(key), v); - } - } - }); - } else { - parse(FastBeanCopier.copy(obj, new LinkedHashMap<>())); - } - return this; - } - - private QueryParamEntity get() { - return query.getParam(); - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/TypeUtils.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/TypeUtils.java deleted file mode 100644 index fedb2e6cf..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/TypeUtils.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder; - -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.JDBCType; -import java.util.Arrays; -import java.util.List; - -/** - * @author zhouhao - * @since 3.0.3 - */ -public class TypeUtils { - private static final List numberType = Arrays.asList( - byte.class, Byte.class - , short.class, Short.class - , int.class, Integer.class - , float.class, Float.class - , double.class, Double.class - , long.class, Long.class - , BigDecimal.class, BigInteger.class - ); - - private static final List numberJdbcType = Arrays.asList( - JDBCType.TINYINT, JDBCType.DECIMAL, JDBCType.NUMERIC, - JDBCType.BIGINT, JDBCType.SMALLINT, JDBCType.INTEGER, - JDBCType.DECIMAL, JDBCType.BIT - ); - - public static boolean isNumberType(RDBColumnMetaData columnMetaData) { - return numberType.contains(columnMetaData.getJavaType()) - || Number.class.isAssignableFrom(columnMetaData.getJavaType()) - || numberJdbcType.contains(columnMetaData.getJdbcType()); - } - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/UpdateSqlBuilder.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/UpdateSqlBuilder.java deleted file mode 100644 index 1404091eb..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/UpdateSqlBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.builder; - -import org.hswebframework.ezorm.core.param.UpdateParam; -import org.hswebframework.ezorm.rdb.executor.SQL; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.hswebframework.ezorm.rdb.render.support.simple.SimpleUpdateSqlRender; - -/** - * @author zhouhao - */ -public class UpdateSqlBuilder extends SimpleUpdateSqlRender { - public UpdateSqlBuilder(Dialect dialect) { - super(dialect); - } - - @Override - public SQL render(RDBTableMetaData metaData, UpdateParam param) { - RDBTableMetaData metaDataNew = metaData.clone(); - metaDataNew.setDatabaseMetaData(metaData.getDatabaseMetaData()); - - metaDataNew.getColumns().stream() - .filter(column -> column.getName().contains(".")) - .map(RDBColumnMetaData::getName) - .forEach(metaDataNew::removeColumn); - return super.render(metaDataNew, param); - } - - @Override - protected SqlAppender getParamString(String paramName, RDBColumnMetaData rdbColumnMetaData) { - String typeHandler = rdbColumnMetaData.getProperty("typeHandler") - .getValue(); - - return new SqlAppender().add("#{", paramName, - ",javaType=", EasyOrmSqlBuilder.getJavaType(rdbColumnMetaData.getJavaType()), - ",jdbcType=", rdbColumnMetaData.getJdbcType(), - typeHandler != null ? ",typeHandler=" + typeHandler : "", "}"); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParser.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParser.java deleted file mode 100644 index 0da0dfece..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParser.java +++ /dev/null @@ -1,194 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder.jpa; - - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtilsBean; -import org.hswebframework.ezorm.core.ValueConverter; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData; -import org.hswebframework.ezorm.rdb.meta.converter.BooleanValueConverter; -import org.hswebframework.ezorm.rdb.meta.converter.DateTimeConverter; -import org.hswebframework.ezorm.rdb.meta.converter.NumberValueConverter; -import org.hswebframework.utils.ClassUtils; -import org.hswebframework.web.dao.mybatis.builder.TypeUtils; -import org.hswebframework.web.dict.EnumDict; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.util.StringUtils; - -import javax.persistence.*; -import java.beans.PropertyDescriptor; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.JDBCType; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.BiFunction; -import java.util.function.Function; - -/** - * jpa 注解解析器 - * - * @author zhouhao - * @since 3.0 - */ -@Slf4j -public class JpaAnnotationParser { - - private static final Map jdbcTypeMapping = new HashMap<>(); - - private static final List> jdbcTypeConvert = new ArrayList<>(); - - static { - jdbcTypeMapping.put(String.class, JDBCType.VARCHAR); - - jdbcTypeMapping.put(Byte.class, JDBCType.TINYINT); - jdbcTypeMapping.put(byte.class, JDBCType.TINYINT); - - jdbcTypeMapping.put(Short.class, JDBCType.INTEGER); - jdbcTypeMapping.put(short.class, JDBCType.INTEGER); - - jdbcTypeMapping.put(Integer.class, JDBCType.INTEGER); - jdbcTypeMapping.put(int.class, JDBCType.INTEGER); - - jdbcTypeMapping.put(Character.class, JDBCType.CHAR); - jdbcTypeMapping.put(char.class, JDBCType.CHAR); - - jdbcTypeMapping.put(Long.class, JDBCType.BIGINT); - jdbcTypeMapping.put(long.class, JDBCType.BIGINT); - - jdbcTypeMapping.put(Double.class, JDBCType.DECIMAL); - jdbcTypeMapping.put(double.class, JDBCType.DECIMAL); - - jdbcTypeMapping.put(Float.class, JDBCType.DECIMAL); - jdbcTypeMapping.put(float.class, JDBCType.DECIMAL); - - jdbcTypeMapping.put(Boolean.class, JDBCType.BIT); - jdbcTypeMapping.put(boolean.class, JDBCType.BIT); - - jdbcTypeMapping.put(byte[].class, JDBCType.BLOB); - - jdbcTypeMapping.put(BigDecimal.class, JDBCType.DECIMAL); - jdbcTypeMapping.put(BigInteger.class, JDBCType.INTEGER); - - jdbcTypeMapping.put(Date.class, JDBCType.TIMESTAMP); - jdbcTypeMapping.put(java.sql.Date.class, JDBCType.TIMESTAMP); - jdbcTypeMapping.put(java.sql.Timestamp.class, JDBCType.TIMESTAMP); - - jdbcTypeMapping.put(Object.class, JDBCType.VARCHAR); - - jdbcTypeConvert.add((type, property) -> { - Enumerated enumerated = getAnnotation(type, property, Enumerated.class); - return enumerated != null ? JDBCType.VARCHAR : null; - }); - jdbcTypeConvert.add((type, property) -> { - Lob enumerated = getAnnotation(type, property, Lob.class); - return enumerated != null ? JDBCType.CLOB : null; - }); - - jdbcTypeConvert.add((type, property) -> { - boolean isArray = type.isArray(); - if (isArray) { - type = type.getComponentType(); - - } - if (type.isEnum() && EnumDict.class.isAssignableFrom(type)) { - Class genType = ClassUtils.getGenericType(type); - if (isArray) { - return JDBCType.BIGINT; - } - return jdbcTypeMapping.getOrDefault(genType, JDBCType.VARCHAR); - } - return null; - }); - } - - - private static List parseColumnMeta(String prefix, String columnName, Class entityClass) { - - PropertyDescriptor[] descriptors = BeanUtilsBean.getInstance() - .getPropertyUtils() - .getPropertyDescriptors(entityClass); - List columnMetaDataList = new ArrayList<>(); - - for (PropertyDescriptor descriptor : descriptors) { - Column columnAnn = getAnnotation(entityClass, descriptor, Column.class); - CollectionTable collectionTable = getAnnotation(entityClass, descriptor, CollectionTable.class); - - if (columnAnn == null) { - if (collectionTable != null) { - columnMetaDataList.addAll(parseColumnMeta(descriptor.getName(), collectionTable.name(), descriptor.getPropertyType())); - continue; - } - continue; - } - - String realName = StringUtils.hasText(columnAnn.name()) ? columnAnn.name() : descriptor.getName(); - String realAlias = StringUtils.hasText(prefix) ? prefix.concat(".").concat(descriptor.getName()) : descriptor.getName(); - - RDBColumnMetaData column = new RDBColumnMetaData(); - column.setName(StringUtils.hasText(columnName) ? columnName.concat(".").concat(realName) : realName); - column.setAlias(realAlias); - column.setLength(columnAnn.length()); - column.setPrecision(columnAnn.precision()); - column.setJavaType(descriptor.getPropertyType()); - if (!columnAnn.updatable()) { - column.setProperty("read-only", true); - } - if (!columnAnn.nullable()) { - column.setNotNull(true); - } - if (StringUtils.hasText(columnAnn.columnDefinition())) { - column.setColumnDefinition(columnAnn.columnDefinition()); - } - Class propertyType = descriptor.getPropertyType(); - - JDBCType type = jdbcTypeMapping.get(propertyType); - if (type == null) { - type = jdbcTypeConvert.stream() - .map(func -> func.apply(entityClass, descriptor)) - .filter(Objects::nonNull) - .findFirst() - .orElse(JDBCType.OTHER); - } - column.setJdbcType(type); - columnMetaDataList.add(column); - } - return columnMetaDataList; - } - - public static RDBTableMetaData parseMetaDataFromEntity(Class entityClass) { - Table table = AnnotationUtils.findAnnotation(entityClass, Table.class); - if (table == null) { - return null; - } - RDBTableMetaData tableMetaData = new RDBTableMetaData(); - tableMetaData.setName(table.name()); - parseColumnMeta(null, null, entityClass).forEach(tableMetaData::addColumn); - return tableMetaData; - } - - - private static T getAnnotation(Class entityClass, PropertyDescriptor descriptor, Class type) { - T ann = null; - try { - Field field = entityClass.getDeclaredField(descriptor.getName()); - ann = AnnotationUtils.findAnnotation(field, type); - } catch (@SuppressWarnings("all") NoSuchFieldException ignore) { - if (entityClass.getSuperclass() != Object.class) { - return getAnnotation(entityClass.getSuperclass(), descriptor, type); - } - } - Method read = descriptor.getReadMethod(), - write = descriptor.getWriteMethod(); - if (null == ann && read != null) { - ann = AnnotationUtils.findAnnotation(read, type); - } - if (null == ann && write != null) { - ann = AnnotationUtils.findAnnotation(write, type); - } - return ann; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java deleted file mode 100644 index f3436ee90..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicDataSourceSqlSessionFactoryBuilder.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.dynamic; - -import org.apache.ibatis.session.Configuration; -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.session.SqlSessionFactoryBuilder; - -public class DynamicDataSourceSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder { - @Override - public SqlSessionFactory build(Configuration config) { - return new DynamicSqlSessionFactory(config); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSpringManagedTransaction.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSpringManagedTransaction.java deleted file mode 100644 index ed5bda268..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSpringManagedTransaction.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.dynamic; - -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.logging.LogFactory; -import org.apache.ibatis.transaction.Transaction; -import org.hswebframework.web.datasource.DataSourceHolder; -import org.mybatis.spring.transaction.SpringManagedTransaction; -import org.springframework.jdbc.datasource.ConnectionHolder; -import org.springframework.jdbc.datasource.DataSourceUtils; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import static org.hswebframework.web.datasource.DataSourceHolder.switcher; - -/** - * mybatis 同一事务,同一个mapper,动态数据源切换支持 - * - * @author zhouhao - */ -public class DynamicSpringManagedTransaction implements Transaction { - - private static final Log LOGGER = LogFactory.getLog(SpringManagedTransaction.class); - - private Map connectionMap = new HashMap<>(); - - /** - * 当前数据源对应的事务代理 - * - * @return {@link TransactionProxy} - */ - protected TransactionProxy getProxy() { - return connectionMap.get(switcher().currentDataSourceId()); - } - - /** - * 添加一个事务代理 - * - * @param proxy - */ - protected void addProxy(TransactionProxy proxy) { - connectionMap.put(switcher().currentDataSourceId(), proxy); - } - - /** - * 获取所有代理 - * - * @return - */ - protected Collection getAllProxy() { - return connectionMap.values(); - } - - @Override - public Connection getConnection() throws SQLException { - TransactionProxy proxy = getProxy(); - if (proxy != null) { - return proxy.getConnection(); - } - //根据当前激活的数据源 获取jdbc链接 - DataSource dataSource = DataSourceHolder.currentDataSource().getNative(); - String dsId = switcher().currentDataSourceId(); - Connection connection = DataSourceUtils.getConnection(dataSource); - proxy = new TransactionProxy(dsId, connection, dataSource); - addProxy(proxy); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug( - "DataSource (" + (dsId == null ? "default" : dsId) + ") JDBC Connection [" - + connection - + "] will" - + (proxy.isConnectionTransactional ? " " : " not ") - + "be managed by Spring"); - } - - return connection; - } - - @Override - public void commit() throws SQLException { - for (TransactionProxy proxy : getAllProxy()) { - proxy.commit(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void rollback() throws SQLException { - for (TransactionProxy proxy : getAllProxy()) { - proxy.rollback(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void close() throws SQLException { - SQLException tmp = null; - for (TransactionProxy proxy : getAllProxy()) { - try { - proxy.close(); - //保证每个链接都能被释放 - } catch (SQLException e) { - tmp = e; - } - } - connectionMap.clear(); - if (null != tmp) { - throw tmp; - } - } - - @Override - public Integer getTimeout() throws SQLException { - return getProxy().getTimeout(); - } - - class TransactionProxy implements Transaction { - Connection connection; - DataSource dataSource; - boolean isConnectionTransactional; - boolean autoCommit; - String dataSourceId; - - public TransactionProxy(String dataSourceId, Connection connection, DataSource dataSource) { - this.connection = connection; - this.dataSource = dataSource; - this.dataSourceId = dataSourceId; - this.isConnectionTransactional = DataSourceUtils.isConnectionTransactional(connection, dataSource); - try { - this.autoCommit = connection.getAutoCommit(); - } catch (SQLException e) { - } - } - - @Override - public Connection getConnection() throws SQLException { - return connection; - } - - /** - * {@inheritDoc} - */ - @Override - public void commit() throws SQLException { - if (this.connection != null && !this.isConnectionTransactional && !this.autoCommit) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Committing DataSource (" + (dataSourceId == null ? "default" : dataSourceId) + ") JDBC Connection [" + this.connection + "]"); - } - this.connection.commit(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void rollback() throws SQLException { - if (this.connection != null && !this.isConnectionTransactional && !this.autoCommit) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Rolling back DataSource (" + dataSourceId + ") JDBC Connection [" + this.connection + "]"); - } - this.connection.rollback(); - } - } - - @Override - public void close() throws SQLException { - DataSourceUtils.releaseConnection(connection, dataSource); - } - - @Override - public Integer getTimeout() throws SQLException { - ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource); - if (holder != null && holder.hasTimeout()) { - return holder.getTimeToLiveInSeconds(); - } - return null; - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSqlSessionFactory.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSqlSessionFactory.java deleted file mode 100644 index dcfe50382..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/dynamic/DynamicSqlSessionFactory.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.dynamic; - -import org.apache.ibatis.exceptions.ExceptionFactory; -import org.apache.ibatis.executor.ErrorContext; -import org.apache.ibatis.executor.Executor; -import org.apache.ibatis.mapping.Environment; -import org.apache.ibatis.session.*; -import org.apache.ibatis.session.defaults.DefaultSqlSession; -import org.apache.ibatis.transaction.Transaction; -import org.apache.ibatis.transaction.TransactionFactory; -import org.apache.ibatis.transaction.managed.ManagedTransactionFactory; -import org.hswebframework.web.datasource.DataSourceHolder; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; - -/** - * @author zhouhao - */ -public class DynamicSqlSessionFactory implements SqlSessionFactory { - private final Configuration configuration; - - public DynamicSqlSessionFactory(Configuration configuration) { - this.configuration = configuration; - } - - @Override - public SqlSession openSession() { - return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false); - } - - @Override - public SqlSession openSession(boolean autoCommit) { - return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, autoCommit); - } - - @Override - public SqlSession openSession(ExecutorType execType) { - return openSessionFromDataSource(execType, null, false); - } - - @Override - public SqlSession openSession(TransactionIsolationLevel level) { - return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false); - } - - @Override - public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) { - return openSessionFromDataSource(execType, level, false); - } - - @Override - public SqlSession openSession(ExecutorType execType, boolean autoCommit) { - return openSessionFromDataSource(execType, null, autoCommit); - } - - @Override - public SqlSession openSession(Connection connection) { - return openSessionFromConnection(configuration.getDefaultExecutorType(), connection); - } - - @Override - public SqlSession openSession(ExecutorType execType, Connection connection) { - return openSessionFromConnection(execType, connection); - } - - @Override - public Configuration getConfiguration() { - return configuration; - } - - @SuppressWarnings("all") - private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { - Transaction tx = null; - try { - final Environment environment = getConfiguration().getEnvironment(); - final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); - DataSource ds = DataSourceHolder.currentDataSource().getNative(); - if (ds == null) { - ds = environment.getDataSource(); - } - tx = transactionFactory.newTransaction(ds, level, autoCommit); - final Executor executor = getConfiguration().newExecutor(tx, execType); - return new DefaultSqlSession(getConfiguration(), executor, autoCommit); - } catch (Exception e) { - closeTransaction(tx); // may have fetched a connection so lets call close() - throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); - } finally { - ErrorContext.instance().reset(); - } - } - - private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) { - try { - boolean autoCommit; - try { - autoCommit = connection.getAutoCommit(); - } catch (SQLException e) { - // Failover to true, as most poor drivers - // or databases won't support transactions - autoCommit = true; - } - final Environment environment = configuration.getEnvironment(); - final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); - final Transaction tx = transactionFactory.newTransaction(connection); - final Executor executor = configuration.newExecutor(tx, execType); - return new DefaultSqlSession(configuration, executor, autoCommit); - } catch (Exception e) { - throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); - } finally { - ErrorContext.instance().reset(); - } - } - - private TransactionFactory getTransactionFactoryFromEnvironment(Environment environment) { - if (environment == null || environment.getTransactionFactory() == null) { - return new ManagedTransactionFactory(); - } - return environment.getTransactionFactory(); - } - - private void closeTransaction(Transaction tx) { - if (tx != null) { - try { - tx.close(); - } catch (SQLException ignore) { - // Intentionally ignore. Prefer previous error. - } - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonArrayHandler.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonArrayHandler.java deleted file mode 100644 index 6cd01d27a..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonArrayHandler.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.handler; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; -import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.type.*; -import org.springframework.util.StringUtils; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -@Alias("jsonArrayHandler") -@MappedTypes({List.class}) -@MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) -@Slf4j -public class JsonArrayHandler extends BaseTypeHandler> { - - private List parseArray(String json) { - if (!StringUtils.hasText(json)) { - return null; - } - return JSON.parseArray(json); - } - - @Override - public List getResult(ResultSet rs, int columnIndex) throws SQLException { - return parseArray(rs.getString(columnIndex)); - } - - @Override - public List getResult(ResultSet rs, String columnName) throws SQLException { - return parseArray(rs.getString(columnName)); - } - - @Override - public List getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parseArray(cs.getString(columnIndex)); - } - - @Override - public void setParameter(PreparedStatement ps, int i, List parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, JSON.toJSONString(parameter, SerializerFeature.WriteClassName)); - } - - @Override - public void setNonNullParameter(PreparedStatement ps, int i, List parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, "[]"); - } - - @Override - public List getNullableResult(ResultSet rs, String columnName) throws SQLException { - return new ArrayList<>(); - } - - @Override - public List getNullableResult(ResultSet rs, int columnIndex) throws SQLException { - return new ArrayList<>(); - } - - @Override - public List getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { - return new ArrayList<>(); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonMapHandler.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonMapHandler.java deleted file mode 100644 index f77bceeff..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonMapHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.handler; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.serializer.SerializerFeature; -import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.type.*; -import org.springframework.util.StringUtils; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; - -@Alias("jsonMapHandler") -@MappedTypes({Map.class}) -@MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) -@Slf4j -public class JsonMapHandler extends BaseTypeHandler> { - private Map parseObject(String json) { - if (!StringUtils.hasText(json)) { - return null; - } - return JSON.parseObject(json); - } - - @Override - public Map getResult(ResultSet rs, int columnIndex) throws SQLException { - return parseObject(rs.getString(columnIndex)); - } - - @Override - public Map getResult(ResultSet rs, String columnName) throws SQLException { - return parseObject(rs.getString(columnName)); - } - - @Override - public Map getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parseObject(cs.getString(columnIndex)); - } - - @Override - public void setParameter(PreparedStatement ps, int i, Map parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, JSON.toJSONString(parameter, SerializerFeature.WriteClassName)); - } - - @Override - public void setNonNullParameter(PreparedStatement ps, int i, Map parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, "{}"); - } - - @Override - public Map getNullableResult(ResultSet rs, String columnName) throws SQLException { - return new HashMap<>(); - } - - @Override - public Map getNullableResult(ResultSet rs, int columnIndex) throws SQLException { - return new HashMap<>(); - } - - @Override - public Map getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { - return new HashMap<>(); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonSetHandler.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonSetHandler.java deleted file mode 100644 index e2d5bf41f..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/JsonSetHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2019 http://www.hswebframework.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.hswebframework.web.dao.mybatis.handler; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; -import lombok.extern.slf4j.Slf4j; -import org.apache.ibatis.type.*; -import org.springframework.util.StringUtils; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; - -@Alias("jsonSetHandler") -@MappedTypes({Set.class}) -@MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) -@Slf4j -public class JsonSetHandler extends BaseTypeHandler { - - @SuppressWarnings("unchecked") - private Set parseSet(String json) { - if (!StringUtils.hasText(json)) { - return null; - } - return (Set) JSON.parseObject(json, Set.class); - } - - @Override - public Set getResult(ResultSet rs, int columnIndex) throws SQLException { - return parseSet(rs.getString(columnIndex)); - } - - @Override - public Set getResult(ResultSet rs, String columnName) throws SQLException { - return parseSet(rs.getString(columnName)); - } - - @Override - public Set getResult(CallableStatement cs, int columnIndex) throws SQLException { - return parseSet(cs.getString(columnIndex)); - } - - @Override - public void setParameter(PreparedStatement ps, int i, Set parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, JSON.toJSONString(parameter, SerializerFeature.WriteClassName)); - } - - @Override - public void setNonNullParameter(PreparedStatement ps, int i, Set parameter, JdbcType jdbcType) throws SQLException { - ps.setString(i, "[]"); - } - - @Override - public Set getNullableResult(ResultSet rs, String columnName) throws SQLException { - return new HashSet<>(); - } - - @Override - public Set getNullableResult(ResultSet rs, int columnIndex) throws SQLException { - return new HashSet<>(); - } - - @Override - public Set getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { - return new HashSet<>(); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/NumberBooleanTypeHandler.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/NumberBooleanTypeHandler.java deleted file mode 100644 index 5480ba9e9..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/handler/NumberBooleanTypeHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.hswebframework.web.dao.mybatis.handler; - -import org.apache.ibatis.type.*; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -@Alias("numberBooleanTypeHandler") -@MappedTypes({Boolean.class}) -@MappedJdbcTypes({JdbcType.NUMERIC, JdbcType.BOOLEAN}) -public class NumberBooleanTypeHandler implements TypeHandler { - @Override - public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { - if (parameter == null) { - ps.setNull(i, jdbcType.TYPE_CODE); - return; - } - if(parameter instanceof Number){ - if (jdbcType == JdbcType.BOOLEAN) { - ps.setBoolean(i, ((Number) parameter).intValue()==1); - }else{ - ps.setInt(i,((Number) parameter).intValue()); - } - }else{ - if (jdbcType == JdbcType.BOOLEAN) { - ps.setBoolean(i, Boolean.TRUE.equals(parameter)); - } else { - ps.setInt(i, Boolean.TRUE.equals(parameter) ? 1 : 0); - } - } - } - - @Override - public Object getResult(ResultSet rs, String columnName) throws SQLException { - return rs.getBoolean(columnName); - } - - @Override - public Object getResult(ResultSet rs, int columnIndex) throws SQLException { - return rs.getBoolean(columnIndex); - } - - @Override - public Object getResult(CallableStatement cs, int columnIndex) throws SQLException { - return cs.getBoolean(columnIndex); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/AbstractSqlTermCustomizer.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/AbstractSqlTermCustomizer.java deleted file mode 100644 index 1b76996f8..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/AbstractSqlTermCustomizer.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.springframework.util.StringUtils; - -import java.util.List; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -@AllArgsConstructor -public abstract class AbstractSqlTermCustomizer implements SqlTermCustomizer { - - @Getter - protected final String termType; - - @Override - public Dialect[] forDialect() { - return null; - } - - protected String createColumnName(RDBColumnMetaData column, String tableAlias) { - if (StringUtils.isEmpty(tableAlias)) { - tableAlias = column.getTableMetaData().getAlias(); - } - return column.getTableMetaData() - .getDatabaseMetaData() - .getDialect() - .buildColumnName(tableAlias, column.getName()); - } - - - protected ChangedTermValue createChangedTermValue(Term term) { - if (term.getValue() instanceof ChangedTermValue) { - return ((ChangedTermValue) term.getValue()); - } else { - ChangedTermValue termValue = new ChangedTermValue(term.getValue(), term.getValue()); - term.setValue(termValue); - return termValue; - } - } - - protected Object appendCondition(List values, String wherePrefix, SqlAppender appender) { - int len = values.size(); - if (len == 1) { - appender.add("=#{", wherePrefix, ".value.value[0]}"); - } else { - appender.add("in("); - for (int i = 0; i < len; i++) { - if (i > 0) { - appender.add(","); - } - appender.add("#{", wherePrefix, ".value.value[" + i + "]}"); - } - appender.add(")"); - } - return values; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/ChangedTermValue.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/ChangedTermValue.java deleted file mode 100644 index bae74c7ae..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/ChangedTermValue.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.io.Serializable; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -@Data -@AllArgsConstructor -public class ChangedTermValue implements Serializable { - private static final long serialVersionUID = 6373611532663483048L; - - private Object old; - - private Object value; -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/SqlTermCustomizer.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/SqlTermCustomizer.java deleted file mode 100644 index 4d67cedb1..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/SqlTermCustomizer.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper; - -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -public interface SqlTermCustomizer extends Dialect.TermTypeMapper { - String getTermType(); - - Dialect[] forDialect(); -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/TreeStructureSqlTermCustomizer.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/TreeStructureSqlTermCustomizer.java deleted file mode 100644 index 754c91018..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/TreeStructureSqlTermCustomizer.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper; - -import lombok.extern.slf4j.Slf4j; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.hswebframework.ezorm.rdb.render.dialect.RenderPhase; -import org.hswebframework.ezorm.rdb.render.dialect.function.SqlFunction; -import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -@Slf4j -public abstract class TreeStructureSqlTermCustomizer extends AbstractSqlTermCustomizer { - protected boolean not; - - protected boolean parent; - - public TreeStructureSqlTermCustomizer(String termType, boolean not, boolean parent) { - super(termType); - this.not = not; - this.parent = parent; - } - - protected abstract String getTableName(); - - protected abstract List getTreePathByTerm(List termValue); - - @Override - public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - ChangedTermValue termValue = createChangedTermValue(term); - Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); - List paths; - if (termValue.getOld() == termValue.getValue()) { - List value = BoostTermTypeMapper.convertList(column, termValue.getOld()); - paths = getTreePathByTerm(value) - .stream() - .map(path -> path.concat("%")) - .collect(Collectors.toList()); - termValue.setValue(paths); - } else { - paths = ((List) termValue.getValue()); - } - - SqlAppender termCondition = new SqlAppender(); - - termCondition.add(not ? "not " : "", "exists(select 1 from ", getTableName(), " tmp where tmp.u_id = ", createColumnName(column, tableAlias)); - int len = paths.size(); - - if (len > 0) { - termCondition.add(" and ("); - } - for (int i = 0; i < len; i++) { - if (i > 0) { - termCondition.addSpc(" or"); - } - if (parent) { - SqlFunction function = dialect.getFunction(SqlFunction.concat); - String concat; - if (function == null) { - concat = getTableName() + ".path"; - log.warn("数据库方言未支持concat函数,你可以调用Dialect.installFunction进行设置!"); - } else { - concat = function.apply(SqlFunction.Param.of(RenderPhase.where, Arrays.asList("tmp.path", "'%'"))); - } - termCondition.add("#{", wherePrefix, ".value.value[", i, "]}", " like ", concat); - } else { - termCondition.add("tmp.path like #{", wherePrefix, ".value.value[", i, "]}"); - } - } - if (len > 0) { - termCondition.add(")"); - } - termCondition.add(")"); - - return termCondition; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictInTermTypeMapper.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictInTermTypeMapper.java deleted file mode 100644 index 81fb221b8..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictInTermTypeMapper.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper.dict; - -import org.hswebframework.ezorm.core.OptionConverter; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.ezorm.core.param.TermType; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.hswebframework.ezorm.rdb.render.dialect.RenderPhase; -import org.hswebframework.ezorm.rdb.render.dialect.function.SqlFunction; -import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; -import org.hswebframework.web.dao.mybatis.mapper.AbstractSqlTermCustomizer; -import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; -import org.hswebframework.web.dict.EnumDict; - -import java.sql.JDBCType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -public class DictInTermTypeMapper extends AbstractSqlTermCustomizer { - - private boolean not; - - public static final String USE_DICT_MASK_FLAG = "dict-mask"; - - public DictInTermTypeMapper(boolean not) { - super(not ? TermType.nin : TermType.in); - this.not = not; - } - - private boolean support(RDBColumnMetaData column) { - if(column.getJdbcType()== JDBCType.VARCHAR){ - return false; - } - Class type = column.getJavaType(); - if (type != null && type.isArray()) { - type = type.getComponentType(); - } - - return ((type != null && type.isEnum() - && EnumDict.class.isAssignableFrom(type) - && column.getJavaType().isArray()) - || - (column.getProperty(USE_DICT_MASK_FLAG).isTrue() - && column.getOptionConverter() != null)); - } - - @SuppressWarnings("all") - private List getAllOption(RDBColumnMetaData column) { - Class type = column.getJavaType(); - if (null != type) { - if (type.isArray()) { - type = type.getComponentType(); - } - if (type.isEnum() && EnumDict.class.isAssignableFrom(type)) { - return (List) Arrays.asList(type.getEnumConstants()); - } - } - - OptionConverter converter = column.getOptionConverter(); - if (converter == null) { - return new ArrayList<>(); - } - - return (List) converter.getOptions(); - } - - @Override - public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - //不支持数据字典 - if (!support(column)) { - return buildNotSupport(wherePrefix, term, column, tableAlias); - } - ChangedTermValue changedValue = createChangedTermValue(term); - - boolean any = term.getOptions().contains("any"); - - List list = BoostTermTypeMapper.convertList(column, changedValue.getOld()); - - EnumDict[] dicts = getAllOption(column) - .stream() - .filter(d -> d.eq(list)) - .toArray(EnumDict[]::new); - - changedValue.setValue(EnumDict.toMask(dicts)); - Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); - - String columnName = dialect.buildColumnName(tableAlias, column.getName()); - String where = "#{" + wherePrefix + ".value.value}"; - SqlFunction sqlFunction = dialect.getFunction(SqlFunction.bitand); - - if (sqlFunction == null) { - throw new UnsupportedOperationException("数据库不支持[BITAND]函数"); - } - String bitAnd = sqlFunction.apply(SqlFunction.Param.of(RenderPhase.where, Arrays.asList(columnName, where))); - - String n; - if (any) { - n = not ? "=" : "!="; - } else { - n = not ? "!=" : "="; - } - return new SqlAppender().add(bitAnd, n, any ? "0" : columnName); - - } - - protected SqlAppender buildNotSupport(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - ChangedTermValue changedValue = createChangedTermValue(term); - Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); - - List values = BoostTermTypeMapper.convertList(column, changedValue.getOld()); - - changedValue.setValue(values); - - String columnName = dialect.buildColumnName(tableAlias, column.getName()); - SqlAppender appender = new SqlAppender(); - appender.add(columnName, not ? " NOT " : " ").add("IN("); - for (int i = 0; i < values.size(); i++) { - appender.add("#{", wherePrefix, ".value.value[", i, "]}", ","); - } - appender.removeLast(); - appender.add(")"); - return appender; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictTermTypeMapper.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictTermTypeMapper.java deleted file mode 100644 index b55db0f4f..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/mapper/dict/DictTermTypeMapper.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.hswebframework.web.dao.mybatis.mapper.dict; - -import org.hswebframework.ezorm.core.OptionConverter; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.ezorm.core.param.TermType; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; -import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.Dialect; -import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; -import org.hswebframework.web.dao.mybatis.mapper.AbstractSqlTermCustomizer; -import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; -import org.hswebframework.web.dict.EnumDict; - -import java.sql.JDBCType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.hswebframework.web.dao.mybatis.mapper.dict.DictInTermTypeMapper.USE_DICT_MASK_FLAG; - -/** - * @author zhouhao - * @since 3.0.0-RC - */ -public class DictTermTypeMapper extends AbstractSqlTermCustomizer { - - private boolean not; - - public DictTermTypeMapper(boolean not) { - super(not ? TermType.not : TermType.eq); - this.not = not; - } - - private boolean support(RDBColumnMetaData column) { - if (column.getJdbcType() == JDBCType.VARCHAR) { - return false; - } - Class type = column.getJavaType(); - if (type != null && type.isArray()) { - type = type.getComponentType(); - } - return ((type != null && type.isEnum() - && EnumDict.class.isAssignableFrom(type) - && column.getJavaType().isArray()) - || - (column.getProperty(USE_DICT_MASK_FLAG).isTrue() && column.getOptionConverter() != null)); - } - - - @SuppressWarnings("all") - private List getAllOption(RDBColumnMetaData column) { - Class type = column.getJavaType(); - if (null != type) { - if (type.isArray()) { - type = type.getComponentType(); - } - if (type.isEnum() && EnumDict.class.isAssignableFrom(type)) { - return (List) Arrays.asList(type.getEnumConstants()); - } - } - - OptionConverter converter = column.getOptionConverter(); - if (converter == null) { - return new ArrayList<>(); - } - - return (List) converter.getOptions(); - } - - @Override - public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - //不支持数据字典 - if (!support(column)) { - return buildNotSupport(wherePrefix, term, column, tableAlias); - } - ChangedTermValue changedValue = createChangedTermValue(term); - - List list = BoostTermTypeMapper.convertList(column, changedValue.getOld()); - - EnumDict[] dicts = getAllOption(column) - .stream() - .filter(d -> d.eq(list)) - .toArray(EnumDict[]::new); - - changedValue.setValue(EnumDict.toMask(dicts)); - Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); - String columnName = dialect.buildColumnName(tableAlias, column.getName()); - return new SqlAppender().add(columnName, not ? " != " : "=", "#{", wherePrefix, ".value.value}"); - } - - protected SqlAppender buildNotSupport(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { - ChangedTermValue termValue = createChangedTermValue(term); - // fix https://github.com/hs-web/hsweb-framework/issues/102 - Object newValue = BoostTermTypeMapper.convertValue(column, termValue.getOld()); - termValue.setValue(newValue); - - Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); - String columnName = dialect.buildColumnName(tableAlias, column.getName()); - SqlAppender appender = new SqlAppender(); - appender.add(columnName, not ? " != " : "=", "#{", wherePrefix, ".value.value}"); - return appender; - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/Pager.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/Pager.java deleted file mode 100644 index 2b538df7d..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/Pager.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.plgins.pager; - - -import org.hswebframework.web.ThreadLocalUtils; - -/** - * 分页插件,通过此接口进行分页操作 - * - * @author zhouhao - * @see PagerInterceptor - */ -public interface Pager { - int pageIndex(); - - int pageSize(); - - String threadLocalKey = "nowPager"; - - static Pager getAndReset() { - try { - return get(); - } finally { - reset(); - } - } - - static Pager get() { - return ThreadLocalUtils.get(threadLocalKey); - } - - static void reset() { - ThreadLocalUtils.remove(threadLocalKey); - } - - static void doPaging(int pageIndex, int pageSize) { - ThreadLocalUtils.put(threadLocalKey, new Pager() { - @Override - public int pageIndex() { - return pageIndex; - } - - @Override - public int pageSize() { - return pageSize; - } - }); - } - - static void doPaging(int pageIndex, int pageSize, int total) { - doPaging(pageIndex, pageSize); - rePaging(total); - } - - static void rePaging(int total) { - Pager pager = get(); - if (pager != null) { - // 当前页没有数据后跳转到最后一页 - if (pager.pageIndex() != 0 && (pager.pageIndex() * pager.pageSize()) >= total) { - int tmp = total / pager.pageSize(); - int pageIndex = total % pager.pageSize() == 0 ? tmp - 1 : tmp; - doPaging(pageIndex, pager.pageSize()); - } - } - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/PagerInterceptor.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/PagerInterceptor.java deleted file mode 100644 index 7d23c02dc..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/plgins/pager/PagerInterceptor.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * * Copyright 2019 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.dao.mybatis.plgins.pager; - -import org.apache.ibatis.executor.Executor; -import org.apache.ibatis.executor.statement.StatementHandler; -import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.plugin.*; -import org.apache.ibatis.reflection.MetaObject; -import org.apache.ibatis.reflection.SystemMetaObject; -import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.RowBounds; -import org.hswebframework.ezorm.core.param.QueryParam; -import org.hswebframework.web.dao.mybatis.builder.EasyOrmSqlBuilder; -import org.springframework.stereotype.Component; - -import java.util.Properties; - -@Intercepts({@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, - RowBounds.class, ResultHandler.class})}) -@Component -public class PagerInterceptor implements Interceptor { - - @Override - public Object intercept(Invocation target) throws Throwable { - return target.proceed(); - } - - @Override - public Object plugin(Object target) { - if (target instanceof StatementHandler) { - StatementHandler statementHandler = (StatementHandler) target; - MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler); - String sql = statementHandler.getBoundSql().getSql(); - Pager pager = Pager.getAndReset(); - - String lower = sql.trim(); - - if (lower.startsWith("select")) { - if (lower.contains("count(")) { - return Plugin.wrap(target, this); - } - String newSql = sql; - if (pager != null) { - newSql = EasyOrmSqlBuilder.getInstance() - .getActiveDatabase().getDialect() - .doPaging(sql, pager.pageIndex(), pager.pageSize()); - } - Object queryEntity = statementHandler.getParameterHandler().getParameterObject(); - if (queryEntity instanceof QueryParam && ((QueryParam) queryEntity).isForUpdate()) { - newSql = newSql + " for update"; - } - metaStatementHandler.setValue("delegate.boundSql.sql", newSql); - } - - } - return Plugin.wrap(target, this); - } - - @Override - public void setProperties(Properties properties) { - } -} \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring-configuration-metadata.json b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring-configuration-metadata.json deleted file mode 100644 index 0c42a4686..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring-configuration-metadata.json +++ /dev/null @@ -1,151 +0,0 @@ -{ - "groups": [ - { - "name": "mybatis", - "type": "org.hswebframework.web.dao.mybatis.MybatisProperties", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - } - ], - "properties": [ - { - "name": "mybatis.dynamic-datasource", - "type": "java.lang.Boolean", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties", - "description": "enable dynamicDatasource." - }, - { - "name": "mybatis.mapper-location-excludes", - "type": "java.lang.String[]", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties", - "description": "exclude mapperLocations." - }, - { - "name": "mybatis.check-config-location", - "type": "java.lang.Boolean", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.check-config-location", - "type": "java.lang.Boolean", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.check-config-location", - "type": "java.lang.Boolean", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.check-config-location", - "type": "java.lang.Boolean", - "description": "Check the config file exists.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties", - "defaultValue": false - }, - { - "name": "mybatis.config", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.config", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.config", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.config", - "type": "java.lang.String", - "description": "Config file path.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.executor-type", - "type": "org.apache.ibatis.session.ExecutorType", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.executor-type", - "type": "org.apache.ibatis.session.ExecutorType", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.executor-type", - "type": "org.apache.ibatis.session.ExecutorType", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.executor-type", - "type": "org.apache.ibatis.session.ExecutorType", - "description": "Execution mode.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.mapper-locations", - "type": "java.lang.String[]", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.mapper-locations", - "type": "java.lang.String[]", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.mapper-locations", - "type": "java.lang.String[]", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.mapper-locations", - "type": "java.lang.String[]", - "description": "Location of mybatis mapper files.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-aliases-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-aliases-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-aliases-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-aliases-package", - "type": "java.lang.String", - "description": "Package to scan domain objects.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-handlers-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-handlers-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-handlers-package", - "type": "java.lang.String", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - }, - { - "name": "mybatis.type-handlers-package", - "type": "java.lang.String", - "description": "Package to scan handlers.", - "sourceType": "org.hswebframework.web.dao.mybatis.MybatisProperties" - } - ], - "hints": [] -} \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring.factories b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring.factories deleted file mode 100644 index aa564c655..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.dao.mybatis.MybatisDaoAutoConfiguration \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/basic/BasicMapper.xml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/basic/BasicMapper.xml deleted file mode 100644 index 7979303ae..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/basic/BasicMapper.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildWhere(resultMapId,tableName,#this['_parameter'])} - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildWhereForUpdate(resultMapId,tableName,#this['_parameter'])} - - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildSelectFields(resultMapId,tableName,#this['_parameter'])} - - - - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildUpdateFields(resultMapId,tableName,#this['_parameter'])} - - - - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildOrder(resultMapId,tableName,#this['_parameter'])} - - - - - - - - - - - - - - - - - - - - - - - - - - - - select - - from ${_fullTableName} - - - - - - - - - - - - delete from ${_fullTableName} - - - - - - - - - ${@org.hswebframework.web.dao.mybatis.builder.SqlBuilder@current().buildInsertSql(resultMapId,tableName,#this['_parameter'])} - - - - - - - update ${_fullTableName} - - - - - - - - - - - - select count(0) as total from ${_fullTableName} - - - - - - diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/DataType.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/DataType.java deleted file mode 100644 index 62bdec10c..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/DataType.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.hswebframework.web.dict.EnumDict; - -@Getter -@AllArgsConstructor -public enum DataType implements EnumDict { - TYPE1((byte) 1, "类型1"), - TYPE2((byte) 2, "类型2"), - TYPE3((byte) 3, "类型3"), - TYPE4((byte) 4, "类型4"); - - private Byte value; - - private String text; -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/NestEntity.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/NestEntity.java deleted file mode 100644 index 7d76b52f8..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/NestEntity.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import lombok.Data; - -import javax.persistence.Column; - -/** - * - * @author zhouhao - * @since - */ -@Data -public class NestEntity { - - @Column - private String name; -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestApplication.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestApplication.java deleted file mode 100644 index 280edc12d..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.session.TransactionIsolationLevel; -import org.apache.ibatis.transaction.Transaction; -import org.hswebframework.web.dao.Dao; -import org.hswebframework.web.dao.mybatis.EnumDictHandlerRegister; -import org.hswebframework.web.dao.mybatis.MybatisEntityFactory; -import org.hswebframework.web.dao.mybatis.MybatisProperties; -import org.hswebframework.web.dao.mybatis.MybatisUtils; -import org.hswebframework.web.dao.mybatis.builder.EasyOrmSqlBuilder; -import org.hswebframework.web.dao.mybatis.dynamic.DynamicDataSourceSqlSessionFactoryBuilder; -import org.hswebframework.web.dao.mybatis.dynamic.DynamicSpringManagedTransaction; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.annotation.MapperScan; -import org.mybatis.spring.boot.autoconfigure.SpringBootVFS; -import org.mybatis.spring.transaction.SpringManagedTransactionFactory; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.util.StringUtils; - -import javax.sql.DataSource; -import java.util.Arrays; - -@SpringBootApplication -//@EntityScan("org.hswebframework.web.dao") - -public class TestApplication { - - @Bean - public SqlSessionFactory sqlSessionFactory2(@Qualifier("dataSource") DataSource dataSource) throws Exception { - SqlSessionFactoryBean factory = new SqlSessionFactoryBean(); - factory.setVfs(SpringBootVFS.class); - factory.setDataSource(dataSource); - String typeHandlers = "org.hswebframework.web.dao.mybatis.handler"; - factory.setTypeHandlersPackage(typeHandlers); - factory.setMapperLocations(new Resource[]{new ClassPathResource("org/hswebframework/web/dao/test/TestDao.xml")}); - - SqlSessionFactory sqlSessionFactory = factory.getObject(); - return sqlSessionFactory; - } - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestCrud.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestCrud.java deleted file mode 100644 index a6f1c00f1..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestCrud.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import lombok.SneakyThrows; -import org.apache.ibatis.session.SqlSessionFactory; -import org.hswebframework.ezorm.core.param.QueryParam; -import org.hswebframework.ezorm.rdb.executor.SqlExecutor; -import org.hswebframework.web.commons.entity.param.DeleteParamEntity; -import org.hswebframework.web.commons.entity.param.QueryParamEntity; -import org.hswebframework.web.commons.entity.param.UpdateParamEntity; -import org.hswebframework.web.datasource.DataSourceHolder; -import org.hswebframework.web.dict.EnumDict; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringRunner; - -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = TestApplication.class) -public class TestCrud extends AbstractTransactionalJUnit4SpringContextTests { - - @Autowired - private TestDao testDao; - - @Autowired - private SqlExecutor sqlExecutor; - - - @Autowired - @Qualifier("sqlSessionFactory2") - SqlSessionFactory sqlSessionFactory2; - - @Autowired - @Qualifier("sqlSessionFactory") - SqlSessionFactory sqlSessionFactory; - - @Before - public void init() throws SQLException { - sqlExecutor.exec("\n" + - "create table h_test(\n" + - " id BIGINT AUTO_INCREMENT PRIMARY KEY,\n" + - " name VARCHAR(32) ,\n" + - " create_time DATETIME,\n" + - " data_type SMALLINT,\n" + - " data_types BIGINT\n" + - ")"); - sqlExecutor.exec("\n" + - "create table h_nest_table(\n" + - " id BIGINT PRIMARY KEY,\n" + - " name VARCHAR(32)\n" + - ")"); - } - - @Test - @SneakyThrows - public void testCRUD() { - - DataSourceHolder.databaseSwitcher().use("PUBLIC"); - - TestEntity entity = new TestEntity(); - entity.setName("测试"); - entity.setDataType(DataType.TYPE1); - entity.setDataTypes(new DataType[]{DataType.TYPE1, DataType.TYPE3}); - testDao.insert(entity); - Assert.assertNotNull(entity.getId()); - sqlExecutor.insert("insert into h_nest_table (id,name) values(#{id},'1234')",entity); - - QueryParamEntity query = new QueryParamEntity(); - //any in - query.where("dataTypes$in$any", Arrays.asList(DataType.TYPE1, DataType.TYPE2)); - - //#102 - //query.where("createTime", "2017-11-10"); - - -// DataSourceHolder.tableSwitcher().use("h_test", "h_test2"); - List entities = testDao.queryNest(query); - query.includes("name"); - testDao.count(query); - testDao.query(query); - - query.includes("nest.name", "*"); - testDao.countNest(query); - - UpdateParamEntity.newUpdate() - .set("name","测试") - .set(entity::getDataType) - .where("id",entity.getId()) - .exec(testDao::update); - - DeleteParamEntity.newDelete() - .where("id", "1234") - .exec(testDao::delete); - System.out.println(entities); - } - - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestDao.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestDao.java deleted file mode 100644 index ed1917f35..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestDao.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import org.hswebframework.web.commons.entity.Entity; -import org.hswebframework.web.dao.CrudDao; - -import java.util.List; - -public interface TestDao extends CrudDao { - List queryNest(Entity queryEntity); - - int countNest(Entity queryEntity); - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestEntity.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestEntity.java deleted file mode 100644 index 370a33da8..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/crud/TestEntity.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.hswebframework.web.dao.crud; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -import javax.persistence.*; -import java.util.Date; - -@Entity -@Table(name = "h_test") -@Getter -@Setter -@ToString -public class TestEntity implements org.hswebframework.web.commons.entity.Entity { - - @Id - @GeneratedValue( - strategy = GenerationType.IDENTITY - ) - private Long id; - - @Column( - name = "name", - columnDefinition = "varchar COMMENT '创建时间'" - ) - private String name; - - @Column( - name = "create_time", - columnDefinition = "timestamp COMMENT '创建时间'" - ) - private Date createTime; - - @Column( - name = "data_type", - columnDefinition = "bigint COMMENT '类型'" - ) - private DataType dataType; - - @Column( - name = "data_types", - columnDefinition = "bigint COMMENT '多个类型'" - ) - private DataType[] dataTypes; - - @CollectionTable(name = "nest_table") - private NestEntity nest; - - @CollectionTable(name = "nest_table2") - private NestEntity nest2; - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParserTest.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParserTest.java deleted file mode 100644 index dc2537ffb..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/SqlParamParserTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; -import lombok.*; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.web.commons.entity.QueryEntity; -import org.hswebframework.web.commons.entity.param.QueryParamEntity; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.asm.ClassReader; - -import java.lang.invoke.LambdaMetafactory; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; - -import static org.junit.Assert.*; - -/** - * @author zhouhao - * @since 1.0 - */ -public class SqlParamParserTest { - @SneakyThrows - public static void test(Function function) { - Class t=function.getClass(); - - System.out.println(t); - } - - public static void main(String[] args) { - test(TestQueryEntity::getName$like); - } - - - @Test - public void testParseQueryParam() { - Map queryParam = new LinkedHashMap<>(); - queryParam.put("name", "张三"); - queryParam.put("name$like$or", "王五"); - queryParam.put("and", TestQueryEntity - .builder() - .name$like("李四%").age$gt(1) - .or(TestQueryEntity.builder().name$like("王五").age$gt(10).build()) - .build()); - - QueryParamEntity entity = SqlParamParser.parseQueryParam(queryParam); - - Assert.assertTrue(!entity.getTerms().isEmpty()); - Assert.assertEquals(entity.getTerms().get(0).getColumn(), "name"); - Assert.assertEquals(entity.getTerms().get(0).getType(), Term.Type.and); - - Assert.assertEquals(entity.getTerms().get(1).getColumn(), "name"); - Assert.assertEquals(entity.getTerms().get(1).getTermType(), "like"); - Assert.assertEquals(entity.getTerms().get(1).getType(), Term.Type.or); - - - Assert.assertEquals(entity.getTerms().get(2).getType(), Term.Type.and); - Assert.assertTrue(!entity.getTerms().get(2).getTerms().isEmpty()); - Assert.assertEquals(entity.getTerms().get(2).getTerms().get(0).getTermType(), "like"); - - Assert.assertEquals(entity.getTerms().get(2).getTerms().get(1).getTermType(), "gt"); - - Assert.assertTrue(!entity.getTerms().get(2).getTerms().get(2).getTerms().isEmpty()); - Assert.assertEquals(entity.getTerms().get(2).getTerms().get(2).getTerms().get(0).getTermType(), "like"); - Assert.assertEquals(entity.getTerms().get(2).getTerms().get(2).getTerms().get(1).getTermType(), "gt"); - - System.out.println(JSON.toJSONString(entity, SerializerFeature.PrettyFormat)); - } - - -} \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/TestQueryEntity.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/TestQueryEntity.java deleted file mode 100644 index 2eb277680..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/TestQueryEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hswebframework.web.commons.entity.QueryEntity; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class TestQueryEntity implements QueryEntity { - - private String name$like; - - private int age$gt; - - private TestQueryEntity or; -} \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/AbstractEntity.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/AbstractEntity.java deleted file mode 100644 index 60d97d385..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/AbstractEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder.jpa; - -import lombok.Getter; -import lombok.Setter; - -import javax.persistence.Column; - -/** - * TODO 完成注释 - * - * @author zhouhao - * @since - */ -@Getter -@Setter -public class AbstractEntity { - - @Column(name = "id") - private Long id; -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParserTest.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParserTest.java deleted file mode 100644 index 4f106b074..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParserTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder.jpa; - -import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData; -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * TODO 完成注释 - * - * @author zhouhao - * @since - */ -public class JpaAnnotationParserTest { - - - @Test - public void testParse() { - RDBTableMetaData metaData = JpaAnnotationParser.parseMetaDataFromEntity(TestEntity.class); - - Assert.assertNotNull(metaData); - Assert.assertEquals(metaData.getColumns().size(), 5); - } -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/TestEntity.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/TestEntity.java deleted file mode 100644 index a67e004e3..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/java/org/hswebframework/web/dao/mybatis/builder/jpa/TestEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.hswebframework.web.dao.mybatis.builder.jpa; - -import lombok.Data; -import org.hswebframework.web.dict.defaults.TrueOrFalse; - -import javax.persistence.Column; -import javax.persistence.Table; - -/** - * @author zhouhao - * @since 3.0 - */ -@Table(name = "s_test") -@Data -public class TestEntity extends AbstractEntity { - - @Column(name = "name") - private String name; - - @Column(name = "age") - private Integer age; - - @Column(name = "role_id") - private String roleId; - - @Column(name = "enabled") - private TrueOrFalse enabled; - -} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/application.yml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/application.yml deleted file mode 100644 index 428f11190..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/application.yml +++ /dev/null @@ -1,26 +0,0 @@ -logging: - level: - org.hswebframework: DEBUG - org.hswebframework.expands: ERROR - com.ruiqi: DEBUG - access-logger: INFO - com.netflix: ERROR -spring: - aop: - auto: true - proxy-target-class: true - profiles: - active: dev - datasource: - url: jdbc:h2:mem:test - username : sa - password : - type: com.alibaba.druid.pool.DruidDataSource - jpa: - generate-ddl: true - show-sql: true - hibernate: - ddl-auto: update -mybatis: - mapper-locations: org/hswebframework/web/dao/test/*.xml - dynamic-datasource: true \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/org/hswebframework/web/dao/test/TestDao.xml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/org/hswebframework/web/dao/test/TestDao.xml deleted file mode 100644 index 7972d3e0b..000000000 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/test/resources/org/hswebframework/web/dao/test/TestDao.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-dao/pom.xml b/hsweb-commons/hsweb-commons-dao/pom.xml index 6252aa364..cf5ad5b1a 100644 --- a/hsweb-commons/hsweb-commons-dao/pom.xml +++ b/hsweb-commons/hsweb-commons-dao/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-commons/hsweb-commons-entity/pom.xml b/hsweb-commons/hsweb-commons-entity/pom.xml index d78430547..e86c3ba71 100644 --- a/hsweb-commons/hsweb-commons-entity/pom.xml +++ b/hsweb-commons/hsweb-commons-entity/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupportEntity.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupportEntity.java index 5c890fda3..155c216e2 100644 --- a/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupportEntity.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupportEntity.java @@ -19,9 +19,9 @@ package org.hswebframework.web.commons.entity; +import org.apache.commons.collections.CollectionUtils; import org.hswebframework.utils.RandomUtil; import org.hswebframework.web.id.IDGenerator; -import org.springframework.util.CollectionUtils; import java.util.*; import java.util.function.*; diff --git a/hsweb-commons/hsweb-commons-model/pom.xml b/hsweb-commons/hsweb-commons-model/pom.xml index 0948fdddc..cf11e910f 100644 --- a/hsweb-commons/hsweb-commons-model/pom.xml +++ b/hsweb-commons/hsweb-commons-model/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/pom.xml b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/pom.xml index f3e8ec1cb..3aa5afd2c 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/pom.xml +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/pom.xml @@ -23,7 +23,7 @@ hsweb-commons-service org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml deleted file mode 100644 index 85c306400..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - hsweb-commons-service - org.hswebframework.web - 3.0.10-SNAPSHOT - - ../pom.xml - - 4.0.0 - - hsweb-commons-service-oauth2 - - 通用增删改查-通用服务OAuth2实现模块 - - - - org.hswebframework.web - hsweb-commons-service-api - ${project.version} - - - org.hswebframework.web - hsweb-authorization-oauth2-client - ${project.version} - - - - \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudService.java deleted file mode 100644 index a0d6f53f8..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudService.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import org.hswebframework.utils.ClassUtils; -import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService; -import org.hswebframework.web.commons.entity.factory.EntityFactory; -import org.hswebframework.web.service.CreateEntityService; -import org.springframework.beans.factory.annotation.Autowired; - -@SuppressWarnings("unchecked") -public abstract class AbstractOAuth2CrudService implements CreateEntityService, OAuth2CrudService { - - private Class entityType; - - private Class primaryKeyType; - - private OAuth2RequestService oAuth2RequestService; - - private EntityFactory entityFactory; - - public AbstractOAuth2CrudService() { - entityType = (Class) ClassUtils.getGenericType(this.getClass(), 0); - primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1); - } - - @Override - public E createEntity() { - return entityFactory.newInstance(entityType); - } - - @Override - public Class getEntityInstanceType() { - return entityType; - } - - @Override - public OAuth2RequestService getRequestService() { - return oAuth2RequestService; - } - - @Override - public Class getEntityType() { - return entityType; - } - - @Override - public Class getPrimaryKeyType() { - return primaryKeyType; - } - - @Autowired - public void setEntityFactory(EntityFactory entityFactory) { - this.entityFactory = entityFactory; - } - - @Autowired - public void setoAuth2RequestService(OAuth2RequestService oAuth2RequestService) { - this.oAuth2RequestService = oAuth2RequestService; - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2CrudService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2CrudService.java deleted file mode 100644 index 9b239adda..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2CrudService.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -public interface OAuth2CrudService extends OAuth2QueryService - , OAuth2QueryByEntityService - , OAuth2DeleteService - , OAuth2InsertService - , OAuth2UpdateService { -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2DeleteService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2DeleteService.java deleted file mode 100644 index 9bd8fcf77..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2DeleteService.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import org.hswebframework.web.service.DeleteService; - -public interface OAuth2DeleteService extends DeleteService, OAuth2ServiceSupport { - @Override - default E deleteByPk(PK pk) { - return createRequest("/" + pk).delete().as(getEntityType()); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2InsertService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2InsertService.java deleted file mode 100644 index c287ff8e2..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2InsertService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import com.alibaba.fastjson.JSON; -import org.hswebframework.web.service.InsertService; - -public interface OAuth2InsertService extends InsertService, OAuth2ServiceSupport { - @Override - default PK insert(E data) { - return createRequest("/").requestBody(JSON.toJSONString(data)).post().as(getPrimaryKeyType()); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryByEntityService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryByEntityService.java deleted file mode 100644 index 00ffeab15..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryByEntityService.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import com.alibaba.fastjson.JSONObject; -import org.hswebframework.web.commons.entity.Entity; -import org.hswebframework.web.commons.entity.PagerResult; -import org.hswebframework.web.service.QueryByEntityService; - -import java.util.List; - -public interface OAuth2QueryByEntityService extends QueryByEntityService, OAuth2ServiceSupport { - - @Override - default PagerResult selectPager(Entity param) { - JSONObject result = createRequest("/", param).get().as(JSONObject.class); - return PagerResult.of(result.getInteger("total"), result.getJSONArray("data").toJavaList(getEntityType())); - } - - @Override - default List select(Entity param) { - return createRequest("/no-paging", param).get().asList(getEntityType()); - } - - @Override - default int count(Entity param) { - return createRequest("/count", param).get().as(Integer.class); - } - - @Override - default E selectSingle(Entity param) { - return createRequest("/single", param).get().as(getEntityType()); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java deleted file mode 100644 index 3f384f6fb..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2QueryService.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import org.hswebframework.web.service.QueryService; - -import java.util.List; - -public interface OAuth2QueryService extends OAuth2ServiceSupport, QueryService { - - @Override - default E selectByPk(PK id) { - return createRequest("/" + id).get().as(getEntityType()); - } - - @Override - default List select() { - return createRequest("/all").get().asList(getEntityType()); - } - - @Override - default List selectByPk(List id) { - return createRequest("/ids") - .param("ids", id.stream() - .map(String::valueOf) - .reduce((id1, id2) -> String.join(",", id1, id2)) - .orElse("")) - .get() - .asList(getEntityType()); - } - - @Override - default int count() { - return createRequest("/count") - .get() - .as(Integer.class); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java deleted file mode 100644 index c8b4fe0de..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2ServiceSupport.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.hswebframework.web.service.oauth2; - - -import org.hswebframework.web.WebUtil; -import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService; -import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Request; -import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Session; - -public interface OAuth2ServiceSupport { - - OAuth2RequestService getRequestService(); - - String getServiceId(); - - String getUriPrefix(); - - Class getEntityType(); - - Class getPrimaryKeyType(); - - default OAuth2Session createSession() { - return getRequestService().create(getServiceId()).byClientCredentials(); - } - - default OAuth2Request createRequest(String uri) { - return createSession().request(getUriPrefix() + uri); - } - - default OAuth2Request createRequest(String uri, Object param) { - return createSession().request(getUriPrefix() + uri) - .params(WebUtil.objectToHttpParameters(param)); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2UpdateService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2UpdateService.java deleted file mode 100644 index dd908d825..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/main/java/org/hswebframework/web/service/oauth2/OAuth2UpdateService.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import com.alibaba.fastjson.JSON; -import org.hswebframework.web.service.UpdateService; - -import java.util.List; - -public interface OAuth2UpdateService extends UpdateService, OAuth2ServiceSupport { - - @Override - default int updateByPk(PK id, E data) { - return createRequest("/" + id).requestBody(JSON.toJSONString(data)).put().as(Integer.class); - } - - @Override - default int updateByPk(List data) { - return createRequest("/batch").requestBody(JSON.toJSONString(data)).put().as(Integer.class); - } - - @Override - default PK saveOrUpdate(E e) { - return createRequest("/").requestBody(JSON.toJSONString(e)).patch().as(getPrimaryKeyType()); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java deleted file mode 100644 index 4b93347fb..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/AbstractOAuth2CrudServiceTests.java +++ /dev/null @@ -1,175 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import com.alibaba.fastjson.JSON; -import org.hswebframework.web.BusinessException; -import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService; -import org.hswebframework.web.authorization.oauth2.client.OAuth2SessionBuilder; -import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Request; -import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Session; -import org.hswebframework.web.commons.entity.PagerResult; -import org.hswebframework.web.commons.entity.param.QueryParamEntity; -import org.hswebframework.web.controller.message.ResponseMessage; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import static org.mockito.Mockito.*; - -@RunWith(MockitoJUnitRunner.class) -public class AbstractOAuth2CrudServiceTests { - - @Mock - private OAuth2RequestService requestService; - - @Mock - private OAuth2SessionBuilder sessionBuilder; - - @Mock - private OAuth2Session oAuth2Session; - - @InjectMocks - private TestEntityService testEntityService; - - @Before - public void init() { - TestEntity entity = TestEntity.builder().build(); - entity.setBoy(true); - entity.setCreateTime(new Date()); - entity.setName("test"); - entity.setId("test"); - - when(oAuth2Session.request("/test/")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(PagerResult.of(1, Arrays.asList(entity)))), - whenRequest("post", ResponseMessage.ok("test")), - whenRequest("patch", ResponseMessage.ok("test")) - )); - - when(oAuth2Session.request("/test/test")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(entity)) - , whenRequest("put", ResponseMessage.ok(1)) - , whenRequest("delete", ResponseMessage.ok()))); - - when(oAuth2Session.request("/test/no-paging")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(Arrays.asList(entity))))); - - when(oAuth2Session.request("/test/all")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(Arrays.asList(entity))))); - - when(oAuth2Session.request("/test/single")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(entity)))); - - when(oAuth2Session.request("/test/count")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(1)))); - - when(oAuth2Session.request("/test/ids")).thenReturn( - createFixedResponseRequest( - whenRequest("get", ResponseMessage.ok(Arrays.asList(entity))))); - - when(oAuth2Session.request("/test/batch")).thenReturn( - createFixedResponseRequest( - whenRequest("put", ResponseMessage.error(400, "名称不能为空")))); - - when(sessionBuilder.byClientCredentials()).thenReturn(oAuth2Session); - - when(requestService.create(anyString())).thenReturn(sessionBuilder); - - } - - private OAuth2Request createFixedResponseRequest(OAuth2MethodRequest... requests) { - return new MockOAuth2Request((method) -> { - for (OAuth2MethodRequest request : requests) { - if (request.getMethod().equals(method)) { - return new MockOAuth2Response(request.getResponse()); - } - } - return new MockOAuth2Response(ResponseMessage.error(404, "not found").toString()); - }); - } - - @Test - public void testCUD() { - String id = testEntityService.insert(TestEntity.builder().build()); - Assert.assertNotNull(id); - - - TestEntity entity = testEntityService.selectByPk("test"); - Assert.assertNotNull(entity); - - int i = testEntityService.updateByPk("test", entity); - Assert.assertEquals(i, 1); - - testEntityService.deleteByPk("test"); - Assert.assertEquals(i, 1); - - String saveId = testEntityService.saveOrUpdate(entity); - Assert.assertNotNull(saveId, id); - try { - testEntityService.updateByPk(Arrays.asList(entity)); - Assert.assertTrue(false); - } catch (BusinessException e) { - Assert.assertEquals(e.getMessage(), "名称不能为空"); - } - - } - - @Test - public void testQuery() { - - PagerResult result = testEntityService.selectPager(new QueryParamEntity().where("name", "test")); - System.out.println(JSON.toJSONString(result)); - - TestEntity entity = testEntityService.selectByPk("test"); - Assert.assertNotNull(entity); - Assert.assertTrue(entity.isBoy()); - Assert.assertEquals(entity.getName(), "test"); - - System.out.println(JSON.toJSONString(entity)); - - List all = testEntityService.select(); - Assert.assertNotNull(all); - - List noPaging = testEntityService.select(QueryParamEntity.empty()); - Assert.assertNotNull(noPaging); - - int total = testEntityService.count(QueryParamEntity.empty()); - Assert.assertEquals(total, 1); - - total = testEntityService.count(); - Assert.assertEquals(total, 1); - - } - - interface OAuth2MethodRequest { - String getMethod(); - - String getResponse(); - } - - public OAuth2MethodRequest whenRequest(String method, Object json) { - return new OAuth2MethodRequest() { - @Override - public String getMethod() { - return method; - } - - @Override - public String getResponse() { - return JSON.toJSONString(json); - } - }; - } -} \ No newline at end of file diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Request.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Request.java deleted file mode 100644 index 5230ff6ac..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Request.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import lombok.extern.slf4j.Slf4j; -import org.hswebframework.web.authorization.oauth2.client.request.OAuth2Request; -import org.hswebframework.web.authorization.oauth2.client.request.TokenExpiredCallBack; -import org.hswebframework.web.authorization.oauth2.client.response.OAuth2Response; - -import java.io.InputStream; -import java.util.Map; -import java.util.function.Consumer; -import java.util.function.Function; - -@Slf4j -public class MockOAuth2Request implements OAuth2Request { - - - private Function responseGetter; - - - public MockOAuth2Request(Function responseGetter) { - this.responseGetter = responseGetter; - } - - @Override - public OAuth2Request onRefreshTokenExpired(TokenExpiredCallBack refreshTokenExpiredCallBack) { - return this; - } - - @Override - public OAuth2Request onTokenExpired(TokenExpiredCallBack callback) { - return this; - } - - @Override - public OAuth2Request param(String name, Object value) { - log.info("set param :{}={}", name, value); - return this; - } - - @Override - public OAuth2Request params(Map params) { - log.info("set params :{}", params); - return this; - } - - @Override - public OAuth2Response upload(String name, InputStream inputStream) { - return responseGetter.apply("post"); - } - - @Override - public OAuth2Response upload(String name, InputStream inputStream, String fileName) { - return responseGetter.apply("post"); - } - - @Override - public OAuth2Request requestBody(String value) { - log.info("set request body :{}", value); - return this; - } - - @Override - public OAuth2Request header(String name, String value) { - return this; - } - - @Override - public OAuth2Request cookie(String cookie) { - return this; - } - - @Override - public OAuth2Request contentType(String contentType) { - return this; - } - - @Override - public OAuth2Request accept(String accept) { - return this; - } - - @Override - public OAuth2Request timeout(long millisecond, Consumer timeoutCallBack) { - return this; - } - - @Override - public OAuth2Response get() { - return responseGetter.apply("get"); - } - - @Override - public OAuth2Response put() { - return responseGetter.apply("put"); - } - - @Override - public OAuth2Response post() { - return responseGetter.apply("post"); - } - - @Override - public OAuth2Response delete() { - return responseGetter.apply("delete"); - } - - @Override - public OAuth2Response patch() { - return responseGetter.apply("patch"); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Response.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Response.java deleted file mode 100644 index 58db27da3..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/MockOAuth2Response.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import org.hswebframework.web.authorization.oauth2.client.request.ResponseConvertHandler; -import org.hswebframework.web.authorization.oauth2.client.response.OAuth2Response; -import org.hswebframework.web.authorization.oauth2.client.response.ResponseConvert; -import org.hswebframework.web.authorization.oauth2.client.simple.provider.HswebResponseConvertSupport; -import org.hswebframework.web.authorization.simple.builder.SimpleAuthenticationBuilderFactory; -import org.hswebframework.web.authorization.simple.builder.SimpleDataAccessConfigBuilderFactory; -import org.hswebframework.web.oauth2.core.ErrorType; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.List; -import java.util.function.BiConsumer; - -public class MockOAuth2Response implements OAuth2Response { - - private String result; - - private ResponseConvertHandler handler = new HswebResponseConvertSupport(new SimpleAuthenticationBuilderFactory(new SimpleDataAccessConfigBuilderFactory())); - - - @Override - public InputStream asStream() { - return new ByteArrayInputStream(result.getBytes()); - } - - public MockOAuth2Response(String result) { - this.result = result; - } - - @Override - public String asString() { - return result; - } - - @Override - public byte[] asBytes() { - return result.getBytes(); - } - - @Override - public T as(ResponseConvert convert) { - return convert.convert(this); - } - - @Override - public T as(Class type) { - return handler.convert(this, type); - } - - @Override - public List asList(Class type) { - return handler.convertList(this, type); - } - - @Override - public int status() { - return 200; - } - - @Override - public OAuth2Response onError(BiConsumer onError) { - return this; - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntity.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntity.java deleted file mode 100644 index 9259db16c..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -import lombok.*; -import org.hswebframework.web.commons.entity.SimpleGenericEntity; - -import java.util.Date; - -@Getter -@Setter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class TestEntity extends SimpleGenericEntity { - private static final long serialVersionUID = 6405200441627288263L; - private String name; - - private boolean boy; - - private Date createTime; -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntityService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntityService.java deleted file mode 100644 index 74df21455..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-oauth2/src/test/java/org/hswebframework/web/service/oauth2/TestEntityService.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.hswebframework.web.service.oauth2; - -public class TestEntityService extends AbstractOAuth2CrudService{ - @Override - public String getServiceId() { - return "test"; - } - - @Override - public String getUriPrefix() { - return "/test"; - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/pom.xml b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/pom.xml index 15344f026..403f876cd 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/pom.xml +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/pom.xml @@ -23,7 +23,7 @@ hsweb-commons-service org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml @@ -67,22 +67,11 @@ hsweb-commons-dao-api ${project.version} - - org.glassfish - javax.el - test - org.springframework.boot spring-boot-starter-test test - - org.hswebframework.web - hsweb-concurrent-cache - ${project.version} - test - org.springframework spring-aspects diff --git a/hsweb-commons/hsweb-commons-service/pom.xml b/hsweb-commons/hsweb-commons-service/pom.xml index 440d8efdb..7860d4ad5 100644 --- a/hsweb-commons/hsweb-commons-service/pom.xml +++ b/hsweb-commons/hsweb-commons-service/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml @@ -36,7 +36,6 @@ hsweb-commons-service-simple hsweb-commons-service-api - hsweb-commons-service-oauth2 diff --git a/hsweb-commons/hsweb-commons-utils/pom.xml b/hsweb-commons/hsweb-commons-utils/pom.xml index 691e84fce..f06e9d181 100644 --- a/hsweb-commons/hsweb-commons-utils/pom.xml +++ b/hsweb-commons/hsweb-commons-utils/pom.xml @@ -23,7 +23,7 @@ hsweb-commons org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 @@ -42,6 +42,10 @@ + + io.projectreactor + reactor-core + javax.servlet diff --git a/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/Context.java b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/Context.java new file mode 100644 index 000000000..e5a57e756 --- /dev/null +++ b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/Context.java @@ -0,0 +1,15 @@ +package org.hswebframework.web.context; + +import java.util.Map; +import java.util.Optional; + +public interface Context { + + Optional get(ContextKey key); + + T getOrDefault(ContextKey key,T defaultValue); + + void put(ContextKey key,T value); + + Map getAll(); +} diff --git a/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextKey.java b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextKey.java new file mode 100644 index 000000000..f2e1abb98 --- /dev/null +++ b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextKey.java @@ -0,0 +1,32 @@ +package org.hswebframework.web.context; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +public final class ContextKey { + + + @Getter + private String key; + + public static ContextKey of(String key) { + return new ContextKey<>(key); + } + + public static ContextKey of(Class key) { + return new ContextKey<>(key.getName()); + } + + public static ContextKey string(String key) { + return of(key); + } + + public static ContextKey integer(String key) { + return of(key); + } + + public static ContextKey bool(String key) { + return of(key); + } +} diff --git a/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextUtils.java b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextUtils.java new file mode 100644 index 000000000..36aa32dbd --- /dev/null +++ b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/ContextUtils.java @@ -0,0 +1,53 @@ +package org.hswebframework.web.context; + + +import reactor.core.publisher.Mono; + +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * @since 3.1.0 + */ +public class ContextUtils { + + + public static Mono currentContext() { + return Mono.subscriberContext() + .handle((context, sink) -> { + if (context.hasKey(Context.class)) { + sink.next(context.get(Context.class)); + } + }) + .subscriberContext(acceptContext(ctx->{ + + })); + } + + public static Function acceptContext(Consumer contextConsumer) { + return context -> { + if (!context.hasKey(Context.class)) { + context = context.put(Context.class, new MapContext()); + } + contextConsumer.accept(context.get(Context.class)); + return context; + }; + } + + + public static void main(String[] args) { + + currentContext() + .flatMap(ctx ->doRequest()) + .subscriberContext(acceptContext(ctx -> ctx.put(ContextKey.integer("test"), 100))) + .subscribe(System.out::println); + + } + + public static Mono doRequest() { + return currentContext() + .map(context -> context.get(ContextKey.integer("test")).orElse(0)); + } + + +} diff --git a/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/MapContext.java b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/MapContext.java new file mode 100644 index 000000000..d438c02a7 --- /dev/null +++ b/hsweb-commons/hsweb-commons-utils/src/main/java/org/hswebframework/web/context/MapContext.java @@ -0,0 +1,33 @@ +package org.hswebframework.web.context; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +@SuppressWarnings("all") +public class MapContext implements Context { + + private Map map = new ConcurrentHashMap<>(); + + @Override + public Optional get(ContextKey key) { + return Optional.ofNullable(map.get(key.getKey())) + .map(v -> ((T) v)); + } + + @Override + public T getOrDefault(ContextKey key, T defaultValue) { + return (T)map.computeIfAbsent(key.getKey(), __ -> defaultValue); + } + + @Override + public void put(ContextKey key, T value) { + map.put(key.getKey(), value); + } + + @Override + public Map getAll() { + return new HashMap<>(map); + } +} diff --git a/hsweb-commons/hsweb-commons-utils/src/test/java/org/hswebframework/web/HttpParameterConverterTests.java b/hsweb-commons/hsweb-commons-utils/src/test/java/org/hswebframework/web/HttpParameterConverterTests.java index f74d178cf..bfd48af1d 100644 --- a/hsweb-commons/hsweb-commons-utils/src/test/java/org/hswebframework/web/HttpParameterConverterTests.java +++ b/hsweb-commons/hsweb-commons-utils/src/test/java/org/hswebframework/web/HttpParameterConverterTests.java @@ -59,7 +59,7 @@ public class HttpParameterConverterTests { @Test public void testConvertObject() { - QueryParam param = Query.empty(new QueryParam()) + QueryParam param = Query.of(new QueryParam()) .where("name", "张三") .and().like("address", "%重庆%") .nest() diff --git a/hsweb-commons/pom.xml b/hsweb-commons/pom.xml index be4368c20..44139d294 100644 --- a/hsweb-commons/pom.xml +++ b/hsweb-commons/pom.xml @@ -23,7 +23,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 @@ -39,6 +39,7 @@ hsweb-commons-utils hsweb-commons-model hsweb-commons-bean + hsweb-commons-crud \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/README.md b/hsweb-concurrent/hsweb-concurrent-async-job/README.md deleted file mode 100644 index b5abc6364..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# 异步任务工具,支持多线程事务 -```xml - - - org.hswebframework.web - hsweb-concurrent-async-job - ${project.verion} - -``` - -```java - @Autowired - private AsyncJobService asyncJobService; - - - public void testJob(){ - List results= asyncJobService.batch() - .submit(()->...) //提交job - .submit(()->...) //提交另外一个job - .submit(()->...,true) //提交支持事务的job - .getResult(); - } - -``` \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/pom.xml b/hsweb-concurrent/hsweb-concurrent-async-job/pom.xml deleted file mode 100644 index 90573592c..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - hsweb-concurrent - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-async-job - - 支持事务的异步任务 - - - - org.springframework - spring-tx - - - - org.springframework.boot - spring-boot-starter - - - org.slf4j - slf4j-api - - - - ch.qos.logback - logback-classic - provided - - - - org.hswebframework.web - hsweb-tests - ${project.version} - test - - - org.codehaus.groovy - groovy-all - test - - - com.h2database - h2 - test - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobException.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobException.java deleted file mode 100644 index 8c4c2ea26..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobException.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.hswebframework.web.async; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * 异步任务执行异常 - * @author zhouhao - */ -public class AsyncJobException extends RuntimeException { - private static final long serialVersionUID = 4003904073250315538L; - private List errors; - - public AsyncJobException(List errors) { - this(errors.size()>0?errors.get(0).getMessage():null,errors); - } - - public AsyncJobException(String message, List errors) { - super(message,errors.size()>0?errors.get(0):null); - this.errors = errors; - } - - public List getErrors() { - return errors; - } - - @Override - public StackTraceElement[] getStackTrace() { - if (null != errors) { - List stackTraceElements = errors.stream() - .map(Exception::getStackTrace) - .flatMap(Stream::of) - .collect(Collectors.toList()); - stackTraceElements.addAll(Arrays.asList(super.getStackTrace())); - return stackTraceElements.toArray(new StackTraceElement[stackTraceElements.size()]); - } - return super.getStackTrace(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobService.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobService.java deleted file mode 100644 index 10f9e3d27..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobService.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.hswebframework.web.async; - -/** - * 异步任务服务 - * - * @author zhouhao - */ -public interface AsyncJobService { - /** - * @return 创建一个异步任务容器 - */ - BatchAsyncJobContainer batch(); -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobServiceAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobServiceAutoConfiguration.java deleted file mode 100644 index a5bf0bb1a..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/AsyncJobServiceAutoConfiguration.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.hswebframework.web.async; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * @author zhouhao - */ -@Configuration -@ConditionalOnMissingBean(AsyncJobService.class) -public class AsyncJobServiceAutoConfiguration { - - @Value("${hsweb.async.job.maxThreadPoolSize:-1}") - private int maxThreadPoolSize = -1; - - @Bean - @ConditionalOnMissingBean(ExecutorService.class) - public ExecutorService executorService() { - if (maxThreadPoolSize == -1) { - maxThreadPoolSize = Runtime.getRuntime().availableProcessors() * 50; - } - return Executors.newFixedThreadPool(maxThreadPoolSize); - } - - @Bean - @ConditionalOnMissingBean(TransactionSupportJobWrapper.class) - public TransactionSupportJobWrapper transactionSupportJobWrapper() { - return new SpringTransactionSupportJobWrapper(); - } - - @Bean - public AsyncJobService asyncJobService(ExecutorService executorService, TransactionSupportJobWrapper transactionSupportJobWrapper) { - TransactionSupportAsyncJobService asyncJobService = new TransactionSupportAsyncJobService(); - - asyncJobService.setTranslationSupportJobWrapper(transactionSupportJobWrapper); - asyncJobService.setExecutorService(executorService); - - return asyncJobService; - - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/BatchAsyncJobContainer.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/BatchAsyncJobContainer.java deleted file mode 100644 index 8c0653e3a..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/BatchAsyncJobContainer.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.hswebframework.web.async; - -import java.util.List; -import java.util.concurrent.Callable; - -/** - * @author zhouhao - */ -public interface BatchAsyncJobContainer { - - default BatchAsyncJobContainer submit(Callable callable) { - submit(callable, false); - return this; - } - - BatchAsyncJobContainer submit(Callable callable, boolean enableTransaction); - - - List getResult() throws Exception; - - BatchAsyncJobContainer cancel(); -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJob.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJob.java deleted file mode 100644 index 3bc2f928f..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJob.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.hswebframework.web.async; - -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; - -import java.util.concurrent.Callable; - -/** - * 使用spring管理事务的异步任务 - * - * @author zhouhao - * @see TransactionTemplate - */ -public class SpringTransactionSupportJob implements TransactionSupportJob { - - private TransactionStatus transactionStatus; - - private TransactionTemplate transactionTemplate; - - private boolean rollback = false; - - private Callable target; - - public SpringTransactionSupportJob(TransactionTemplate transactionTemplate, Callable job) { - this.transactionTemplate = transactionTemplate; - this.target = job; - } - - @Override - public void rollBackOnly() { - rollback = true; - } - - @Override - public void commit() { - //do noting - if (transactionStatus != null) { - if (rollback) { - transactionTemplate.getTransactionManager().rollback(transactionStatus); - } else { - transactionTemplate.getTransactionManager().commit(transactionStatus); - } - } - } - - @Override - public V call() throws Exception { - transactionStatus = transactionTemplate.getTransactionManager().getTransaction(transactionTemplate); - if (rollback) { - transactionStatus.setRollbackOnly(); - } - return target.call(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJobWrapper.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJobWrapper.java deleted file mode 100644 index c1858ab9a..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/SpringTransactionSupportJobWrapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.hswebframework.web.async; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.support.TransactionTemplate; - -import java.util.concurrent.Callable; - -/** - * @author zhouhao - */ -public class SpringTransactionSupportJobWrapper implements TransactionSupportJobWrapper { - - private TransactionTemplate transactionTemplate; - - @Autowired - public void setTransactionTemplate(TransactionTemplate transactionTemplate) { - this.transactionTemplate = transactionTemplate; - } - - @Override - public TransactionSupportJob wrapper(Callable callable) { - return new SpringTransactionSupportJob<>(transactionTemplate, callable); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionBatchAsyncJobContainer.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionBatchAsyncJobContainer.java deleted file mode 100644 index 35a247393..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionBatchAsyncJobContainer.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.hswebframework.web.async; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -/** - * @author zhouhao - */ -public class TransactionBatchAsyncJobContainer implements BatchAsyncJobContainer { - - private ExecutorService executorService; - private TransactionSupportJobWrapper translationSupportJobWrapper; - private static final Logger logger = LoggerFactory.getLogger(TransactionBatchAsyncJobContainer.class); - - public TransactionBatchAsyncJobContainer(ExecutorService executorService, TransactionSupportJobWrapper translationSupportJobWrapper) { - this.executorService = executorService; - this.translationSupportJobWrapper = translationSupportJobWrapper; - } - - private List exceptions = new ArrayList<>(); - - private AtomicInteger failCounter = new AtomicInteger(); - - private AtomicInteger transactionJobOverCounter = new AtomicInteger(0); - - private CountDownLatch countDownLatch = new CountDownLatch(1); - - private List futures = new ArrayList<>(); - - private AtomicInteger transactionJobNumber = new AtomicInteger(0); - - private volatile boolean shutdown = false; - - public void setExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - - @Override - public BatchAsyncJobContainer submit(Callable callable, boolean enableTransaction) { - if (shutdown) { - logger.warn("TransactionBatchAsyncJobContainer is shutdown, fail job number :{}", failCounter.get()); - return this; - } - if (!enableTransaction) { - if (logger.isDebugEnabled()) { - logger.debug("submit not transaction support job"); - } - futures.add(executorService.submit(() -> { - if (shutdown) { - return null; - } - return callable.call(); - })); - return this; - } - - int tmpJobFlag = transactionJobNumber.incrementAndGet(); - - if (logger.isDebugEnabled()) { - logger.debug("submit transaction support job {}", transactionJobNumber); - } - - TransactionSupportJob translationJob = translationSupportJobWrapper.wrapper(callable); - Callable proxy = () -> { - V value = null; - try { - if (failCounter.get() > 0 || shutdown) { - return null; - } - value = translationJob.call(); - transactionJobOverCounter.incrementAndGet(); - if (logger.isDebugEnabled()) { - logger.debug("transaction support job {} success,wait...", tmpJobFlag); - } - //等待其他任务完成 - countDownLatch.await(); - if (failCounter.get() > 0) { - if (logger.isDebugEnabled()) { - logger.debug("transaction support job {} success,but other job failed, do rollback only!", tmpJobFlag); - } - translationJob.rollBackOnly(); - } else { - if (logger.isDebugEnabled()) { - logger.debug("transaction support job {} success,commit.", tmpJobFlag); - } - } - translationJob.commit(); - } catch (Exception e) { - exceptions.add(e); - failCounter.incrementAndGet(); - logger.warn("transaction support job {} fail.", tmpJobFlag, e); - }finally { - transactionJobOverCounter.incrementAndGet(); - } - return value; - }; - futures.add(executorService.submit(proxy)); - return this; - } - - @Override - public List getResult() throws Exception { - while (transactionJobOverCounter.get() != transactionJobNumber.get() && failCounter.get() == 0) { - Thread.sleep(50); - } - countDownLatch.countDown(); - - List results = futures.stream().map(this::getValue).collect(Collectors.toList()); - if (!exceptions.isEmpty()) { - throw new AsyncJobException(exceptions); - } - return results; - } - - private Object getValue(Future future) { - if(future==null){return null;} - try { - return future.get(); - } catch (Exception e) { - exceptions.add(e); - } - return null; - } - - @Override - public BatchAsyncJobContainer cancel() { - shutdown = true; - return this; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportAsyncJobService.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportAsyncJobService.java deleted file mode 100644 index 583a7e8ae..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportAsyncJobService.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.hswebframework.web.async; - -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.concurrent.ExecutorService; - -/** - * @author zhouhao - */ -public class TransactionSupportAsyncJobService implements AsyncJobService { - - private ExecutorService executorService; - - private TransactionSupportJobWrapper translationSupportJobWrapper; - - @Autowired(required = false) - public void setExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - - @Autowired - public void setTranslationSupportJobWrapper(TransactionSupportJobWrapper translationSupportJobWrapper) { - this.translationSupportJobWrapper = translationSupportJobWrapper; - } - - @Override - public BatchAsyncJobContainer batch() { - return new TransactionBatchAsyncJobContainer(executorService, translationSupportJobWrapper); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJob.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJob.java deleted file mode 100644 index 347a39256..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJob.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hswebframework.web.async; - -import java.util.concurrent.Callable; - -/** - * 支持事务的异步任务 - * @author zhouhao - */ -public interface TransactionSupportJob extends Callable { - - /** - * 回滚 - */ - void rollBackOnly(); - - /** - * 提交事务 - */ - void commit(); -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJobWrapper.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJobWrapper.java deleted file mode 100644 index 470c7775a..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/java/org/hswebframework/web/async/TransactionSupportJobWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.hswebframework.web.async; - -import java.util.concurrent.Callable; - -/** - * 支持事务的任务包装器 - * - * @author zhouhao - */ -public interface TransactionSupportJobWrapper { - /** - * 将一个普通任务包装为支持事务的任务 - * - * @param callable 普通任务 - * @param 任务返回值类型 - * @return 支持事务的任务 - */ - TransactionSupportJob wrapper(Callable callable); -} diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-async-job/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 8fe3b1ec0..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.async.AsyncJobServiceAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/test/resources/application.yml b/hsweb-concurrent/hsweb-concurrent-async-job/src/test/resources/application.yml deleted file mode 100644 index f2eac679f..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/test/resources/application.yml +++ /dev/null @@ -1,18 +0,0 @@ -spring: - aop: - auto: true - datasource: - url : jdbc:h2:mem:async_test_mem - username : sa - password : - type: com.alibaba.druid.pool.DruidDataSource - driver-class-name : org.h2.Driver - initial-size: 100 - max-active: 2000 -hsweb: - app: - name: 异步任务 - version: 3.0.0 -logging: - level: - org.hswebframework: debug \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-cache/pom.xml b/hsweb-concurrent/hsweb-concurrent-cache/pom.xml deleted file mode 100644 index f64fae708..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - hsweb-concurrent - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-cache - - 对spring-cache的拓展 - - - - org.springframework - spring-context - - - - - - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/FixUseSupperClassAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/FixUseSupperClassAutoConfiguration.java deleted file mode 100644 index 2528d3a94..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/FixUseSupperClassAutoConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.hswebframework.web.cache; - -import org.hswebframework.web.cache.spring.fix.FixUseSupperClassAnnotationParser; -import org.hswebframework.web.cache.spring.fix.FixUseSupperClassCacheOperationSource; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.cache.interceptor.CacheOperationSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Role; - -/** - * - * @author zhouhao - */ -@Configuration -public class FixUseSupperClassAutoConfiguration { - @Bean - @Role(BeanDefinition.ROLE_INFRASTRUCTURE) - public CacheOperationSource cacheOperationSource() { - return new FixUseSupperClassCacheOperationSource(new FixUseSupperClassAnnotationParser()); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/monitor/MonitorSupportCache.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/monitor/MonitorSupportCache.java deleted file mode 100644 index 37ea17154..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/monitor/MonitorSupportCache.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.hswebframework.web.cache.monitor; - -import org.springframework.cache.Cache; - -import java.util.Set; - -/** - * 支持监控的缓存 - * - * @author zhouhao - */ -public interface MonitorSupportCache extends Cache { - long getTotalTimes(); - - long getHitTimes(); - - long getUpdateTimes(); - - long size(); - - Set keySet(); -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassAnnotationParser.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassAnnotationParser.java deleted file mode 100644 index 634748674..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassAnnotationParser.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.hswebframework.web.cache.spring.fix; - -import org.springframework.cache.annotation.*; -import org.springframework.cache.interceptor.CacheEvictOperation; -import org.springframework.cache.interceptor.CacheOperation; -import org.springframework.cache.interceptor.CachePutOperation; -import org.springframework.cache.interceptor.CacheableOperation; -import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; - -import java.io.Serializable; -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; - -/** - * Strategy implementation for parsing Spring's {@link Caching}, {@link Cacheable}, - * {@link CacheEvict}, and {@link CachePut} annotations. - * - * @author Costin Leau - * @author Juergen Hoeller - * @author Chris Beams - * @author Phillip Webb - * @author Stephane Nicoll - * @author Sam Brannen - * @since 3.1 - */ -@SuppressWarnings("serial") -public class FixUseSupperClassAnnotationParser implements FixUseSupperClassCacheAnnotationParser, Serializable { - @Override - public Collection parseCacheAnnotations(Class targetClass, Method method) { - DefaultCacheConfig defaultConfig = getDefaultCacheConfig(targetClass); - return parseCacheAnnotations(defaultConfig, method); - } - - @Override - public Collection parseCacheAnnotations(Class type) { - DefaultCacheConfig defaultConfig = getDefaultCacheConfig(type); - return parseCacheAnnotations(defaultConfig, type); - } - - @Override - public Collection parseCacheAnnotations(Method method) { - DefaultCacheConfig defaultConfig = getDefaultCacheConfig(method.getDeclaringClass()); - return parseCacheAnnotations(defaultConfig, method); - } - - protected Collection parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) { - Collection ops = null; - - Collection cacheables = AnnotatedElementUtils.getAllMergedAnnotations(ae, Cacheable.class); - if (!cacheables.isEmpty()) { - ops = lazyInit(ops); - for (Cacheable cacheable : cacheables) { - ops.add(parseCacheableAnnotation(ae, cachingConfig, cacheable)); - } - } - Collection evicts = AnnotatedElementUtils.getAllMergedAnnotations(ae, CacheEvict.class); - if (!evicts.isEmpty()) { - ops = lazyInit(ops); - for (CacheEvict evict : evicts) { - ops.add(parseEvictAnnotation(ae, cachingConfig, evict)); - } - } - Collection puts = AnnotatedElementUtils.getAllMergedAnnotations(ae, CachePut.class); - if (!puts.isEmpty()) { - ops = lazyInit(ops); - for (CachePut put : puts) { - ops.add(parsePutAnnotation(ae, cachingConfig, put)); - } - } - Collection cachings = AnnotatedElementUtils.getAllMergedAnnotations(ae, Caching.class); - if (!cachings.isEmpty()) { - ops = lazyInit(ops); - for (Caching caching : cachings) { - Collection cachingOps = parseCachingAnnotation(ae, cachingConfig, caching); - if (cachingOps != null) { - ops.addAll(cachingOps); - } - } - } - - return ops; - } - - private Collection lazyInit(Collection ops) { - return (ops != null ? ops : new ArrayList(1)); - } - - CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) { - CacheableOperation.Builder builder = new CacheableOperation.Builder(); - - builder.setName(ae.toString()); - builder.setCacheNames(cacheable.cacheNames()); - builder.setCondition(cacheable.condition()); - builder.setUnless(cacheable.unless()); - builder.setKey(cacheable.key()); - builder.setKeyGenerator(cacheable.keyGenerator()); - builder.setCacheManager(cacheable.cacheManager()); - builder.setCacheResolver(cacheable.cacheResolver()); - builder.setSync(cacheable.sync()); - - defaultConfig.applyDefault(builder); - CacheableOperation op = builder.build(); - validateCacheOperation(ae, op); - - return op; - } - - CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CacheEvict cacheEvict) { - CacheEvictOperation.Builder builder = new CacheEvictOperation.Builder(); - - builder.setName(ae.toString()); - builder.setCacheNames(cacheEvict.cacheNames()); - builder.setCondition(cacheEvict.condition()); - builder.setKey(cacheEvict.key()); - builder.setKeyGenerator(cacheEvict.keyGenerator()); - builder.setCacheManager(cacheEvict.cacheManager()); - builder.setCacheResolver(cacheEvict.cacheResolver()); - builder.setCacheWide(cacheEvict.allEntries()); - builder.setBeforeInvocation(cacheEvict.beforeInvocation()); - - defaultConfig.applyDefault(builder); - CacheEvictOperation op = builder.build(); - validateCacheOperation(ae, op); - - return op; - } - - CacheOperation parsePutAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CachePut cachePut) { - CachePutOperation.Builder builder = new CachePutOperation.Builder(); - - builder.setName(ae.toString()); - builder.setCacheNames(cachePut.cacheNames()); - builder.setCondition(cachePut.condition()); - builder.setUnless(cachePut.unless()); - builder.setKey(cachePut.key()); - builder.setKeyGenerator(cachePut.keyGenerator()); - builder.setCacheManager(cachePut.cacheManager()); - builder.setCacheResolver(cachePut.cacheResolver()); - - defaultConfig.applyDefault(builder); - CachePutOperation op = builder.build(); - validateCacheOperation(ae, op); - - return op; - } - - Collection parseCachingAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Caching caching) { - Collection ops = null; - - Cacheable[] cacheables = caching.cacheable(); - if (!ObjectUtils.isEmpty(cacheables)) { - ops = lazyInit(ops); - for (Cacheable cacheable : cacheables) { - ops.add(parseCacheableAnnotation(ae, defaultConfig, cacheable)); - } - } - CacheEvict[] cacheEvicts = caching.evict(); - if (!ObjectUtils.isEmpty(cacheEvicts)) { - ops = lazyInit(ops); - for (CacheEvict cacheEvict : cacheEvicts) { - ops.add(parseEvictAnnotation(ae, defaultConfig, cacheEvict)); - } - } - CachePut[] cachePuts = caching.put(); - if (!ObjectUtils.isEmpty(cachePuts)) { - ops = lazyInit(ops); - for (CachePut cachePut : cachePuts) { - ops.add(parsePutAnnotation(ae, defaultConfig, cachePut)); - } - } - - return ops; - } - - /** - * Provides the {@link DefaultCacheConfig} instance for the specified {@link Class}. - * - * @param target the class-level to handle - * @return the default config (never {@code null}) - */ - DefaultCacheConfig getDefaultCacheConfig(Class target) { - CacheConfig annotation = AnnotatedElementUtils.getMergedAnnotation(target, CacheConfig.class); - if (annotation != null) { - return new DefaultCacheConfig(annotation.cacheNames(), annotation.keyGenerator(), - annotation.cacheManager(), annotation.cacheResolver()); - } - return new DefaultCacheConfig(); - } - - /** - * Validates the specified {@link CacheOperation}. - *

Throws an {@link IllegalStateException} if the state of the operation is - * invalid. As there might be multiple sources for default values, this ensure - * that the operation is in a proper state before being returned. - * - * @param ae the annotated element of the cache operation - * @param operation the {@link CacheOperation} to validate - */ - private void validateCacheOperation(AnnotatedElement ae, CacheOperation operation) { - if (StringUtils.hasText(operation.getKey()) && StringUtils.hasText(operation.getKeyGenerator())) { - throw new IllegalStateException("Invalid cache annotation configuration on '" + - ae.toString() + "'. Both 'key' and 'keyGenerator' attributes have been set. " + - "These attributes are mutually exclusive: either set the SpEL expression used to" + - "compute the key at runtime or set the name of the KeyGenerator bean to use."); - } - if (StringUtils.hasText(operation.getCacheManager()) && StringUtils.hasText(operation.getCacheResolver())) { - throw new IllegalStateException("Invalid cache annotation configuration on '" + - ae.toString() + "'. Both 'cacheManager' and 'cacheResolver' attributes have been set. " + - "These attributes are mutually exclusive: the cache manager is used to configure a" + - "default cache resolver if none is set. If a cache resolver is set, the cache manager" + - "won't be used."); - } - } - - @Override - public boolean equals(Object other) { - return (this == other || other instanceof FixUseSupperClassAnnotationParser); - } - - @Override - public int hashCode() { - return FixUseSupperClassAnnotationParser.class.hashCode(); - } - - - /** - * Provides default settings for a given set of cache operations. - */ - static class DefaultCacheConfig { - - private final String[] cacheNames; - - private final String keyGenerator; - - private final String cacheManager; - - private final String cacheResolver; - - public DefaultCacheConfig() { - this(null, null, null, null); - } - - private DefaultCacheConfig(String[] cacheNames, String keyGenerator, String cacheManager, String cacheResolver) { - this.cacheNames = cacheNames; - this.keyGenerator = keyGenerator; - this.cacheManager = cacheManager; - this.cacheResolver = cacheResolver; - } - - /** - * Apply the defaults to the specified {@link CacheOperation.Builder}. - * - * @param builder the operation builder to update - */ - public void applyDefault(CacheOperation.Builder builder) { - if (builder.getCacheNames().isEmpty() && this.cacheNames != null) { - builder.setCacheNames(this.cacheNames); - } - if (!StringUtils.hasText(builder.getKey()) && !StringUtils.hasText(builder.getKeyGenerator()) && - StringUtils.hasText(this.keyGenerator)) { - builder.setKeyGenerator(this.keyGenerator); - } - - if (StringUtils.hasText(builder.getCacheManager()) || StringUtils.hasText(builder.getCacheResolver())) { - // One of these is set so we should not inherit anything - } else if (StringUtils.hasText(this.cacheResolver)) { - builder.setCacheResolver(this.cacheResolver); - } else if (StringUtils.hasText(this.cacheManager)) { - builder.setCacheManager(this.cacheManager); - } - } - - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheAnnotationParser.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheAnnotationParser.java deleted file mode 100644 index ee20b4f88..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheAnnotationParser.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hswebframework.web.cache.spring.fix; - -import org.springframework.cache.annotation.CacheAnnotationParser; -import org.springframework.cache.interceptor.CacheOperation; - -import java.lang.reflect.Method; -import java.util.Collection; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public interface FixUseSupperClassCacheAnnotationParser extends CacheAnnotationParser { - - Collection parseCacheAnnotations(Class targetClass, Method method); -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheOperationSource.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheOperationSource.java deleted file mode 100644 index b0c670af8..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassCacheOperationSource.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2002-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.hswebframework.web.cache.spring.fix; - -import org.springframework.cache.annotation.CacheAnnotationParser; -import org.springframework.cache.interceptor.CacheOperation; -import org.springframework.util.Assert; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.*; - -/** - * Implementation of the {@link org.springframework.cache.interceptor.CacheOperationSource - * CacheOperationSource} interface for working with caching metadata in annotation format. - *

- *

This class reads Spring's {@link org.springframework.cache.annotation.Cacheable}, {@link org.springframework.cache.annotation.CachePut} and {@link org.springframework.cache.annotation.CacheEvict} - * annotations and exposes corresponding caching operation definition to Spring's cache - * infrastructure. This class may also serve as base class for a custom - * {@code CacheOperationSource}. - * - * @author Costin Leau - * @author Juergen Hoeller - * @author Stephane Nicoll - * @since 3.1 - */ -@SuppressWarnings("serial") -public class FixUseSupperClassCacheOperationSource extends FixUseSupperClassFallbackCacheOperationSource implements Serializable { - - private boolean publicMethodsOnly; - - private final Set annotationParsers; - - - /** - * Create a default AnnotationCacheOperationSource, supporting public methods - * that carry the {@code Cacheable} and {@code CacheEvict} annotations. - */ - public FixUseSupperClassCacheOperationSource() { - this(true); - } - - /** - * Create a default {@code AnnotationCacheOperationSource}, supporting public methods - * that carry the {@code Cacheable} and {@code CacheEvict} annotations. - * - * @param publicMethodsOnly whether to support only annotated public methods - * typically for use with proxy-based AOP), or protected/private methods as well - * (typically used with AspectJ class weaving) - */ - public FixUseSupperClassCacheOperationSource(boolean publicMethodsOnly) { - this.publicMethodsOnly = publicMethodsOnly; - this.annotationParsers = new LinkedHashSet<>(1); - this.annotationParsers.add(new FixUseSupperClassAnnotationParser()); - } - - /** - * Create a custom AnnotationCacheOperationSource. - * - * @param annotationParser the CacheAnnotationParser to use - */ - public FixUseSupperClassCacheOperationSource(FixUseSupperClassCacheAnnotationParser annotationParser) { - this.publicMethodsOnly = true; - Assert.notNull(annotationParser, "CacheAnnotationParser must not be null"); - this.annotationParsers = Collections.singleton(annotationParser); - } - - /** - * Create a custom AnnotationCacheOperationSource. - * - * @param annotationParsers the CacheAnnotationParser to use - */ - public FixUseSupperClassCacheOperationSource(FixUseSupperClassCacheAnnotationParser... annotationParsers) { - this.publicMethodsOnly = true; - Assert.notEmpty(annotationParsers, "At least one CacheAnnotationParser needs to be specified"); - Set parsers = new LinkedHashSet<>(annotationParsers.length); - Collections.addAll(parsers, annotationParsers); - this.annotationParsers = parsers; - } - - /** - * Create a custom AnnotationCacheOperationSource. - * - * @param annotationParsers the CacheAnnotationParser to use - */ - public FixUseSupperClassCacheOperationSource(Set annotationParsers) { - this.publicMethodsOnly = true; - Assert.notEmpty(annotationParsers, "At least one CacheAnnotationParser needs to be specified"); - this.annotationParsers = annotationParsers; - } - - - @Override - protected Collection findCacheOperations(Class targetClass, Method method) { - return determineCacheOperations(parser -> parser.parseCacheAnnotations(targetClass, method)); - } - - @Override - protected Collection findCacheOperations(final Class clazz) { - return determineCacheOperations(parser -> parser.parseCacheAnnotations(clazz)); - } - -// @Override -// protected Collection findCacheOperations(final Method method) { -// return determineCacheOperations(parser -> parser.parseCacheAnnotations(method)); -// } - - /** - * Determine the cache operation(s) for the given {@link CacheOperationProvider}. - *

This implementation delegates to configured - * {@link CacheAnnotationParser}s for parsing known annotations into - * Spring's metadata attribute class. - *

Can be overridden to support custom annotations that carry - * caching metadata. - * - * @param provider the cache operation provider to use - * @return the configured caching operations, or {@code null} if none found - */ - protected Collection determineCacheOperations(CacheOperationProvider provider) { - Collection ops = null; - for (FixUseSupperClassCacheAnnotationParser annotationParser : this.annotationParsers) { - Collection annOps = provider.getCacheOperations(annotationParser); - if (annOps != null) { - if (ops == null) { - ops = new ArrayList<>(); - } - ops.addAll(annOps); - } - } - return ops; - } - - /** - * By default, only public methods can be made cacheable. - */ - @Override - protected boolean allowPublicMethodsOnly() { - return this.publicMethodsOnly; - } - - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof FixUseSupperClassCacheOperationSource)) { - return false; - } - FixUseSupperClassCacheOperationSource otherCos = (FixUseSupperClassCacheOperationSource) other; - return (this.annotationParsers.equals(otherCos.annotationParsers) && - this.publicMethodsOnly == otherCos.publicMethodsOnly); - } - - @Override - public int hashCode() { - return this.annotationParsers.hashCode(); - } - - public void setPublicMethodsOnly(boolean publicMethodsOnly) { - this.publicMethodsOnly = publicMethodsOnly; - } - - /** - * Callback interface providing {@link CacheOperation} instance(s) based on - * a given {@link CacheAnnotationParser}. - */ - protected interface CacheOperationProvider { - - /** - * Return the {@link CacheOperation} instance(s) provided by the specified parser. - * - * @param parser the parser to use - * @return the cache operations, or {@code null} if none found - */ - Collection getCacheOperations(FixUseSupperClassCacheAnnotationParser parser); - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassFallbackCacheOperationSource.java b/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassFallbackCacheOperationSource.java deleted file mode 100644 index df3757f46..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/java/org/hswebframework/web/cache/spring/fix/FixUseSupperClassFallbackCacheOperationSource.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.hswebframework.web.cache.spring.fix; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.cache.interceptor.CacheOperation; -import org.springframework.cache.interceptor.CacheOperationSource; -import org.springframework.core.BridgeMethodResolver; -import org.springframework.core.MethodClassKey; -import org.springframework.util.ClassUtils; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Abstract implementation of {@link CacheOperation} that caches attributes - * for methods and implements a fallback policy: 1. specific target method; - * 2. target class; 3. declaring method; 4. declaring class/interface. - *

- *

Defaults to using the target class's caching attribute if none is - * associated with the target method. Any caching attribute associated with - * the target method completely overrides a class caching attribute. - * If none found on the target class, the interface that the invoked method - * has been called through (in case of a JDK proxy) will be checked. - *

- *

This implementation caches attributes by method after they are first - * used. If it is ever desirable to allow dynamic changing of cacheable - * attributes (which is very unlikely), caching could be made configurable. - * - * @author Costin Leau - * @author Juergen Hoeller - * @author zhouhao - * @see org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource - * @since 3.1 - */ -public abstract class FixUseSupperClassFallbackCacheOperationSource implements CacheOperationSource { - - /** - * Canonical value held in cache to indicate no caching attribute was - * found for this method and we don't need to look again. - */ - private final static Collection NULL_CACHING_ATTRIBUTE = new java.util.ArrayList<>(); - - - /** - * Logger available to subclasses. - *

As this base class is not marked Serializable, the logger will be recreated - * after serialization - provided that the concrete subclass is Serializable. - */ - protected final Log logger = LogFactory.getLog(getClass()); - - /** - * Cache of CacheOperations, keyed by method on a specific target class. - *

As this base class is not marked Serializable, the cache will be recreated - * after serialization - provided that the concrete subclass is Serializable. - */ - private final Map> attributeCache = - new ConcurrentHashMap>(1024); - - - /** - * Determine the caching attribute for this method invocation. - *

Defaults to the class's caching attribute if no method attribute is found. - * - * @param method the method for the current invocation (never {@code null}) - * @param targetClass the target class for this invocation (may be {@code null}) - * @return {@link CacheOperation} for this method, or {@code null} if the method - * is not cacheable - */ - @Override - public Collection getCacheOperations(Method method, Class targetClass) { - if (method.getDeclaringClass() == Object.class) { - return null; - } - - Object cacheKey = getCacheKey(method, targetClass); - Collection cached = this.attributeCache.get(cacheKey); - - if (cached != null) { - return (cached != NULL_CACHING_ATTRIBUTE ? cached : null); - } else { - Collection cacheOps = computeCacheOperations(method, targetClass); - if (cacheOps != null) { - if (logger.isDebugEnabled()) { - logger.debug("Adding cacheable method '" + method.getName() + "' with attribute: " + cacheOps); - } - this.attributeCache.put(cacheKey, cacheOps); - } else { - this.attributeCache.put(cacheKey, NULL_CACHING_ATTRIBUTE); - } - return cacheOps; - } - } - - /** - * Determine a cache key for the given method and target class. - *

Must not produce same key for overloaded methods. - * Must produce same key for different instances of the same method. - * - * @param method the method (never {@code null}) - * @param targetClass the target class (may be {@code null}) - * @return the cache key (never {@code null}) - */ - protected Object getCacheKey(Method method, Class targetClass) { - return new MethodClassKey(method, targetClass); - } - - private Collection computeCacheOperations(Method method, Class targetClass) { - // Don't allow no-public methods as required. - if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { - return null; - } - - // The method may be on an interface, but we need attributes from the target class. - // If the target class is null, the method will be unchanged. - Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass); - // If we are dealing with method with generic parameters, find the original method. - specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod); - - - // First try is the method in the target class. - // 解决@CacheConfig不能继承的问题 - Collection opDef = findCacheOperations(targetClass, specificMethod); - if (opDef != null) { - return opDef; - } - - // Second try is the caching operation on the target class. - opDef = findCacheOperations(specificMethod.getDeclaringClass()); - if (opDef != null && ClassUtils.isUserLevelMethod(method)) { - return opDef; - } - - if (specificMethod != method) { - // Fallback is to look at the original method. - opDef = findCacheOperations(targetClass, method); - if (opDef != null) { - return opDef; - } - // Last fallback is the class of the original method. - opDef = findCacheOperations(method.getDeclaringClass()); - if (opDef != null && ClassUtils.isUserLevelMethod(method)) { - return opDef; - } - } - - return null; - } - - - /** - * Subclasses need to implement this to return the caching attribute - * for the given method, if any. - * - * @param method the method to retrieve the attribute for - * @return all caching attribute associated with this method - * (or {@code null} if none) - */ - protected abstract Collection findCacheOperations(Class targetClass, Method method); - - /** - * Subclasses need to implement this to return the caching attribute - * for the given class, if any. - * - * @param clazz the class to retrieve the attribute for - * @return all caching attribute associated with this class - * (or {@code null} if none) - */ - protected abstract Collection findCacheOperations(Class clazz); - - /** - * Should only public methods be allowed to have caching semantics? - *

The default implementation returns {@code false}. - */ - protected boolean allowPublicMethodsOnly() { - return false; - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-cache/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-cache/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 7668f2026..000000000 --- a/hsweb-concurrent/hsweb-concurrent-cache/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.cache.FixUseSupperClassAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/pom.xml b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/pom.xml deleted file mode 100644 index 747596602..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - hsweb-concurrent-counter - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-counter-api - - 计数器API以及本地实现 - - - - org.springframework.boot - spring-boot-starter - true - - - com.google.guava - guava - 20.0 - true - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractBoomFilterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractBoomFilterManager.java deleted file mode 100644 index d74c7fe3e..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractBoomFilterManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author zhouhao - */ -public abstract class AbstractBoomFilterManager implements BloomFilterManager { - - private final Map counterStore = new HashMap<>(128); - - @Override - public BloomFilter getBloomFilter(String key) { - BloomFilter filter = counterStore.get(key); - if (filter != null) { - return filter; - } - synchronized (counterStore) { - return counterStore.computeIfAbsent(key, this::createBloomFilter); - } - } - - protected abstract BloomFilter createBloomFilter(String name); -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractCounterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractCounterManager.java deleted file mode 100644 index 6dd294792..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/AbstractCounterManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author zhouhao - */ -public abstract class AbstractCounterManager implements CounterManager { - - private final Map counterStore = new HashMap<>(128); - - @Override - public Counter getCounter(String name) { - Counter counter = counterStore.get(name); - if (counter != null) { - return counter; - } - synchronized (counterStore) { - return counterStore.computeIfAbsent(name, this::createCount); - } - } - - protected abstract Counter createCount(String name); -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilter.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilter.java deleted file mode 100644 index cc82e83e7..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilter.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import lombok.SneakyThrows; - -import java.util.function.Supplier; - -public interface BloomFilter { - - boolean put(String unique); - - boolean contains(String unique); - - @SneakyThrows - default void tryPut(String unique, Supplier supplier) { - if (!put(unique)) { - throw supplier.get(); - } - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilterManager.java deleted file mode 100644 index 10c5338dd..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/BloomFilterManager.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -public interface BloomFilterManager { - - BloomFilter getBloomFilter(String key); -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/Counter.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/Counter.java deleted file mode 100644 index add007105..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/Counter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2019 http://www.hswebframework.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.hswebframework.web.concurrent.counter; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public interface Counter { - long get(); - - void set(long num); - - long getAndAdd(long num); - - void add(long num); - - void increment(); - - void decrement(); - - long incrementAndGet(); - - long decrementAndGet(); - -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterAutoConfiguration.java deleted file mode 100644 index 2ecdbb1ea..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterAutoConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author zhouhao - * @since 3.0 - */ -@Configuration -public class CounterAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(CounterManager.class) - public CounterManager counterManager() { - return new SimpleCounterManager(); - } - - - @Bean - @ConditionalOnMissingBean(BloomFilterManager.class) - @ConditionalOnClass(name = "com.google.common.hash.BloomFilter") - public BloomFilterManager bloomFilterManager() { - return new GuavaBloomFilterManager(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterManager.java deleted file mode 100644 index 9aee09842..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/CounterManager.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 http://www.hswebframework.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.hswebframework.web.concurrent.counter; - -/** - * @author zhouhao - */ -public interface CounterManager { - - Counter getCounter(String name); - -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManager.java deleted file mode 100644 index 6cec59a4b..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManager.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import lombok.Getter; -import lombok.Setter; - -import java.nio.charset.StandardCharsets; - -@Getter -@Setter -public class GuavaBloomFilterManager extends AbstractBoomFilterManager { - - private long expectedInsertions = 55000000L; - - private double fpp = 0.01; - - @Override - protected BloomFilter createBloomFilter(String name) { - com.google.common.hash.BloomFilter - filter = com.google.common.hash.BloomFilter.create((str, sink) -> sink.putString(str, StandardCharsets.UTF_8), expectedInsertions, fpp); - return new BloomFilter() { - @Override - public boolean put(String unique) { - return filter.put(unique); - } - - @Override - public boolean contains(String unique) { - return filter.mightContain(unique); - } - }; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounter.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounter.java deleted file mode 100644 index 9dead4d20..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounter.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author zhouhao - */ -public class SimpleCounter implements Counter { - private final AtomicLong counter = new AtomicLong(); - - @Override - public long get() { - return counter.get(); - } - - @Override - public void set(long num) { - counter.set(num); - } - - @Override - public long getAndAdd(long num) { - return counter.getAndAdd(num); - } - - @Override - public void add(long num) { - counter.addAndGet(num); - } - - @Override - public void increment() { - counter.incrementAndGet(); - } - - @Override - public void decrement() { - counter.decrementAndGet(); - } - - @Override - public long incrementAndGet() { - return counter.incrementAndGet(); - } - - @Override - public long decrementAndGet() { - return counter.decrementAndGet(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounterManager.java deleted file mode 100644 index 66e48a9a1..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/java/org/hswebframework/web/concurrent/counter/SimpleCounterManager.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -/** - * @author zhouhao - */ -public class SimpleCounterManager extends AbstractCounterManager { - @Override - protected Counter createCount(String name) { - return new SimpleCounter(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 92f8211fc..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.concurrent.counter.CounterAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/test/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManagerTest.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/test/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManagerTest.java deleted file mode 100644 index bf109ba3d..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-api/src/test/java/org/hswebframework/web/concurrent/counter/GuavaBloomFilterManagerTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hswebframework.web.concurrent.counter; - -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class GuavaBloomFilterManagerTest { - - @Test - public void testGuavaBloomFilter() { - BloomFilterManager manager = new GuavaBloomFilterManager(); - - BloomFilter filter = manager.getBloomFilter("test"); - Assert.assertNotNull(filter); - - for (int i = 0; i < 100000; i++) { - Assert.assertTrue(filter.put("test" + i)); - Assert.assertTrue(filter.contains("test" + i)); - Assert.assertFalse(filter.put("test" + i)); - } - - } - -} \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/pom.xml b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/pom.xml deleted file mode 100644 index 78e094384..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - hsweb-concurrent-counter - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-counter-redis - - 计数器redisson实现 - - - - org.hswebframework.web - hsweb-concurrent-counter-api - ${project.version} - - - org.redisson - redisson - - - org.springframework.boot - spring-boot-starter - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisBloomFilterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisBloomFilterManager.java deleted file mode 100644 index 44e56b05b..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisBloomFilterManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.hswebframework.web.counter.redis; - -import lombok.AllArgsConstructor; -import org.hswebframework.web.concurrent.counter.AbstractBoomFilterManager; -import org.hswebframework.web.concurrent.counter.BloomFilter; -import org.redisson.api.RBloomFilter; -import org.redisson.api.RedissonClient; -import org.redisson.client.codec.StringCodec; - -@AllArgsConstructor -public class RedisBloomFilterManager extends AbstractBoomFilterManager { - - private RedissonClient redissonClient; - - @Override - protected BloomFilter createBloomFilter(String name) { - RBloomFilter filter = redissonClient.getBloomFilter("hsweb:bloom-filter:" + name, StringCodec.INSTANCE); - filter.tryInit(55000000L, 0.01); - return new BloomFilter() { - @Override - public boolean put(String unique) { - return filter.add(unique); - } - - @Override - public boolean contains(String unique) { - return filter.contains(unique); - } - }; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisCounterAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisCounterAutoConfiguration.java deleted file mode 100644 index baefc28d4..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedisCounterAutoConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hswebframework.web.counter.redis; - -import org.hswebframework.web.concurrent.counter.BloomFilterManager; -import org.hswebframework.web.concurrent.counter.CounterAutoConfiguration; -import org.hswebframework.web.concurrent.counter.CounterManager; -import org.redisson.api.RedissonClient; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author zhouhao - * @since 3.0 - */ -@Configuration -@AutoConfigureBefore(CounterAutoConfiguration.class) -public class RedisCounterAutoConfiguration { - - @Bean - @ConditionalOnBean(RedissonClient.class) - public CounterManager counterManager(RedissonClient client) { - return new RedissonCounterManager(client); - } - - - @Bean - @ConditionalOnBean(BloomFilterManager.class) - public BloomFilterManager bloomFilterManager(RedissonClient client) { - return new RedisBloomFilterManager(client); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounter.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounter.java deleted file mode 100644 index 961fb6443..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounter.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.hswebframework.web.counter.redis; - -import org.hswebframework.web.concurrent.counter.Counter; -import org.redisson.api.RAtomicLong; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public class RedissonCounter implements Counter { - - private final RAtomicLong atomicLong; - - public RedissonCounter(RAtomicLong rAtomicLong) { - this.atomicLong = rAtomicLong; - } - - @Override - public long get() { - return atomicLong.get(); - } - - @Override - public void set(long num) { - atomicLong.set(num); - } - - @Override - public long getAndAdd(long num) { - return atomicLong.getAndAdd(num); - } - - @Override - public void add(long num) { - atomicLong.addAndGet(num); - } - - @Override - public void increment() { - atomicLong.incrementAndGet(); - } - - @Override - public void decrement() { - atomicLong.decrementAndGet(); - } - - @Override - public long incrementAndGet() { - return atomicLong.incrementAndGet(); - } - - @Override - public long decrementAndGet() { - return atomicLong.decrementAndGet(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounterManager.java b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounterManager.java deleted file mode 100644 index a6ffe5baf..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/java/org/hswebframework/web/counter/redis/RedissonCounterManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hswebframework.web.counter.redis; - -import org.hswebframework.web.concurrent.counter.AbstractCounterManager; -import org.hswebframework.web.concurrent.counter.Counter; -import org.hswebframework.web.concurrent.counter.CounterManager; -import org.redisson.Redisson; -import org.redisson.api.RAtomicLong; -import org.redisson.api.RedissonClient; - -import java.util.Map; - -/** - * @author zhouhao - */ -public class RedissonCounterManager extends AbstractCounterManager { - - private RedissonClient redisson; - - public RedissonCounterManager(RedissonClient redisson) { - this.redisson = redisson; - } - - @Override - protected Counter createCount(String name) { - return new RedissonCounter(redisson.getAtomicLong(name)); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/resources/META-INF/spring.factories deleted file mode 100644 index dc938065c..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/hsweb-concurrent-counter-redis/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.counter.redis.RedisCounterAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-counter/pom.xml b/hsweb-concurrent/hsweb-concurrent-counter/pom.xml deleted file mode 100644 index 5f52ac1b0..000000000 --- a/hsweb-concurrent/hsweb-concurrent-counter/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - hsweb-concurrent - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - 计数器 - - hsweb-concurrent-counter - pom - - hsweb-concurrent-counter-api - hsweb-concurrent-counter-redis - - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/pom.xml b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/pom.xml deleted file mode 100644 index 2a430f75d..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - hsweb-concurrent-lock - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-lock-api - - 锁API以及本地实现 - - - - org.springframework.boot - spring-boot-starter-test - test - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/AbstractLockManager.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/AbstractLockManager.java deleted file mode 100644 index 5b35b1cba..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/AbstractLockManager.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.hswebframework.web.concurrent.lock; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public abstract class AbstractLockManager implements LockManager { - private final Map lockStore = new HashMap<>(128); - private final Map readWriteLockStore = new HashMap<>(128); - - @Override - public Lock getLock(String lockName) { - Lock lock = lockStore.get(lockName); - if (lock != null) { - return lock; - } - synchronized (lockStore) { - return lockStore.computeIfAbsent(lockName, this::createLock); - } - } - - @Override - public ReadWriteLock getReadWriteLock(String lockName) { - ReadWriteLock lock = readWriteLockStore.get(lockName); - if (lock != null) { - return lock; - } - synchronized (readWriteLockStore) { - return readWriteLockStore.computeIfAbsent(lockName, this::createReadWriteLock); - } - } - - protected abstract Lock createLock(String lockName); - - protected abstract ReadWriteLock createReadWriteLock(String lockName); - -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/LockManager.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/LockManager.java deleted file mode 100644 index da3843c2e..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/LockManager.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hswebframework.web.concurrent.lock; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; - -/** - * 锁工厂,用于创建获取锁 - * - * @author zhouhao - * @see Lock - * @see ReadWriteLock - * @since 3.0 - */ -public interface LockManager { - /** - * 根据锁名称获取锁,相同的名称,则锁也相同 - * - * @param lockName 锁名称 - * @return 锁对象 - * @see Lock - */ - Lock getLock(String lockName); - - /** - * 根据锁名称获取读写锁,相同的名称,则锁也相同 - * - * @param lockName 锁名称 - * @return 读写锁对象 - * @see ReadWriteLock - */ - ReadWriteLock getReadWriteLock(String lockName); -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/SimpleLockManager.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/SimpleLockManager.java deleted file mode 100644 index 2b605aa5e..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/SimpleLockManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hswebframework.web.concurrent.lock; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * 使用jdk的锁实现 - * - * @author zhouhao - * @see ReentrantLock - * @see ReentrantReadWriteLock - * @see AbstractLockManager - * @since 3.0 - */ -public class SimpleLockManager extends AbstractLockManager { - @Override - protected Lock createLock(String lockName) { - return new ReentrantLock(); - } - - @Override - protected ReadWriteLock createReadWriteLock(String lockName) { - return new ReentrantReadWriteLock(); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/Lock.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/Lock.java deleted file mode 100644 index 546a4c1d0..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/Lock.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.hswebframework.web.concurrent.lock.annotation; - -import java.lang.annotation.*; -import java.util.concurrent.TimeUnit; - -/** - * 锁注解,在方法上注解,则对此方法加锁 - * - * @author zhouhao - * @see org.hswebframework.web.concurrent.lock.LockManager - * @see java.util.concurrent.locks.Lock - * @since 3.0 - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface Lock { - /** - * 锁名,支持表达式,表达式使用 ${} 进行标识;如果此值为空,则使用方法名称作为锁名 - * e.g. - *

-     *     @Lock("my_lock_${#id}")
-     *     public void foo(String id){
-     *
-     *     }
-     *
-     *     @Lock(value="my_lock_${#id}",condition="#id!=null")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * - * @return 锁名称, 支持spel表达式 - * @see org.hswebframework.web.concurrent.lock.LockManager#getLock(String) - */ - String[] value() default {}; - - /** - * 锁的条件表达式,当满足条件的时候才执行锁 - * e.g. - *
-     *     @Lock(value="my_lock_${#id}",condition="#id!=null")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * - * @return 条件表达式 - */ - String condition() default ""; - - - /** - * 超时时间,超过此时间不能获取锁则抛出异常{@link InterruptedException},如果设置为-1,则认为不设置超时时间 - * - * @return 超时时间, 默认10秒 - */ - long timeout() default 10; - - /** - * @return 超时时间单位, 秒 - */ - TimeUnit timeUnit() default TimeUnit.SECONDS; -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/ReadLock.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/ReadLock.java deleted file mode 100644 index d4a8cfd7c..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/ReadLock.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.hswebframework.web.concurrent.lock.annotation; - -import java.lang.annotation.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReadWriteLock; - -/** - * 读锁注解,在方法上注解,则对此方法加锁. - * - * @author zhouhao - * @see org.hswebframework.web.concurrent.lock.LockManager - * @see ReadWriteLock#readLock() - * @since 3.0 - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface ReadLock { - /** - * 锁名,支持表达式,表达式使用 ${} 进行标识;如果此值为空,则使用方法名称作为锁名 - * e.g. - *
-     *     @ReadLock("my_lock_${#id}")
-     *     public void foo(String id){
-     *
-     *     }
-     *
-     *     @ReadLock(value="my_lock_${#id}",condition="#id!=null")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * - * @return 锁名称, 支持spel表达式 - * @see org.hswebframework.web.concurrent.lock.LockManager#getReadWriteLock(String) - */ - String[] value() default {}; - - /** - * 锁的条件表达式,当满足条件的时候才执行锁 - * e.g. - *
-     *     @ReadLock(value="my_lock_${#id}",condition="#id!=null")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * @return 条件表达式 - */ - String condition() default ""; - - /** - * 超时时间,超过此时间不能获取锁则抛出异常{@link InterruptedException},如果设置为-1,则认为不设置超时时间 - * - * @return 超时时间, 默认10秒 - */ - long timeout() default 10; - - /** - * @return 超时时间单位, 秒 - */ - TimeUnit timeUnit() default TimeUnit.SECONDS; -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/WriteLock.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/WriteLock.java deleted file mode 100644 index f555cc843..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/main/java/org/hswebframework/web/concurrent/lock/annotation/WriteLock.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.hswebframework.web.concurrent.lock.annotation; - -import java.lang.annotation.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReadWriteLock; - -/** - * 写锁注解,在方法上注解,则对此方法加锁.
- * e.g. - *
- *     @ReadLock("my_lock_${#id}")
- *     public void foo(String id){
- *          //do some thing
- *     }
- * 
- * 满足条件才锁 - * e.g. - *
- *     @WriteLock(value="my_lock_${#id}",condition="#id!=null")
- *     public void foo(String id){
- *
- *     }
- * 
- * - * @author zhouhao - * @see org.hswebframework.web.concurrent.lock.LockManager - * @see ReadWriteLock#writeLock() - * @since 3.0 - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface WriteLock { - /** - * 锁名,支持表达式,表达式使用 ${} 进行标识;如果此值为空,则使用方法名称作为锁名 - * e.g. - *
-     *     @ReadLock("my_lock_${#id}")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * - * @return 锁名称, 支持spel表达式 - * @see org.hswebframework.web.concurrent.lock.LockManager#getReadWriteLock(String) - */ - String[] value() default {}; - - /** - * 锁的条件表达式,当满足条件的时候才执行锁 - * e.g. - *
-     *     @WriteLock(value="my_lock_${#id}",condition="#id!=null")
-     *     public void foo(String id){
-     *
-     *     }
-     * 
- * - * @return 条件表达式 - */ - String condition() default ""; - - /** - * 超时时间,超过此时间不能获取锁则抛出异常{@link InterruptedException},如果设置为-1,则认为不设置超时时间 - * - * @return 超时时间, 默认10秒 - */ - long timeout() default 10; - - /** - * @return 超时时间单位, 秒 - */ - TimeUnit timeUnit() default TimeUnit.SECONDS; -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/test/java/org/hswebframework/web/concurrent/lok/SimpleLockTests.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/test/java/org/hswebframework/web/concurrent/lok/SimpleLockTests.java deleted file mode 100644 index d7a1c52a7..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-api/src/test/java/org/hswebframework/web/concurrent/lok/SimpleLockTests.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.hswebframework.web.concurrent.lok; - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.concurrent.lock.SimpleLockManager; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.function.Consumer; - -/** - * @author zhouhao - */ -public class SimpleLockTests { - - private LockManager lockManager = new SimpleLockManager(); - - private long counter = 0; - - @Test - public void testLock() throws InterruptedException { - counter = 0; - Lock lock = lockManager.getLock("foo"); - for (int i = 0; i < 100; i++) { - new Thread(() -> { - lock.lock(); - for (int i1 = 0; i1 < 100; i1++) { - counter++; - } - lock.unlock(); - }).start(); - } - Thread.sleep(1000); - Assert.assertEquals(counter, 100 * 100); - } - - @Test - public void testReadWriteLock() throws InterruptedException { - counter = 0; - ReadWriteLock readWriteLock = lockManager.getReadWriteLock("foo"); - - Lock readLock = readWriteLock.readLock(); - - Lock writeLock = readWriteLock.writeLock(); - Consumer[] consumer = new Consumer[1]; - consumer[0] = System.out::println; - for (int i = 0; i < 10; i++) { - new Thread(() -> { - for (int i1 = 0; i1 < 10; i1++) { - try { - Thread.sleep(500); - } catch (InterruptedException ignored) { - } - writeLock.lock(); - long tmp = ++counter; - - //判断增加的值与 读取的值一致 - consumer[0] = l -> Assert.assertEquals(Long.valueOf(tmp), l); - System.out.println("write:" + counter); - writeLock.unlock(); - } - }).start(); - new Thread(() -> { - for (int i1 = 0; i1 < 10; i1++) { - try { - Thread.sleep(500); - } catch (InterruptedException ignored) { - } - readLock.lock(); - consumer[0].accept(counter); - System.out.println("read:" + counter); - readLock.unlock(); - } - }).start(); - } - Thread.sleep(5000); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/pom.xml b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/pom.xml deleted file mode 100644 index 9efbb79d9..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - hsweb-concurrent-lock - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-lock-redis - - 使用redisson实现分布式锁 - - - - org.redisson - redisson - - - org.hswebframework.web - hsweb-concurrent-lock-api - ${project.version} - - - io.netty - netty-transport-native-epoll - 4.1.8.Final - provided - linux-x86_64 - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/main/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockManager.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/main/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockManager.java deleted file mode 100644 index 8623cedf4..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/main/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.hswebframework.web.concurrent.lock.redis; - -import org.hswebframework.web.concurrent.lock.AbstractLockManager; -import org.redisson.api.RedissonClient; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; - -/** - * @author zhouhao - */ -public class RedissonLockManager extends AbstractLockManager { - private RedissonClient redisson; - - public RedissonLockManager(RedissonClient redisson) { - if (null == redisson) { - throw new NullPointerException(); - } - this.redisson = redisson; - } - - @Override - protected Lock createLock(String lockName) { - return redisson.getFairLock(lockName); - } - - @Override - protected ReadWriteLock createReadWriteLock(String lockName) { - return redisson.getReadWriteLock(lockName); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/test/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockTest.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/test/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockTest.java deleted file mode 100644 index d47ccbc20..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-redis/src/test/java/org/hswebframework/web/concurrent/lock/redis/RedissonLockTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.hswebframework.web.concurrent.lock.redis; - - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.junit.Assert; -import org.redisson.Redisson; -import org.redisson.config.Config; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.function.Consumer; - -/** - * @author zhouhao - */ -public class RedissonLockTest { - static long counter = 0; - - static LockManager lockManager = null; - - static Redisson redisson; - - public static LockManager createLockFactory() { - if (lockManager != null) { - return lockManager; - } - Config config = new Config(); -// config.setUseLinuxNativeEpoll(true); - config.useSingleServer().setAddress("redis://127.0.0.1:6379"); - redisson = (Redisson) Redisson.create(config); - return lockManager = new RedissonLockManager(redisson); - } - - public static void main(String[] args) throws InterruptedException { - testLock(); - - testReadWriteLock(); - redisson.shutdown(); - } - - public static void testReadWriteLock() throws InterruptedException { - counter = 0; - LockManager lockManager = createLockFactory(); - - ReadWriteLock readWriteLock = lockManager.getReadWriteLock("foo"); - - Lock readLock = readWriteLock.readLock(); - - Lock writeLock = readWriteLock.writeLock(); - Consumer[] consumer = new Consumer[1]; - consumer[0] = System.out::println; - for (int i = 0; i < 10; i++) { - new Thread(() -> { - for (int i1 = 0; i1 < 10; i1++) { - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { - } - writeLock.lock(); - long tmp = ++counter; - - //判断增加的值与 读取的值一致 - consumer[0] = l -> Assert.assertEquals(Long.valueOf(tmp), l); - System.out.println("write:" + counter); - writeLock.unlock(); - } - }).start(); - new Thread(() -> { - for (int i1 = 0; i1 < 10; i1++) { - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { - } - readLock.lock(); - consumer[0].accept(counter); - System.out.println("read:" + counter); - readLock.unlock(); - } - }).start(); - } - Thread.sleep(5000); - System.out.println("wait 5s"); - } - - public static void testLock() throws InterruptedException { - counter = 0; - LockManager lockManager = createLockFactory(); - Lock lock = lockManager.getLock("foo"); - for (int i = 0; i < 100; i++) { - new Thread(() -> { - lock.lock(); - for (int i1 = 0; i1 < 100; i1++) { - counter++; - } - lock.unlock(); - }).start(); - } - Thread.sleep(1000); - System.out.println(counter); - Assert.assertEquals(counter, 100 * 100); - } -} \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/pom.xml b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/pom.xml deleted file mode 100644 index cd5626f8d..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - hsweb-concurrent-lock - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-lock-starter - - 使用AOP实现锁 - - - - org.springframework.boot - spring-boot-starter - - - org.hswebframework.web - hsweb-concurrent-lock-api - ${project.version} - - - org.hswebframework.web - hsweb-concurrent-lock-redis - ${project.version} - true - - - org.hswebframework.web - hsweb-boost-aop - ${project.version} - - - org.hswebframework.web - hsweb-tests - ${project.version} - test - - - com.h2database - h2 - test - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/AopLockAdvisor.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/AopLockAdvisor.java deleted file mode 100644 index 0dde660a4..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/AopLockAdvisor.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import lombok.extern.slf4j.Slf4j; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.hswebframework.web.AopUtils; -import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder; -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.concurrent.lock.annotation.Lock; -import org.hswebframework.web.concurrent.lock.annotation.ReadLock; -import org.hswebframework.web.concurrent.lock.annotation.WriteLock; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.TimeUnit; - -/** - * @author zhouhao - */ -@Slf4j -public class AopLockAdvisor extends StaticMethodMatcherPointcutAdvisor { - - public AopLockAdvisor(LockManager lockManager) { - Objects.requireNonNull(lockManager); - setAdvice((MethodInterceptor) methodInvocation -> { - MethodInterceptorHolder holder = MethodInterceptorHolder.create(methodInvocation); - Lock lockAnn = holder.findMethodAnnotation(Lock.class); - ReadLock readLockAnn = holder.findMethodAnnotation(ReadLock.class); - WriteLock writeLock = holder.findMethodAnnotation(WriteLock.class); - List lockProcessors = new ArrayList<>(); - if (null != lockAnn) { - lockProcessors.add(initLockInfo(lockAnn.timeout(), lockAnn.timeUnit(), - LockProcessor.build(lockAnn, holder) - .lockNameIs(Lock::value) - .lockIs(lockManager::getLock))); - } - if (null != readLockAnn) { - lockProcessors.add(initLockInfo(readLockAnn.timeout(), readLockAnn.timeUnit(), - LockProcessor.build(readLockAnn, holder) - .lockNameIs(ReadLock::value) - .lockIs(name -> lockManager.getReadWriteLock(name).readLock()))); - } - if (null != writeLock) { - lockProcessors.add(initLockInfo(writeLock.timeout(), writeLock.timeUnit(), - LockProcessor.build(writeLock, holder) - .lockNameIs(WriteLock::value) - .lockIs(name -> lockManager.getReadWriteLock(name).writeLock()))); - } - boolean lockError = false; - try { - for (LockProcessor processor : lockProcessors) { - Throwable e = processor.doLock(); - if (e != null) { - lockError = true; - throw e; - } - } - return methodInvocation.proceed(); - } finally { - for (LockProcessor processor : lockProcessors) { - try { - processor.doUnlock(); - } catch (Exception e) { - if (!lockError) { - log.error("unlock {} error", methodInvocation.getMethod(), e); - } - } - } - } - }); - } - - protected LockProcessor initLockInfo(long timeout, TimeUnit timeUnit, LockProcessor lockProcessor) { - return lockProcessor - .lock(lock -> lock.tryLock(timeout, timeUnit)) - .unlock(lock -> { - lock.unlock(); - return true; - }).init(); - } - - @Override - public int getOrder() { - return Integer.MIN_VALUE; - } - - @Override - public boolean matches(Method method, Class aClass) { - Lock lock = AopUtils.findMethodAnnotation(aClass, method, Lock.class); - if (null != lock) { - return true; - } - ReadLock readLock = AopUtils.findMethodAnnotation(aClass, method, ReadLock.class); - if (null != readLock) { - return true; - } - WriteLock writeLock = AopUtils.findMethodAnnotation(aClass, method, WriteLock.class); - if (null != writeLock) { - return true; - } - return false; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockManagerAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockManagerAutoConfiguration.java deleted file mode 100644 index fc71e70ee..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockManagerAutoConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.concurrent.lock.SimpleLockManager; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author zhouhao - */ -@Configuration -public class LockManagerAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(LockManager.class) - public LockManager lockManager() { - return new SimpleLockManager(); - } - - @Bean - public AopLockAdvisor aopLockAdvisor(LockManager lockManager) { - return new AopLockAdvisor(lockManager); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockProcessor.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockProcessor.java deleted file mode 100644 index c03486b01..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/LockProcessor.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - - -import org.hswebframework.web.AopUtils; -import org.hswebframework.web.ExpressionUtils; -import org.hswebframework.web.boost.aop.context.MethodInterceptorHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - -import java.lang.annotation.Annotation; -import java.util.*; -import java.util.concurrent.TimeoutException; -import java.util.function.Function; - -/** - * @author zhouhao - */ -@SuppressWarnings("unchecked") -public class LockProcessor { - - private Logger logger = LoggerFactory.getLogger(this.getClass()); - - private A lockAnn; - - private MethodInterceptorHolder interceptorHolder; - - private Function lockNameGetter; - - private Function lockGetter; - - private LockAccepter lockAccepter; - - private LockAccepter unlockAccepter; - - private Map lockStore = new HashMap<>(); - - private LockProcessor() { - } - - public static LockProcessor build(A annotation, MethodInterceptorHolder holder) { - LockProcessor alLockProcessor = new LockProcessor<>(); - alLockProcessor.lockAnn = annotation; - alLockProcessor.interceptorHolder = holder; - return alLockProcessor; - } - - public LockProcessor lockNameIs(Function lockNameGetter) { - this.lockNameGetter = lockNameGetter; - return this; - } - - public LockProcessor lockIs(Function lockGetter) { - this.lockGetter = lockGetter; - return this; - } - - public LockProcessor lock(LockAccepter lockAccepter) { - this.lockAccepter = lockAccepter; - return this; - } - - public LockProcessor unlock(LockAccepter unlockAccepter) { - this.unlockAccepter = unlockAccepter; - return this; - } - - public LockProcessor init() { - Objects.requireNonNull(lockAnn); - Objects.requireNonNull(interceptorHolder); - Objects.requireNonNull(lockNameGetter); - String[] lockNameArr = lockNameGetter.apply(lockAnn); - if (lockNameArr.length == 0) { - String name = createLockName(null); - lockStore.put(name, lockGetter.apply(name)); - } else { - for (String expression : lockNameArr) { - String name = createLockName(expression); - lockStore.put(name, lockGetter.apply(name)); - } - } - return this; - } - - protected String createLockName(String expression) { - try { - if (StringUtils.isEmpty(expression)) { - return interceptorHolder.getMethod().getName().concat("_").concat(interceptorHolder.getId()); - } - return ExpressionUtils.analytical(expression, interceptorHolder.getArgs(), "spel"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private List successLock = new ArrayList<>(); - - public Throwable doLock() { - Throwable lockError = null; - for (Map.Entry lock : lockStore.entrySet()) { - try { - boolean success = lockAccepter.accept(lock.getValue()); - if (!success) { - return new TimeoutException("try lock " + lock.getKey() + " error"); - } - successLock.add(lock.getValue()); - } catch (Throwable throwable) { - lockError = throwable; - } - } - return lockError; - } - - public void doUnlock() { - for (L lock : successLock) { - try { - unlockAccepter.accept(lock); - } catch (Throwable error) { - logger.error("unlock {} error", interceptorHolder.getMethod(), error); - } - } - } - - public interface LockAccepter { - boolean accept(T t) throws Throwable; - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/RedisLockManagerAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/RedisLockManagerAutoConfiguration.java deleted file mode 100644 index 8e2362176..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/java/org/hswebframework/web/concurrent/lock/starter/RedisLockManagerAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.concurrent.lock.redis.RedissonLockManager; -import org.redisson.api.RedissonClient; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author zhouhao - */ -@Configuration -@ConditionalOnClass({RedissonClient.class, RedissonLockManager.class}) -@ConditionalOnBean(RedissonClient.class) -public class RedisLockManagerAutoConfiguration { - @Bean - public LockManager lockManager(RedissonClient redissonClient) { - return new RedissonLockManager(redissonClient); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 95601ca05..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,4 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.concurrent.lock.starter.LockManagerAutoConfiguration,\ - org.hswebframework.web.concurrent.lock.starter.RedisLockManagerAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockAnnotationTest.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockAnnotationTest.java deleted file mode 100644 index 980be1211..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockAnnotationTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.tests.SimpleWebApplicationTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.redisson.Redisson; -import org.redisson.api.RedissonClient; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = TestApplication.class) -public class LockAnnotationTest extends AbstractTransactionalJUnit4SpringContextTests { - @Autowired - private LockService lockService; - - @Autowired - private LockManager lockManager; - - @Test - public void testLock() throws InterruptedException { - new Thread(() -> { - System.out.println("锁住"); - lockService.testLockSleep("test", 2000); - System.out.println("解锁"); - }).start(); - Thread.sleep(200); - System.out.println("开始任务1"); - lockService.testLock("test"); - System.out.println("任务1结束"); - for (int i = 0; i < 100; i++) { - new Thread(() -> lockService.testLock("test")).start(); - } - Thread.sleep(5000); - Assert.assertEquals(lockService.getCounter(), 101); - - lockService.reset(); - } - - - @Test - public void testReadLock() throws InterruptedException { - new Thread(() -> { - try { - System.out.println("锁住"); - lockManager.getReadWriteLock("lock_test").writeLock().lock(); - Thread.sleep(2000); //停顿2秒 - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("解锁"); - lockManager.getReadWriteLock("lock_test").writeLock().unlock(); - }).start(); - Thread.sleep(200); - System.out.println("开始任务1"); - lockService.testReadLock("test"); - System.out.println("任务1结束"); - for (int i = 0; i < 100; i++) { - new Thread(() -> lockService.testWriteLock("test")).start(); - } - Thread.sleep(5000); - Assert.assertEquals(lockService.getCounter(), 101); - lockService.reset(); - } - - -} \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockService.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockService.java deleted file mode 100644 index eac104026..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/LockService.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import lombok.extern.slf4j.Slf4j; -import org.hswebframework.web.concurrent.lock.annotation.Lock; -import org.hswebframework.web.concurrent.lock.annotation.ReadLock; -import org.hswebframework.web.concurrent.lock.annotation.WriteLock; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -/** - * @author zhouhao - */ -@Slf4j -public class LockService { - - private long counter = 0; - -// @Scheduled(cron = "0/1 * * * * ?") -// @Lock("test2") -// public void test() throws InterruptedException { -// log.info("try lock"); -// Thread.sleep(5000); -// log.info("un lock"); -// } - - @Lock("lock_${#key}") - public long testLockSleep(String key, long time) { - try { - Thread.sleep(time); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return counter; - } - - @Lock("lock_${#key}") - public long testLock(String key) { - return counter++; - } - - @ReadLock("lock_${#key}") - public long testReadLock(String key) { - return counter++; - } - - @WriteLock("lock_${#key}") - public long testWriteLock(String key) { - return counter++; - } - - public long getCounter() { - return counter; - } - - public void reset() { - counter = 0; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/TestApplication.java b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/TestApplication.java deleted file mode 100644 index 8f115d929..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/java/org/hswebframework/web/concurrent/lock/starter/TestApplication.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.hswebframework.web.concurrent.lock.starter; - -import org.hswebframework.web.concurrent.lock.LockManager; -import org.hswebframework.web.concurrent.lock.redis.RedissonLockManager; -import org.redisson.Redisson; -import org.redisson.api.RedissonClient; -import org.redisson.config.Config; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.EnableScheduling; - -@Configuration -@SpringBootApplication -@EnableScheduling -public class TestApplication { -// @Bean -// public RedissonClient redissonClient() { -// Config config = new Config(); -// config.useSingleServer().setAddress("redis://127.0.0.1:6379"); -// config.setLockWatchdogTimeout(60_1000); -// -// return Redisson.create(); -// } - -// @Bean -// public LockManager lockManager(RedissonClient redissonClient) { -// return new RedissonLockManager(redissonClient); -// } - - @Bean - public LockService lockService() { - return new LockService(); - } -} \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/resources/application.yml b/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/resources/application.yml deleted file mode 100644 index 099287677..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/hsweb-concurrent-lock-starter/src/test/resources/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -spring: - datasource: - url : jdbc:h2:mem:test_mem - username : sa - password : - type: com.alibaba.druid.pool.DruidDataSource - driver-class-name : org.h2.Driver - -hsweb: - app: - name: lock测试 - version: 3.0.0 \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-lock/pom.xml b/hsweb-concurrent/hsweb-concurrent-lock/pom.xml deleted file mode 100644 index 19993c61f..000000000 --- a/hsweb-concurrent/hsweb-concurrent-lock/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - hsweb-concurrent - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - 锁模块 - - hsweb-concurrent-lock - pom - - hsweb-concurrent-lock-api - hsweb-concurrent-lock-redis - hsweb-concurrent-lock-starter - - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/pom.xml b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/pom.xml deleted file mode 100644 index c19b63f78..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - hsweb-concurrent-rate-limiter - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-rate-limiter-api - - - - com.google.guava - guava - 20.0 - true - - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/AbstractRateLimiterManager.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/AbstractRateLimiterManager.java deleted file mode 100644 index 8631b4e9f..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/AbstractRateLimiterManager.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hswebframework.web.concurrent; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -/** - * @author zhouhao - * @since 3.0.4 - */ -public abstract class AbstractRateLimiterManager implements RateLimiterManager { - private final Map counterStore = new HashMap<>(128); - - protected abstract RateLimiter createRateLimiter(String key, double permits, TimeUnit timeUnit); - - @Override - public RateLimiter getRateLimiter(String key, double permits, TimeUnit timeUnit) { - RateLimiter counter = counterStore.get(key); - if (counter != null) { - return counter; - } - synchronized (counterStore) { - return counterStore.computeIfAbsent(key, k -> createRateLimiter(key, permits, timeUnit)); - } - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/GuavaRateLimiterManager.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/GuavaRateLimiterManager.java deleted file mode 100644 index c565986a0..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/GuavaRateLimiterManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hswebframework.web.concurrent; - -import java.util.concurrent.TimeUnit; - -/** - * @author zhouhao - * @since 3.0.4 - */ -public class GuavaRateLimiterManager extends AbstractRateLimiterManager { - @Override - protected RateLimiter createRateLimiter(String key, double permits, TimeUnit timeUnit) { - long seconds = timeUnit.toSeconds(1); - double permitsPerSecond = permits; - - if (seconds > 0) { - permitsPerSecond = permits / timeUnit.toSeconds(1); - } else { - if (timeUnit == TimeUnit.MILLISECONDS) { - permitsPerSecond = permits / 1000D; - } - } - - com.google.common.util.concurrent.RateLimiter rateLimiter = - com.google.common.util.concurrent.RateLimiter.create(permitsPerSecond); - return rateLimiter::tryAcquire; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiter.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiter.java deleted file mode 100644 index 8bf6bfc38..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiter.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hswebframework.web.concurrent; - -import java.util.concurrent.TimeUnit; - -/** - * @author zhouhao - * @since 3.0.4 - */ -public interface RateLimiter { - - boolean tryAcquire(int permits, long timeout, TimeUnit timeUnit); - - default boolean tryAcquire(long timeout, TimeUnit unit) { - return tryAcquire(1, timeout, unit); - } - -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiterManager.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiterManager.java deleted file mode 100644 index c6325f6ba..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/RateLimiterManager.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.hswebframework.web.concurrent; - -import java.util.concurrent.TimeUnit; - -/** - * @author zhouhao - * @since 3.0.4 - */ -public interface RateLimiterManager { - - RateLimiter getRateLimiter(String key, double permits, TimeUnit timeUnit); -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/annotation/RateLimiter.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/annotation/RateLimiter.java deleted file mode 100644 index ba334c89e..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/main/java/org/hswebframework/web/concurrent/annotation/RateLimiter.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.hswebframework.web.concurrent.annotation; - -import java.lang.annotation.*; -import java.util.concurrent.TimeUnit; - -/** - * 开启限流 - * - * @author zhouhao - * @see org.hswebframework.web.concurrent.RateLimiter - * @since 3.0.4 - */ -@Target({ElementType.TYPE, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface RateLimiter { - - /** - * key,支持spel表达式: ${#username+'login'} .默认以当前注解的方法为key - * - * @return 限流Key - */ - String[] key() default {}; - - /** - * @return 时间单位内允许访问次数, 如:每秒100次 - */ - double permits() default 100D; - - /** - * @return 时间单位, 支持毫秒及以上的时间单位 - */ - TimeUnit timeUnit() default TimeUnit.SECONDS; - - long acquire() default 10; - - TimeUnit acquireTimeUnit() default TimeUnit.SECONDS; -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/test/java/org/hswebframework/web/concurrent/GuavaRateLimiterManagerTest.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/test/java/org/hswebframework/web/concurrent/GuavaRateLimiterManagerTest.java deleted file mode 100644 index 51bf2acf0..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-api/src/test/java/org/hswebframework/web/concurrent/GuavaRateLimiterManagerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hswebframework.web.concurrent; - -import lombok.SneakyThrows; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - - -/** - * @author zhouhao - * @since 3.0.4 - */ -public class GuavaRateLimiterManagerTest { - GuavaRateLimiterManager manager = new GuavaRateLimiterManager(); - - @SneakyThrows - @Test - public void testRateLimiter() { - RateLimiter limiter = manager.getRateLimiter("test", 1, TimeUnit.SECONDS); - for (int i = 0; i < 10; i++) { - if (!limiter.tryAcquire(10, TimeUnit.SECONDS)) { - throw new UnsupportedOperationException(); - } - System.out.println(i + ":" + System.currentTimeMillis()); - } - - } -} \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/pom.xml b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/pom.xml deleted file mode 100644 index 148e13f3b..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - hsweb-concurrent-rate-limiter - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-rate-limiter-starter - - - - org.hswebframework.web - hsweb-concurrent-rate-limiter-api - ${project.version} - - - org.springframework.boot - spring-boot-starter - - - org.hswebframework.web - hsweb-commons-utils - ${project.version} - - - org.hswebframework.web - hsweb-authorization-api - ${project.version} - - - com.google.guava - guava - 20.0 - test - - - - org.hswebframework.web - hsweb-tests - ${project.version} - test - - - org.springframework - spring-aspects - - - \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAopAdvisor.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAopAdvisor.java deleted file mode 100644 index 7068c2a8b..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAopAdvisor.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.hswebframework.web.concurent; - -import lombok.extern.slf4j.Slf4j; -import org.hswebframework.web.ExpressionUtils; -import org.hswebframework.web.authorization.Authentication; -import org.hswebframework.web.concurrent.RateLimiterManager; -import org.hswebframework.web.concurrent.annotation.RateLimiter; -import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; -import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.util.ClassUtils; - -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.TimeoutException; - -/** - * @author zhouhao - * @since 3.0.4 - */ -@Slf4j -public class RateLimiterAopAdvisor extends StaticMethodMatcherPointcutAdvisor { - - private static final long serialVersionUID = -1076122956392948260L; - private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); - - public RateLimiterAopAdvisor(RateLimiterManager rateLimiterManager) { - setAdvice((MethodBeforeAdvice) (method, args, target) -> { - String[] names = nameDiscoverer.getParameterNames(method); - RateLimiter limiter = Optional.ofNullable(AnnotationUtils.findAnnotation(method, RateLimiter.class)) - .orElseGet(() -> AnnotationUtils.findAnnotation(ClassUtils.getUserClass(target), RateLimiter.class)); - if (limiter != null) { - List keyExpressionList = new ArrayList<>(Arrays.asList(limiter.key())); - if (keyExpressionList.isEmpty()) { - keyExpressionList.add(method.toString()); - } - for (String keyExpress : keyExpressionList) { - if (keyExpress.contains("${")) { - Map params = new HashMap<>(); - params.put("user", Authentication.current().map(Authentication::getUser).orElse(null)); - for (int i = 0; i < args.length; i++) { - params.put(names.length > i ? names[i] : "arg" + i, args[i]); - params.put("arg" + i, args[i]); - - } - keyExpress = ExpressionUtils.analytical(keyExpress, params, "spel"); - } - log.debug("do rate limiter:[{}]. ", keyExpress); - boolean success = rateLimiterManager - .getRateLimiter(keyExpress, limiter.permits(), limiter.timeUnit()) - .tryAcquire(limiter.acquire(), limiter.acquireTimeUnit()); - if (!success) { - throw new TimeoutException("请求超时"); - } - } - } - }); - } - - - @Override - public boolean matches(Method method, Class targetClass) { - - return AnnotationUtils.findAnnotation(method, RateLimiter.class) != null - || AnnotationUtils.findAnnotation(targetClass, RateLimiter.class) != null; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAutoConfiguration.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAutoConfiguration.java deleted file mode 100644 index 003bf7079..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/java/org/hswebframework/web/concurent/RateLimiterAutoConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.hswebframework.web.concurent; - -import org.hswebframework.web.concurrent.GuavaRateLimiterManager; -import org.hswebframework.web.concurrent.RateLimiterManager; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author zhouhao - * @since 3.0.4 - */ -@Configuration -public class RateLimiterAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(RateLimiterManager.class) - @ConditionalOnClass(name = "com.google.common.util.concurrent.RateLimiter") - public GuavaRateLimiterManager guavaRateLimiterManager() { - return new GuavaRateLimiterManager(); - } - - @Bean - @ConditionalOnBean(RateLimiterManager.class) - public RateLimiterAopAdvisor rateLimiterAopAdvisor(RateLimiterManager rateLimiterManager) { - return new RateLimiterAopAdvisor(rateLimiterManager); - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/resources/META-INF/spring.factories b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index c102a8a67..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.hswebframework.web.concurent.RateLimiterAutoConfiguration \ No newline at end of file diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/RateLimiterAopAdvisorTest.groovy b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/RateLimiterAopAdvisorTest.groovy deleted file mode 100644 index a22492033..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/RateLimiterAopAdvisorTest.groovy +++ /dev/null @@ -1,48 +0,0 @@ -package org.hswebframework.web.concurent - -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration -import spock.lang.Specification - -/** - * @author zhouhao - * @since 3.0.4 - */ -@SpringBootTest(classes = TestApplication.class) -@ContextConfiguration -class RateLimiterAopAdvisorTest extends Specification { - - @Autowired - public TestService testService; - - def "测试限流"() { - TestService.counter.set(0); - given: - testService.test(); - def timeoutException; - try { - testService.test(); - } catch (Exception e) { - timeoutException = e; - } - expect: - TestService.counter.get() == 1 - timeoutException != null - } - - def "测试指定key限流"() { - TestService.counter.set(0); - given: - testService.test("test"); - def timeoutException; - try { - testService.test("test"); - } catch (Exception e) { - timeoutException = e; - } - expect: - TestService.counter.get() == 1 - timeoutException != null - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestApplication.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestApplication.java deleted file mode 100644 index aad35e625..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestApplication.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.hswebframework.web.concurent; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * @author zhouhao - * @since 3.0.4 - */ -@SpringBootApplication -public class TestApplication { -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestService.java b/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestService.java deleted file mode 100644 index e76f82c7e..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/hsweb-concurrent-rate-limiter-starter/src/test/groovy/org/hswebframework/web/concurent/TestService.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.hswebframework.web.concurent; - -import org.hswebframework.web.concurrent.annotation.RateLimiter; -import org.springframework.stereotype.Service; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author zhouhao - * @since 3.0.4 - */ -@Service -public class TestService { - - public static AtomicLong counter = new AtomicLong(); - - - @RateLimiter(permits = 1, acquire = 500, acquireTimeUnit = TimeUnit.MILLISECONDS) //一秒一次 - public String test() { - counter.incrementAndGet(); - return "ok"; - } - - @RateLimiter(key = "${#name}", permits = 1, acquire = 500, acquireTimeUnit = TimeUnit.MILLISECONDS) - public String test(String name) { - counter.incrementAndGet(); - return name; - } -} diff --git a/hsweb-concurrent/hsweb-concurrent-rate-limiter/pom.xml b/hsweb-concurrent/hsweb-concurrent-rate-limiter/pom.xml deleted file mode 100644 index 3f509024f..000000000 --- a/hsweb-concurrent/hsweb-concurrent-rate-limiter/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - hsweb-concurrent - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - hsweb-concurrent-rate-limiter - pom - - hsweb-concurrent-rate-limiter-api - hsweb-concurrent-rate-limiter-starter - - - - \ No newline at end of file diff --git a/hsweb-concurrent/pom.xml b/hsweb-concurrent/pom.xml deleted file mode 100644 index 099274818..000000000 --- a/hsweb-concurrent/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - hsweb-framework - org.hswebframework.web - 3.0.10-SNAPSHOT - - 4.0.0 - - 并发包 - - hsweb-concurrent - pom - - hsweb-concurrent-cache - hsweb-concurrent-lock - hsweb-concurrent-counter - hsweb-concurrent-async-job - hsweb-concurrent-rate-limiter - - - - \ No newline at end of file diff --git a/hsweb-core/pom.xml b/hsweb-core/pom.xml index 89dd986f8..9002f8578 100644 --- a/hsweb-core/pom.xml +++ b/hsweb-core/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 @@ -18,7 +18,7 @@ org.javassist javassist - + 3.22.0-GA org.hswebframework diff --git a/hsweb-datasource/hsweb-datasource-api/pom.xml b/hsweb-datasource/hsweb-datasource-api/pom.xml index 9d730d6ef..27cd0f657 100644 --- a/hsweb-datasource/hsweb-datasource-api/pom.xml +++ b/hsweb-datasource/hsweb-datasource-api/pom.xml @@ -5,7 +5,7 @@ hsweb-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-datasource/hsweb-datasource-jta/pom.xml b/hsweb-datasource/hsweb-datasource-jta/pom.xml index de47f4cdf..50db4a1a0 100644 --- a/hsweb-datasource/hsweb-datasource-jta/pom.xml +++ b/hsweb-datasource/hsweb-datasource-jta/pom.xml @@ -5,7 +5,7 @@ hsweb-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-datasource/hsweb-datasource-web/pom.xml b/hsweb-datasource/hsweb-datasource-web/pom.xml index 34a88c5be..88d0ef9cc 100644 --- a/hsweb-datasource/hsweb-datasource-web/pom.xml +++ b/hsweb-datasource/hsweb-datasource-web/pom.xml @@ -5,7 +5,7 @@ hsweb-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-datasource/pom.xml b/hsweb-datasource/pom.xml index 3e0b60c3c..f9ed0a828 100644 --- a/hsweb-datasource/pom.xml +++ b/hsweb-datasource/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-logging/hsweb-access-logging-aop/pom.xml b/hsweb-logging/hsweb-access-logging-aop/pom.xml index 9a2afcf1d..5a2a9ee0a 100644 --- a/hsweb-logging/hsweb-access-logging-aop/pom.xml +++ b/hsweb-logging/hsweb-access-logging-aop/pom.xml @@ -5,7 +5,7 @@ hsweb-logging org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-logging/hsweb-access-logging-api/pom.xml b/hsweb-logging/hsweb-access-logging-api/pom.xml index 6f98bd465..7975a1268 100644 --- a/hsweb-logging/hsweb-access-logging-api/pom.xml +++ b/hsweb-logging/hsweb-access-logging-api/pom.xml @@ -5,7 +5,7 @@ hsweb-logging org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-logging/pom.xml b/hsweb-logging/pom.xml index 5e1002ef4..3ad26f657 100644 --- a/hsweb-logging/pom.xml +++ b/hsweb-logging/pom.xml @@ -23,7 +23,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-starter/hsweb-spring-boot-starter/pom.xml b/hsweb-starter/hsweb-spring-boot-starter/pom.xml index 6fc34f71d..fa0c2557c 100644 --- a/hsweb-starter/hsweb-spring-boot-starter/pom.xml +++ b/hsweb-starter/hsweb-spring-boot-starter/pom.xml @@ -23,7 +23,7 @@ hsweb-starter org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-starter/pom.xml b/hsweb-starter/pom.xml index 088d78339..b8ab1a929 100644 --- a/hsweb-starter/pom.xml +++ b/hsweb-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/pom.xml index 30fa7e932..a9ecc5007 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/pom.xml index 8f721bd0e..e8138287e 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthenticationManager.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthenticationManager.java index a5f7861eb..a9f0f2b6a 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthenticationManager.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthenticationManager.java @@ -6,7 +6,6 @@ import org.hswebframework.web.authorization.Authentication; import org.hswebframework.web.authorization.AuthenticationInitializeService; import org.hswebframework.web.authorization.AuthenticationManager; import org.hswebframework.web.authorization.AuthenticationRequest; -import org.hswebframework.web.authorization.listener.event.AuthorizationFailedEvent; import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest; import org.hswebframework.web.commons.entity.DataStatus; import org.hswebframework.web.entity.authorization.UserEntity; diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java index 60edfd531..d4e6af04d 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-local/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorizationSettingService.java @@ -22,17 +22,14 @@ import org.hswebframework.web.authorization.Authentication; import org.hswebframework.web.authorization.AuthenticationInitializeService; import org.hswebframework.web.authorization.Permission; import org.hswebframework.web.authorization.access.DataAccessConfig; -import org.hswebframework.web.authorization.listener.event.AuthorizationInitializeEvent; +import org.hswebframework.web.authorization.events.AuthorizationInitializeEvent; import org.hswebframework.web.authorization.simple.SimpleAuthentication; import org.hswebframework.web.authorization.simple.SimplePermission; import org.hswebframework.web.authorization.simple.SimpleRole; import org.hswebframework.web.authorization.simple.SimpleUser; import org.hswebframework.web.bean.FastBeanCopier; import org.hswebframework.web.commons.entity.DataStatus; -import org.hswebframework.web.commons.entity.QueryEntity; import org.hswebframework.web.commons.entity.TreeSupportEntity; -import org.hswebframework.web.commons.entity.factory.EntityFactory; -import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.dao.authorization.AuthorizationSettingDao; import org.hswebframework.web.dao.authorization.AuthorizationSettingDetailDao; import org.hswebframework.web.entity.authorization.*; @@ -68,7 +65,6 @@ import static org.hswebframework.web.commons.entity.DataStatus.STATUS_ENABLED; import static org.hswebframework.web.entity.authorization.AuthorizationSettingDetailEntity.*; import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.settingFor; import static org.hswebframework.web.entity.authorization.AuthorizationSettingEntity.type; -import static org.hswebframework.web.service.DefaultDSLDeleteService.*; import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_AUTH_CACHE_NAME; import static org.hswebframework.web.service.authorization.simple.CacheConstants.USER_MENU_CACHE_NAME; diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml index f81fd9cdb..5c1c926a6 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml @@ -22,7 +22,7 @@ hsweb-system-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-web/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-web/pom.xml index b3d7d42ab..fa081d455 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-web/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-authorization org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-authorization/pom.xml b/hsweb-system/hsweb-system-authorization/pom.xml index efa90feca..b85e88e5a 100644 --- a/hsweb-system/hsweb-system-authorization/pom.xml +++ b/hsweb-system/hsweb-system-authorization/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-api/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-api/pom.xml index 3250602aa..f6d37c608 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-api/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-api/pom.xml @@ -23,7 +23,7 @@ hsweb-system-config org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-local/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-local/pom.xml index 59c713d8e..6ab007a1c 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-local/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-local/pom.xml @@ -23,7 +23,7 @@ hsweb-system-config org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/pom.xml index b8982510e..175ba71f4 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-config org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-web/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-web/pom.xml index 6fd64ff56..b1e21cd84 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-web/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-web/pom.xml @@ -23,7 +23,7 @@ hsweb-system-config org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-config/pom.xml b/hsweb-system/hsweb-system-config/pom.xml index b6c260ed9..1652c3edc 100644 --- a/hsweb-system/hsweb-system-config/pom.xml +++ b/hsweb-system/hsweb-system-config/pom.xml @@ -23,7 +23,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-api/pom.xml b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-api/pom.xml index 251139fe8..f5160137d 100644 --- a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-api/pom.xml +++ b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dashboard org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-local/pom.xml b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-local/pom.xml index 4054798d8..58246d6e0 100644 --- a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-local/pom.xml +++ b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dashboard org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-starter/pom.xml b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-starter/pom.xml index bf1c12d39..caea7c84a 100644 --- a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-starter/pom.xml +++ b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dashboard org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-web/pom.xml b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-web/pom.xml index 29a751d95..45fd7826c 100644 --- a/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-web/pom.xml +++ b/hsweb-system/hsweb-system-dashboard/hsweb-system-dashboard-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dashboard org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dashboard/pom.xml b/hsweb-system/hsweb-system-dashboard/pom.xml index ba93b3a03..bc6d7c847 100644 --- a/hsweb-system/hsweb-system-dashboard/pom.xml +++ b/hsweb-system/hsweb-system-dashboard/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-api/pom.xml b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-api/pom.xml index 0e096f062..4eb3fd585 100644 --- a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-api/pom.xml +++ b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-database-manager org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-local/pom.xml b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-local/pom.xml index 9eba8afd3..065c98687 100644 --- a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-local/pom.xml +++ b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-database-manager org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-starter/pom.xml b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-starter/pom.xml index ef0f8b3f6..16bc710c3 100644 --- a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-starter/pom.xml +++ b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-database-manager org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-web/pom.xml b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-web/pom.xml index 9f94f140c..3da25869b 100644 --- a/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-web/pom.xml +++ b/hsweb-system/hsweb-system-database-manager/hsweb-system-database-manager-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-database-manager org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-database-manager/pom.xml b/hsweb-system/hsweb-system-database-manager/pom.xml index dceb47599..3e29e6ac2 100644 --- a/hsweb-system/hsweb-system-database-manager/pom.xml +++ b/hsweb-system/hsweb-system-database-manager/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-api/pom.xml b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-api/pom.xml index 526333db2..15c988e9d 100644 --- a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-api/pom.xml +++ b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-local/pom.xml b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-local/pom.xml index dff18869d..4e9278162 100644 --- a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-local/pom.xml +++ b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-starter/pom.xml b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-starter/pom.xml index f26c6c1ab..2a45734cf 100644 --- a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-starter/pom.xml +++ b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-web/pom.xml b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-web/pom.xml index 28ca6521b..1bf54659a 100644 --- a/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-web/pom.xml +++ b/hsweb-system/hsweb-system-datasource/hsweb-system-datasource-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-datasource org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-datasource/pom.xml b/hsweb-system/hsweb-system-datasource/pom.xml index 658df57e9..e26ddda27 100644 --- a/hsweb-system/hsweb-system-datasource/pom.xml +++ b/hsweb-system/hsweb-system-datasource/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml diff --git a/hsweb-system/hsweb-system-dev-tools/pom.xml b/hsweb-system/hsweb-system-dev-tools/pom.xml index e807da49d..8f5f46d27 100644 --- a/hsweb-system/hsweb-system-dev-tools/pom.xml +++ b/hsweb-system/hsweb-system-dev-tools/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-api/pom.xml b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-api/pom.xml index 72614865c..f6a84ef63 100644 --- a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-api/pom.xml +++ b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dictionary org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/pom.xml b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/pom.xml index 63fffe755..d7d5b8e12 100644 --- a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/pom.xml +++ b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dictionary org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-starter/pom.xml b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-starter/pom.xml index 99d21dcbd..3f95aae51 100644 --- a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-starter/pom.xml +++ b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-starter/pom.xml @@ -22,7 +22,7 @@ hsweb-system-dictionary org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-web/pom.xml b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-web/pom.xml index 79f2996ed..1d0da5dd8 100644 --- a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-web/pom.xml +++ b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dictionary org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dictionary/pom.xml b/hsweb-system/hsweb-system-dictionary/pom.xml index 29dad9d1b..1e744874d 100644 --- a/hsweb-system/hsweb-system-dictionary/pom.xml +++ b/hsweb-system/hsweb-system-dictionary/pom.xml @@ -22,7 +22,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-api/pom.xml b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-api/pom.xml index 2e9ef2e4b..5c20c35b1 100644 --- a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-api/pom.xml +++ b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dynamic-form org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/pom.xml b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/pom.xml index df87e94dc..20c1e65a3 100644 --- a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/pom.xml +++ b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dynamic-form org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-starter/pom.xml b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-starter/pom.xml index 17e643094..467866e2f 100644 --- a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-starter/pom.xml +++ b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dynamic-form org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-web/pom.xml b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-web/pom.xml index 8273a810b..085abac0e 100644 --- a/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-web/pom.xml +++ b/hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-dynamic-form org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-dynamic-form/pom.xml b/hsweb-system/hsweb-system-dynamic-form/pom.xml index f99eb4ae5..3f117d975 100644 --- a/hsweb-system/hsweb-system-dynamic-form/pom.xml +++ b/hsweb-system/hsweb-system-dynamic-form/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-api/pom.xml b/hsweb-system/hsweb-system-file/hsweb-system-file-api/pom.xml index 9e711e628..0feba0f96 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-api/pom.xml +++ b/hsweb-system/hsweb-system-file/hsweb-system-file-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-file org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-local/pom.xml b/hsweb-system/hsweb-system-file/hsweb-system-file-local/pom.xml index 194e62436..caeb25fae 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-local/pom.xml +++ b/hsweb-system/hsweb-system-file/hsweb-system-file-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-file org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-oauth2/pom.xml b/hsweb-system/hsweb-system-file/hsweb-system-file-oauth2/pom.xml index f4a6b22ba..b0ef72e3d 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-oauth2/pom.xml +++ b/hsweb-system/hsweb-system-file/hsweb-system-file-oauth2/pom.xml @@ -5,7 +5,7 @@ hsweb-system-file org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-starter/pom.xml b/hsweb-system/hsweb-system-file/hsweb-system-file-starter/pom.xml index cffbe56cb..46a441cc6 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-starter/pom.xml +++ b/hsweb-system/hsweb-system-file/hsweb-system-file-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-file org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/hsweb-system-file-web/pom.xml b/hsweb-system/hsweb-system-file/hsweb-system-file-web/pom.xml index c86de0dea..5a6639e91 100644 --- a/hsweb-system/hsweb-system-file/hsweb-system-file-web/pom.xml +++ b/hsweb-system/hsweb-system-file/hsweb-system-file-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-file org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-file/pom.xml b/hsweb-system/hsweb-system-file/pom.xml index 8c728b3b1..691ff7c21 100644 --- a/hsweb-system/hsweb-system-file/pom.xml +++ b/hsweb-system/hsweb-system-file/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-api/pom.xml b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-api/pom.xml index 8a3bbb96a..9b7ce28d0 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-api/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-oauth2-client org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-local/pom.xml b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-local/pom.xml index 5abf85007..965603caf 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-local/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-oauth2-client org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-starter/pom.xml b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-starter/pom.xml index 73bf7258e..5f3647d89 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-starter/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-starter/pom.xml @@ -22,7 +22,7 @@ hsweb-system-oauth2-client org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-web/pom.xml b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-web/pom.xml index 4d41bda2b..21e4a48d3 100644 --- a/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-web/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-oauth2-client org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-client/pom.xml b/hsweb-system/hsweb-system-oauth2-client/pom.xml index 85eb871ac..e869ff210 100644 --- a/hsweb-system/hsweb-system-oauth2-client/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-client/pom.xml @@ -23,7 +23,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/pom.xml b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/pom.xml index 0a429c5c3..ab5fc3681 100644 --- a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-oauth2-server org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/pom.xml b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/pom.xml index 1205a2369..6d48e7f0b 100644 --- a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-starter/pom.xml @@ -23,7 +23,7 @@ hsweb-system-oauth2-server org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-web/pom.xml b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-web/pom.xml index 413260ebf..b680d8557 100644 --- a/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-web/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-server/hsweb-system-oauth2-server-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-oauth2-server org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-oauth2-server/pom.xml b/hsweb-system/hsweb-system-oauth2-server/pom.xml index 544f4c540..75ca89dba 100644 --- a/hsweb-system/hsweb-system-oauth2-server/pom.xml +++ b/hsweb-system/hsweb-system-oauth2-server/pom.xml @@ -23,7 +23,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-api/pom.xml b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-api/pom.xml index 6764036c8..3597d002a 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-api/pom.xml +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-organizational org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml index 313ca5b8a..4d86e504d 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-authorization/pom.xml @@ -5,7 +5,7 @@ hsweb-system-organizational org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/pom.xml b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/pom.xml index 18bb2bdd7..893eff4a8 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/pom.xml +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-organizational org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-starter/pom.xml b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-starter/pom.xml index d278ffa76..505c7ef6a 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-starter/pom.xml +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-starter/pom.xml @@ -22,7 +22,7 @@ hsweb-system-organizational org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-web/pom.xml b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-web/pom.xml index 5c9de6abd..e9df3062a 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-web/pom.xml +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-organizational org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-organizational/pom.xml b/hsweb-system/hsweb-system-organizational/pom.xml index ee323e58f..6572b7e1c 100644 --- a/hsweb-system/hsweb-system-organizational/pom.xml +++ b/hsweb-system/hsweb-system-organizational/pom.xml @@ -22,7 +22,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-api/pom.xml b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-api/pom.xml index 3969014eb..65f219cf9 100644 --- a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-api/pom.xml +++ b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-schedule org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-local/pom.xml b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-local/pom.xml index cfba8b098..cf2fe5bde 100644 --- a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-local/pom.xml +++ b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-schedule org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-starter/pom.xml b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-starter/pom.xml index e98195840..d5a38a796 100644 --- a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-starter/pom.xml +++ b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-schedule org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-web/pom.xml b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-web/pom.xml index e8287ba4e..75d1c079d 100644 --- a/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-web/pom.xml +++ b/hsweb-system/hsweb-system-schedule/hsweb-system-schedule-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-schedule org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-schedule/pom.xml b/hsweb-system/hsweb-system-schedule/pom.xml index 854ea4df0..72abaa205 100644 --- a/hsweb-system/hsweb-system-schedule/pom.xml +++ b/hsweb-system/hsweb-system-schedule/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 pom diff --git a/hsweb-system/hsweb-system-script/hsweb-system-script-api/pom.xml b/hsweb-system/hsweb-system-script/hsweb-system-script-api/pom.xml index f7d6cc2f1..a9d909bc0 100644 --- a/hsweb-system/hsweb-system-script/hsweb-system-script-api/pom.xml +++ b/hsweb-system/hsweb-system-script/hsweb-system-script-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-script org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-script/hsweb-system-script-local/pom.xml b/hsweb-system/hsweb-system-script/hsweb-system-script-local/pom.xml index dcb2c2357..86361afe7 100644 --- a/hsweb-system/hsweb-system-script/hsweb-system-script-local/pom.xml +++ b/hsweb-system/hsweb-system-script/hsweb-system-script-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-script org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml b/hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml index daff229f1..8128c7639 100644 --- a/hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml +++ b/hsweb-system/hsweb-system-script/hsweb-system-script-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-script org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-script/hsweb-system-script-web/pom.xml b/hsweb-system/hsweb-system-script/hsweb-system-script-web/pom.xml index 5883a3696..f4e78b0f1 100644 --- a/hsweb-system/hsweb-system-script/hsweb-system-script-web/pom.xml +++ b/hsweb-system/hsweb-system-script/hsweb-system-script-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-script org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-script/pom.xml b/hsweb-system/hsweb-system-script/pom.xml index 1021ec71f..739a16c34 100644 --- a/hsweb-system/hsweb-system-script/pom.xml +++ b/hsweb-system/hsweb-system-script/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-template/hsweb-system-template-api/pom.xml b/hsweb-system/hsweb-system-template/hsweb-system-template-api/pom.xml index 00ebd2313..c2e9a6b35 100644 --- a/hsweb-system/hsweb-system-template/hsweb-system-template-api/pom.xml +++ b/hsweb-system/hsweb-system-template/hsweb-system-template-api/pom.xml @@ -5,7 +5,7 @@ hsweb-system-template org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-template/hsweb-system-template-local/pom.xml b/hsweb-system/hsweb-system-template/hsweb-system-template-local/pom.xml index 312c4a8ed..a5fa48d9a 100644 --- a/hsweb-system/hsweb-system-template/hsweb-system-template-local/pom.xml +++ b/hsweb-system/hsweb-system-template/hsweb-system-template-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-template org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-template/hsweb-system-template-starter/pom.xml b/hsweb-system/hsweb-system-template/hsweb-system-template-starter/pom.xml index dee1c18a3..f00829279 100644 --- a/hsweb-system/hsweb-system-template/hsweb-system-template-starter/pom.xml +++ b/hsweb-system/hsweb-system-template/hsweb-system-template-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-template org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-template/hsweb-system-template-web/pom.xml b/hsweb-system/hsweb-system-template/hsweb-system-template-web/pom.xml index 1d17593f5..1147f6aa6 100644 --- a/hsweb-system/hsweb-system-template/hsweb-system-template-web/pom.xml +++ b/hsweb-system/hsweb-system-template/hsweb-system-template-web/pom.xml @@ -5,7 +5,7 @@ hsweb-system-template org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-template/pom.xml b/hsweb-system/hsweb-system-template/pom.xml index 8fe893642..f51c96c9d 100644 --- a/hsweb-system/hsweb-system-template/pom.xml +++ b/hsweb-system/hsweb-system-template/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-local/pom.xml b/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-local/pom.xml index 219ba9c6e..f7be57d00 100644 --- a/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-local/pom.xml +++ b/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-local/pom.xml @@ -5,7 +5,7 @@ hsweb-system-workflow org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-starter/pom.xml b/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-starter/pom.xml index a51f080c6..840e69c4a 100644 --- a/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-starter/pom.xml +++ b/hsweb-system/hsweb-system-workflow/hsweb-system-workflow-starter/pom.xml @@ -5,7 +5,7 @@ hsweb-system-workflow org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/hsweb-system-workflow/pom.xml b/hsweb-system/hsweb-system-workflow/pom.xml index 0f8070e45..4cf36739f 100644 --- a/hsweb-system/hsweb-system-workflow/pom.xml +++ b/hsweb-system/hsweb-system-workflow/pom.xml @@ -5,7 +5,7 @@ hsweb-system org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-system/pom.xml b/hsweb-system/pom.xml index 6dd22e8af..924e1f3f3 100644 --- a/hsweb-system/pom.xml +++ b/hsweb-system/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-tests/pom.xml b/hsweb-tests/pom.xml index e8363c8d1..e9c8748a4 100644 --- a/hsweb-tests/pom.xml +++ b/hsweb-tests/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/hsweb-thirdparty/hsweb-thirdparty-ueditor/pom.xml b/hsweb-thirdparty/hsweb-thirdparty-ueditor/pom.xml index 44acadead..26eec574d 100644 --- a/hsweb-thirdparty/hsweb-thirdparty-ueditor/pom.xml +++ b/hsweb-thirdparty/hsweb-thirdparty-ueditor/pom.xml @@ -5,7 +5,7 @@ hsweb-thirdparty org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hsweb-thirdparty/pom.xml b/hsweb-thirdparty/pom.xml index 6ea060da7..7c826c64b 100644 --- a/hsweb-thirdparty/pom.xml +++ b/hsweb-thirdparty/pom.xml @@ -5,7 +5,7 @@ hsweb-framework org.hswebframework.web - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 676a81d3c..731f54d62 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.hswebframework.web hsweb-framework - 3.0.10-SNAPSHOT + 4.0.0-SNAPSHOT hsweb-starter hsweb-core @@ -34,7 +34,6 @@ hsweb-datasource hsweb-commons hsweb-logging - hsweb-concurrent hsweb-boost hsweb-thirdparty @@ -82,8 +81,7 @@ 1.8 ${java.version} - - 1.5.19.RELEASE + 2.2.0.M6 3.20.0-GA 5.19.0.2 @@ -95,7 +93,7 @@ 1.6.12 5.1.1.Final - 3.0.6 + 4.0.0-SNAPSHOT 3.0.2 3.0.2 @@ -239,14 +237,9 @@ - addTestSources - compile - compileTests - - @@ -276,10 +269,7 @@ - - - - + org.codehaus.groovy groovy-all @@ -312,6 +302,11 @@ + + org.hibernate + hibernate-validator + 6.0.17.Final + io.vavr vavr @@ -383,20 +378,20 @@ org.hswebframework - hsweb-easy-orm + hsweb-easy-orm-rdb + ${hsweb.ezorm.version} + + + + org.hswebframework + hsweb-easy-orm-core + ${hsweb.ezorm.version} + + + + org.hswebframework + hsweb-easy-orm-elasticsearch ${hsweb.ezorm.version} - - - org.hswebframework - hsweb-expands-script - - - com.alibaba - fastjson - - - pom - import @@ -443,11 +438,19 @@ + aliyun-nexus aliyun http://maven.aliyun.com/nexus/content/groups/public/ + + + spring.io + spring + https://repo.spring.io/milestone + +