mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-18 12:25:15 +00:00
perf[orm]: 优化缓存注解
This commit is contained in:
@@ -305,9 +305,10 @@ public class OrmManager implements IOrmManager {
|
||||
var cacheStrategies = ormConfig.getCaches();
|
||||
var persisterStrategies = ormConfig.getPersisters();
|
||||
|
||||
var cache = clazz.getAnnotation(EntityCache.class);
|
||||
var cacheStrategyOptional = cacheStrategies.stream().filter(it -> it.getStrategy().equals(cache.cacheStrategy())).findFirst();
|
||||
AssertionUtils.isTrue(cacheStrategyOptional.isPresent(), "实体类Entity[{}]没有找到缓存策略[{}]", clazz.getSimpleName(), cache.cacheStrategy());
|
||||
var entityCache = clazz.getAnnotation(EntityCache.class);
|
||||
var cache = entityCache.cache();
|
||||
var cacheStrategyOptional = cacheStrategies.stream().filter(it -> it.getStrategy().equals(cache.value())).findFirst();
|
||||
AssertionUtils.isTrue(cacheStrategyOptional.isPresent(), "实体类Entity[{}]没有找到缓存策略[{}]", clazz.getSimpleName(), cache.value());
|
||||
|
||||
var cacheStrategy = cacheStrategyOptional.get();
|
||||
var cacheSize = cacheStrategy.getSize();
|
||||
@@ -316,9 +317,9 @@ public class OrmManager implements IOrmManager {
|
||||
var idField = ReflectionUtils.getFieldsByAnnoInPOJOClass(clazz, Id.class)[0];
|
||||
ReflectionUtils.makeAccessible(idField);
|
||||
|
||||
var persister = cache.persister();
|
||||
var persister = entityCache.persister();
|
||||
var persisterStrategyOptional = persisterStrategies.stream().filter(it -> it.getStrategy().equals(persister.value())).findFirst();
|
||||
AssertionUtils.isTrue(persisterStrategyOptional.isPresent(), "实体类Entity[{}]没有找到持久化策略[{}]", clazz.getSimpleName(), persister);
|
||||
AssertionUtils.isTrue(persisterStrategyOptional.isPresent(), "实体类Entity[{}]没有找到持久化策略[{}]", clazz.getSimpleName(), persister.value());
|
||||
|
||||
var persisterStrategy = persisterStrategyOptional.get();
|
||||
var indexDefMap = new HashMap<String, IndexDef>();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo 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 com.zfoo.orm.model.anno;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface Cache {
|
||||
|
||||
String value() default "default";
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface EntityCache {
|
||||
|
||||
String cacheStrategy();
|
||||
Cache cache() default @Cache;
|
||||
|
||||
Persister persister() default @Persister;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.zfoo.orm.model.entity.IEntity;
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@EntityCache(cacheStrategy = "thousand", persister = @Persister("time30s"))
|
||||
@EntityCache(persister = @Persister("time30s"))
|
||||
public class MailEnt implements IEntity<String> {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
* @version 3.0@EntityCache(persister = @Persister("time30s"))
|
||||
*/
|
||||
@EntityCache(cacheStrategy = "thousand", persister = @Persister("time30s"))
|
||||
@EntityCache
|
||||
public class UserEntity implements IEntity<Long> {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@EntityCache(cacheStrategy = "thousand", persister = @Persister("time30s"))
|
||||
@EntityCache(persister = @Persister("time30s"))
|
||||
public class MapEntity implements IEntity<Long> {
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@@ -30,11 +30,12 @@
|
||||
<orm:cache strategy="hundred" size="100" expire-millisecond="600000"/>
|
||||
<orm:cache strategy="thousand" size="1000" expire-millisecond="600000"/>
|
||||
<orm:cache strategy="threeThousand" size="3000" expire-millisecond="600000"/>
|
||||
<orm:cache strategy="default" size="5000" expire-millisecond="600000"/>
|
||||
</orm:caches>
|
||||
|
||||
<!-- 持久化策略 -->
|
||||
<orm:persisters>
|
||||
<orm:persister strategy="cronDefault" type="cron" config="0,30 * * * * ?"/>
|
||||
<orm:persister strategy="default" type="cron" config="0,30 * * * * ?"/>
|
||||
<orm:persister strategy="cron30s" type="cron" config="0/30 * * * * ?"/>
|
||||
<orm:persister strategy="time30s" type="time" config="30000"/>
|
||||
</orm:persisters>
|
||||
|
||||
Reference in New Issue
Block a user