feat: 优化缓存代码

This commit is contained in:
wangyu 2023-03-02 11:30:57 +08:00
parent df4349b774
commit 75d302a510

View File

@ -46,8 +46,7 @@ public final class EntityNameUtils {
} }
public static Map<String, String> getFields(Class<?> clazz) { public static Map<String, String> getFields(Class<?> clazz) {
tryCache(clazz); return tryCache(clazz);
return COLUMN_CACHE.get(clazz);
} }
/** /**
@ -78,7 +77,7 @@ public final class EntityNameUtils {
SerializedLambda lambda = resolve(func); SerializedLambda lambda = resolve(func);
String property = SqlNameUtils.methodToProperty(lambda.getImplMethodName()); String property = SqlNameUtils.methodToProperty(lambda.getImplMethodName());
Class<?> beanClass = resolveEntityClass(lambda); Class<?> beanClass = resolveEntityClass(lambda);
String column = COLUMN_CACHE.get(beanClass).getOrDefault(property, SqlNameUtils.camelToUnderline(property)); String column = tryCache(beanClass).getOrDefault(property, SqlNameUtils.camelToUnderline(property));
// 取得别名缓存 // 取得别名缓存
AliasComposite.AliasCache cache = AliasComposite.sharedCache(); AliasComposite.AliasCache cache = AliasComposite.sharedCache();
// 确定最终名称 // 确定最终名称
@ -117,7 +116,9 @@ public final class EntityNameUtils {
* @return 最终获取的类 * @return 最终获取的类
*/ */
private static Class<?> resolveEntityClass(SerializedLambda lambda) { private static Class<?> resolveEntityClass(SerializedLambda lambda) {
return tryCache(lambda.getInstantiatedType()); Class<?> type = lambda.getInstantiatedType();
tryCache(type);
return type;
} }
/** /**
@ -150,8 +151,7 @@ public final class EntityNameUtils {
* *
* @param entityClass bean的类型 * @param entityClass bean的类型
*/ */
private static Class<?> tryCache(Class<?> entityClass) { private static Map<String, String> tryCache(Class<?> entityClass) {
COLUMN_CACHE.computeIfAbsent(entityClass, EntityNameUtils::buildFieldsCache); return COLUMN_CACHE.computeIfAbsent(entityClass, EntityNameUtils::buildFieldsCache);
return entityClass;
} }
} }