Browse Source

性能优化

woody 5 months ago
parent
commit
ca68884b15

+ 5 - 4
framework-base/src/main/java/com/chelvc/framework/base/context/ApplicationContextHolder.java

@@ -2,6 +2,7 @@ package com.chelvc.framework.base.context;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.ref.WeakReference;
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.util.Arrays;
@@ -120,7 +121,7 @@ public class ApplicationContextHolder implements ApplicationContextAware, Proper
     /**
      * 属性名/对象实例映射表
      */
-    private static final Map<String, Object> PROPERTY_OBJECT_MAPPING = Maps.newConcurrentMap();
+    private static final Map<String, WeakReference<Object>> PROPERTY_OBJECT_MAPPING = Maps.newConcurrentMap();
 
     /**
      * 应用上下文对象
@@ -794,7 +795,7 @@ public class ApplicationContextHolder implements ApplicationContextAware, Proper
      */
     @SuppressWarnings("unchecked")
     public static <T> T getProperty(@NonNull String key, @NonNull Function<String, T> function) {
-        Object object = PROPERTY_OBJECT_MAPPING.get(key);
+        Object object = ObjectUtils.ifNull(PROPERTY_OBJECT_MAPPING.get(key), WeakReference::get);
         if (object == null) {
             object = PROPERTY_OBJECT_MAPPING.computeIfAbsent(key, k -> {
                 Object value = null;
@@ -806,8 +807,8 @@ public class ApplicationContextHolder implements ApplicationContextAware, Proper
                         log.error("Get property value failed: {}", key, e);
                     }
                 }
-                return ObjectUtils.ifNull(value, ObjectUtils.EMPTY);
-            });
+                return new WeakReference<>(ObjectUtils.ifNull(value, ObjectUtils.EMPTY));
+            }).get();
         }
         return object == ObjectUtils.EMPTY ? null : (T) object;
     }

+ 1 - 1
framework-common/src/main/java/com/chelvc/framework/common/model/Pool.java

@@ -56,7 +56,7 @@ public class Pool<T> {
     static {
         try {
             Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
-            UNSAFE = (Unsafe) ObjectUtils.getValue(sun.misc.Unsafe.class, field);
+            UNSAFE = (Unsafe) ObjectUtils.getObjectValue(sun.misc.Unsafe.class, field);
             MARK = UNSAFE.objectFieldOffset(Node.class.getDeclaredField("mark"));
         } catch (Exception e) {
             throw new Error(e);

+ 2 - 2
framework-common/src/main/java/com/chelvc/framework/common/util/JacksonUtils.java

@@ -1231,7 +1231,7 @@ public final class JacksonUtils {
         }
         T instance = ObjectUtils.instance(type);
         if (ObjectUtils.notEmpty(map)) {
-            Map<String, Field> fields = ObjectUtils.getAllFields(type);
+            Map<String, Field> fields = ObjectUtils.getClassFields(type);
             if (ObjectUtils.notEmpty(fields)) {
                 for (Map.Entry<String, ?> entry : map.entrySet()) {
                     Field field = fields.get(entry.getKey());
@@ -1244,7 +1244,7 @@ public final class JacksonUtils {
                                 && !ObjectUtils.isSameClass(field.getType(), value.getClass()))) {
                             value = deserialize(mapper, value.toString(), field.getGenericType());
                         }
-                        ObjectUtils.setValue(instance, field, function.apply(field, value));
+                        ObjectUtils.setObjectValue(instance, field, function.apply(field, value));
                     }
                 }
             }

+ 86 - 96
framework-common/src/main/java/com/chelvc/framework/common/util/ObjectUtils.java

@@ -6,6 +6,7 @@ import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.io.Serializable;
 import java.lang.invoke.SerializedLambda;
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
@@ -71,22 +72,24 @@ public final class ObjectUtils {
     /**
      * 对象字段映射表
      */
-    private static final Map<Class<?>, Map<String, Field>> CLASS_FIELD_MAPPING = Maps.newConcurrentMap();
+    private static final Map<Class<?>, WeakReference<Map<String, Field>>> CLASS_FIELD_MAPPING = Maps.newConcurrentMap();
 
     /**
      * Protostuff对象类型/Schema映射表
      */
-    private static final Map<Class<?>, Schema<?>> PROTOSTUFF_SCHEMA_MAPPING = Maps.newConcurrentMap();
+    private static final Map<Class<?>, WeakReference<Schema<?>>> PROTOSTUFF_SCHEMA_MAPPING = Maps.newConcurrentMap();
 
     /**
      * SerializedLambda 反序列化缓存
      */
-    private static final Map<Class<?>, SerializedLambda> LAMBDA_FUNCTION_MAPPING = Maps.newConcurrentMap();
+    private static final Map<Class<?>, WeakReference<SerializedLambda>> LAMBDA_FUNCTION_MAPPING =
+            Maps.newConcurrentMap();
 
     /**
      * 类对象/属性描述映射表
      */
-    private static final Map<Class<?>, List<PropertyDescriptor>> PROPERTY_DESCRIPTOR_MAPPING = Maps.newConcurrentMap();
+    private static final Map<Class<?>, WeakReference<List<PropertyDescriptor>>> PROPERTY_DESCRIPTOR_MAPPING =
+            Maps.newConcurrentMap();
 
     static {
         // 注册简单的对象拷贝转换器
@@ -440,99 +443,95 @@ public final class ObjectUtils {
     }
 
     /**
-     * 查找类对象字段
+     * 获取对象字段
      *
-     * @param clazz 对象
-     * @param consumer 字段回调函数
+     * @param clazz 对象
+     * @return 字段名称/实例映射表
      */
-    public static void lookupClassFields(@NonNull Class<?> clazz, @NonNull Consumer<Field> consumer) {
-        filterClassFields(clazz, field -> {
-            consumer.accept(field);
-            return false;
-        });
+    public static Map<String, Field> getClassFields(@NonNull Class<?> clazz) {
+        Map<String, Field> fields = ObjectUtils.ifNull(CLASS_FIELD_MAPPING.get(clazz), WeakReference::get);
+        return fields != null ? fields : CLASS_FIELD_MAPPING.computeIfAbsent(
+                clazz, k -> new WeakReference<>(findClassFields(clazz))
+        ).get();
     }
 
     /**
-     * 过滤类对象字段
+     * 查找对象字段
      *
-     * @param clazz    类对象
-     * @param function 字段回调函数
-     * @return true/false
+     * @param clazz 对象
+     * @return 字段名称/实例映射表
      */
-    public static boolean filterClassFields(@NonNull Class<?> clazz, @NonNull Function<Field, Boolean> function) {
-        if (!Modifier.isInterface(clazz.getModifiers())) {
-            do {
-                Field[] fields = clazz.getDeclaredFields();
-                if (notEmpty(fields)) {
-                    boolean enumerable = Enum.class.isAssignableFrom(clazz);
-                    for (Field field : fields) {
-                        if (!field.isSynthetic() && ((enumerable && field.isEnumConstant())
-                                || (!enumerable && !Modifier.isStatic(field.getModifiers())))) {
-                            field.setAccessible(true);
-                            if (Boolean.TRUE.equals(function.apply(field))) {
-                                return true;
-                            }
-                        }
-                    }
-                }
-            } while ((clazz = clazz.getSuperclass()) != null && clazz != Enum.class && clazz != Object.class);
-        }
-        return false;
+    public static Map<String, Field> findClassFields(@NonNull Class<?> clazz) {
+        Map<String, Field> fields = Maps.newHashMap();
+        findClassField(clazz, field -> {
+            fields.put(field.getName(), field);
+            return false;
+        });
+        return fields.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(fields);
     }
 
     /**
      * 获取对象字段
      *
-     * @param clazz 目标对象
+     * @param clazz 对象
      * @param name  字段名称
      * @return 字段实例
      */
-    public static Field getField(@NonNull Class<?> clazz, @NonNull String name) {
-        Field field = findField(clazz, name);
-        return AssertUtils.nonnull(field, () -> "No such field: " + clazz.getName() + "." + name);
+    public static Field getClassField(@NonNull Class<?> clazz, @NonNull String name) {
+        Field field = findClassField(clazz, name);
+        AssertUtils.check(Objects.nonNull(field), () -> "No such field: " + clazz.getName() + "." + name);
+        return field;
     }
 
     /**
      * 查找对象字段
      *
-     * @param clazz 目标对象
+     * @param clazz 对象
      * @param name  字段名称
      * @return 字段实例
      */
-    public static Field findField(@NonNull Class<?> clazz, @NonNull String name) {
-        return ifNull(getAllFields(clazz), fields -> fields.get(name));
+    public static Field findClassField(@NonNull Class<?> clazz, @NonNull String name) {
+        return findClassField(clazz, field -> Objects.equals(field.getName(), name));
     }
 
     /**
-     * 获取对象所有字段
+     * 查找对象字段
      *
-     * @param clazz 目标对象
-     * @return 字段名称/实例映射表
+     * @param clazz    对象
+     * @param function 字段回调函数
+     * @return 字段实例
      */
-    public static Map<String, Field> getAllFields(@NonNull Class<?> clazz) {
-        Map<String, Field> cache = CLASS_FIELD_MAPPING.get(clazz);
-        return cache != null ? cache : CLASS_FIELD_MAPPING.computeIfAbsent(clazz, k -> {
-            // 接口对象类型
-            if (Modifier.isInterface(k.getModifiers())) {
-                return Collections.emptyMap();
-            }
-
-            // 普通对象类型
-            Map<String, Field> all = Maps.newHashMap();
-            boolean enumerable = Enum.class.isAssignableFrom(k);
+    public static Field findClassField(@NonNull Class<?> clazz, @NonNull Function<Field, Boolean> function) {
+        if (!Modifier.isInterface(clazz.getModifiers())) {
             do {
-                Field[] fields = k.getDeclaredFields();
+                Field[] fields = clazz.getDeclaredFields();
                 if (notEmpty(fields)) {
+                    boolean enumerable = Enum.class.isAssignableFrom(clazz);
                     for (Field field : fields) {
                         if (!field.isSynthetic() && ((enumerable && field.isEnumConstant())
                                 || (!enumerable && !Modifier.isStatic(field.getModifiers())))) {
                             field.setAccessible(true);
-                            all.put(field.getName(), field);
+                            if (Boolean.TRUE.equals(function.apply(field))) {
+                                return field;
+                            }
                         }
                     }
                 }
-            } while ((k = k.getSuperclass()) != null && k != Enum.class && k != Object.class);
-            return all.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(Maps.newHashMap(all));
+            } while ((clazz = clazz.getSuperclass()) != null && clazz != Enum.class && clazz != Object.class);
+        }
+        return null;
+    }
+
+    /**
+     * 查找对象字段
+     *
+     * @param clazz    对象
+     * @param consumer 字段回调函数
+     */
+    public static void foreachClassFields(@NonNull Class<?> clazz, @NonNull Consumer<Field> consumer) {
+        findClassField(clazz, field -> {
+            consumer.accept(field);
+            return false;
         });
     }
 
@@ -543,7 +542,7 @@ public final class ObjectUtils {
      * @param field  字段对象
      * @return 字段值
      */
-    public static Object getValue(Object object, @NonNull Field field) {
+    public static Object getObjectValue(Object object, @NonNull Field field) {
         if (object == null) {
             return null;
         } else if (!field.isAccessible()) {
@@ -563,20 +562,8 @@ public final class ObjectUtils {
      * @param property 属性名
      * @return 属性值
      */
-    public static Object getValue(Object object, @NonNull String property) {
-        return object == null ? null : getValue(object, getField(object.getClass(), property));
-    }
-
-    /**
-     * 批量设置对象字段值
-     *
-     * @param object 对象实例
-     * @param values 属性名/值映射表
-     */
-    public static void setValue(Object object, @NonNull Map<String, ?> values) {
-        if (object != null && notEmpty(values)) {
-            values.forEach((key, value) -> setValue(object, key, value));
-        }
+    public static Object getObjectValue(Object object, @NonNull String property) {
+        return object == null ? null : getObjectValue(object, getClassField(object.getClass(), property));
     }
 
     /**
@@ -586,7 +573,7 @@ public final class ObjectUtils {
      * @param field  属性字段对象
      * @param value  字段值
      */
-    public static void setValue(Object object, @NonNull Field field, Object value) {
+    public static void setObjectValue(Object object, @NonNull Field field, Object value) {
         if (object == null) {
             return;
         } else if (!field.isAccessible()) {
@@ -606,9 +593,9 @@ public final class ObjectUtils {
      * @param property 属性名
      * @param value    属性值
      */
-    public static void setValue(Object object, @NonNull String property, Object value) {
+    public static void setObjectValue(Object object, @NonNull String property, Object value) {
         if (object != null) {
-            setValue(object, getField(object.getClass(), property), value);
+            setObjectValue(object, getClassField(object.getClass(), property), value);
         }
     }
 
@@ -638,12 +625,12 @@ public final class ObjectUtils {
         if (object == null) {
             return null;
         }
-        Map<String, Field> fields = getAllFields(object.getClass());
+        Map<String, Field> fields = getClassFields(object.getClass());
         if (isEmpty(fields)) {
             return Collections.emptyMap();
         }
         Map<String, Object> map = Maps.newHashMapWithExpectedSize(fields.size());
-        fields.forEach((name, field) -> map.put(name, getValue(object, field)));
+        fields.forEach((name, field) -> map.put(name, getObjectValue(object, field)));
         return map;
     }
 
@@ -658,18 +645,18 @@ public final class ObjectUtils {
         if (object == null) {
             return null;
         }
-        Map<String, Field> targets = getAllFields(type);
+        Map<String, Field> targets = getClassFields(type);
         if (isEmpty(targets)) {
             return Collections.emptyMap();
         }
-        Map<String, Field> fields = getAllFields(object.getClass());
+        Map<String, Field> fields = getClassFields(object.getClass());
         if (isEmpty(fields)) {
             return Collections.emptyMap();
         }
         Map<String, Object> map = Maps.newHashMapWithExpectedSize(fields.size());
         fields.forEach((name, field) -> {
             if (targets.containsKey(name)) {
-                map.put(name, getValue(object, field));
+                map.put(name, getObjectValue(object, field));
             }
         });
         return map.isEmpty() ? Collections.emptyMap() : map;
@@ -689,12 +676,12 @@ public final class ObjectUtils {
         }
         T instance = instance(type);
         if (notEmpty(map)) {
-            Map<String, Field> fields = getAllFields(type);
+            Map<String, Field> fields = getClassFields(type);
             if (notEmpty(fields)) {
                 map.forEach((name, value) -> {
                     Field field = fields.get(name);
                     if (field != null) {
-                        setValue(instance, field, value);
+                        setObjectValue(instance, field, value);
                     }
                 });
             }
@@ -909,8 +896,10 @@ public final class ObjectUtils {
      */
     @SuppressWarnings("unchecked")
     private static <M, T extends Schema<M>> T getProtostuffSchema(@NonNull Class<M> clazz) {
-        T schema = (T) PROTOSTUFF_SCHEMA_MAPPING.get(clazz);
-        return schema != null ? schema : (T) PROTOSTUFF_SCHEMA_MAPPING.computeIfAbsent(clazz, RuntimeSchema::getSchema);
+        T schema = (T) ObjectUtils.ifNull(PROTOSTUFF_SCHEMA_MAPPING.get(clazz), WeakReference::get);
+        return schema != null ? schema : (T) PROTOSTUFF_SCHEMA_MAPPING.computeIfAbsent(
+                clazz, k -> new WeakReference<>(RuntimeSchema.getSchema(clazz))
+        ).get();
     }
 
     /**
@@ -957,7 +946,8 @@ public final class ObjectUtils {
      * @return 属性描述列表
      */
     public static List<PropertyDescriptor> getPropertyDescriptors(@NonNull Class<?> clazz) {
-        List<PropertyDescriptor> descriptors = PROPERTY_DESCRIPTOR_MAPPING.get(clazz);
+        List<PropertyDescriptor> descriptors =
+                ObjectUtils.ifNull(PROPERTY_DESCRIPTOR_MAPPING.get(clazz), WeakReference::get);
         return descriptors != null ? descriptors : PROPERTY_DESCRIPTOR_MAPPING.computeIfAbsent(clazz, k -> {
             BeanInfo bean;
             try {
@@ -965,8 +955,8 @@ public final class ObjectUtils {
             } catch (IntrospectionException e) {
                 throw new RuntimeException(e);
             }
-            return Arrays.asList(bean.getPropertyDescriptors());
-        });
+            return new WeakReference<>(Arrays.asList(bean.getPropertyDescriptors()));
+        }).get();
     }
 
     /**
@@ -989,16 +979,16 @@ public final class ObjectUtils {
      */
     private static SerializedLambda lookupFunctionLambda(Serializable function) {
         Class<?> clazz = function.getClass();
-        SerializedLambda lambda = LAMBDA_FUNCTION_MAPPING.get(clazz);
+        SerializedLambda lambda = ObjectUtils.ifNull(LAMBDA_FUNCTION_MAPPING.get(clazz), WeakReference::get);
         return lambda != null ? lambda : LAMBDA_FUNCTION_MAPPING.computeIfAbsent(clazz, k -> {
             try {
                 Method method = k.getDeclaredMethod("writeReplace");
                 method.setAccessible(true);
-                return (SerializedLambda) method.invoke(function);
+                return new WeakReference<>((SerializedLambda) method.invoke(function));
             } catch (ReflectiveOperationException e) {
                 throw new RuntimeException(e);
             }
-        });
+        }).get();
     }
 
     /**
@@ -1434,7 +1424,7 @@ public final class ObjectUtils {
         if (object == null || other == null) {
             return Collections.emptyList();
         }
-        Map<String, Field> fields = getAllFields(object.getClass());
+        Map<String, Field> fields = getClassFields(object.getClass());
         if (isEmpty(fields)) {
             return Collections.emptyList();
         }
@@ -1442,8 +1432,8 @@ public final class ObjectUtils {
         Set<String> _excludes = excludes.length == 0 ? Collections.emptySet() : Sets.newHashSet(excludes);
         fields.forEach((name, field) -> {
             if (_excludes.isEmpty() || !_excludes.contains(name)) {
-                Object before = getValue(object, field);
-                Object after = getValue(other, field);
+                Object before = getObjectValue(object, field);
+                Object after = getObjectValue(other, field);
                 if (!equals(before, after)) {
                     modifications.add(Modification.builder().name(name).before(before).after(after).build());
                 }

+ 6 - 3
framework-common/src/main/java/com/chelvc/framework/common/util/StringUtils.java

@@ -1,5 +1,6 @@
 package com.chelvc.framework.common.util;
 
+import java.lang.ref.WeakReference;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Map;
@@ -177,7 +178,7 @@ public final class StringUtils {
     /**
      * 正则表达式/匹配模式对象映射表
      */
-    private static final Map<String, Pattern> REGEX_PATTERN_MAPPING = Maps.newConcurrentMap();
+    private static final Map<String, WeakReference<Pattern>> REGEX_PATTERN_MAPPING = Maps.newConcurrentMap();
 
     private StringUtils() {
     }
@@ -339,8 +340,10 @@ public final class StringUtils {
      * @return 匹配模式对象
      */
     public static Pattern getPattern(@NonNull String regex) {
-        Pattern pattern = REGEX_PATTERN_MAPPING.get(regex);
-        return pattern != null ? pattern : REGEX_PATTERN_MAPPING.computeIfAbsent(regex, Pattern::compile);
+        Pattern pattern = ObjectUtils.ifNull(REGEX_PATTERN_MAPPING.get(regex), WeakReference::get);
+        return pattern != null ? pattern : REGEX_PATTERN_MAPPING.computeIfAbsent(
+                regex, k -> new WeakReference<>(Pattern.compile(regex))
+        ).get();
     }
 
     /**

+ 10 - 10
framework-database/src/main/java/com/chelvc/framework/database/config/TypeHandlerConfigurer.java

@@ -67,8 +67,8 @@ import com.chelvc.framework.database.handler.RegionArrayTypeHandler;
 import com.chelvc.framework.database.handler.RegionSetTypeHandler;
 import com.chelvc.framework.database.handler.RegionsTypeHandler;
 import com.chelvc.framework.database.handler.SensitiveArrayTypeHandler;
-import com.chelvc.framework.database.handler.SensitiveSetTypeHandler;
 import com.chelvc.framework.database.handler.SensitiveListTypeHandler;
+import com.chelvc.framework.database.handler.SensitiveSetTypeHandler;
 import com.chelvc.framework.database.handler.SensitiveTypeHandler;
 import com.chelvc.framework.database.handler.SetTypeHandler;
 import com.chelvc.framework.database.handler.SetsTypeHandler;
@@ -174,7 +174,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
      * @return true/false
      */
     private boolean isTypeHandlerConfigurable(Class<?> clazz) {
-        return !this.isMetaType(clazz) && ObjectUtils.filterClassFields(clazz, field -> {
+        return !this.isMetaType(clazz) && Objects.nonNull(ObjectUtils.findClassField(clazz, field -> {
             TableField annotation = field.getAnnotation(TableField.class);
             if (annotation != null && !annotation.exist()) {
                 return false;
@@ -186,7 +186,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
             // JSON字段
             Type type = TypeParameterResolver.resolveFieldType(field, clazz);
             return !DatabaseContextHolder.isTypeHandlerRegistered(ObjectUtils.type2class(type));
-        });
+        }));
     }
 
     /**
@@ -205,14 +205,14 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
         }
 
         // 绑定并注册字段类型处理器
-        ObjectUtils.setValue(field, "typeHandler", handler);
-        String el = (String) ObjectUtils.getValue(field, "el");
+        ObjectUtils.setObjectValue(field, "typeHandler", handler);
+        String el = (String) ObjectUtils.getObjectValue(field, "el");
         int delimiter = el.indexOf(',');
         if (delimiter > 0) {
             el = el.substring(0, delimiter);
         }
         el = el + ",typeHandler=" + handler.getName();
-        ObjectUtils.setValue(field, "el", el);
+        ObjectUtils.setObjectValue(field, "el", el);
         return true;
     }
 
@@ -458,7 +458,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
         element.setAttribute("type", clazz.getName());
 
         // 添加resultMap字段映射
-        ObjectUtils.lookupClassFields(clazz, field -> initializeResultMapping(
+        ObjectUtils.foreachClassFields(clazz, field -> initializeResultMapping(
                 document, clazz, field, element::appendChild
         ));
         return element;
@@ -529,7 +529,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
                     if ("id".equalsIgnoreCase(child.getName())) {
                         continue;
                     }
-                    Field field = ObjectUtils.findField(clazz, property);
+                    Field field = ObjectUtils.findClassField(clazz, property);
                     if (field == null || field.isAnnotationPresent(TableId.class)) {
                         continue;
                     }
@@ -561,7 +561,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
                 }
 
                 // 补齐缺失字段映射
-                ObjectUtils.lookupClassFields(clazz, field -> {
+                ObjectUtils.foreachClassFields(clazz, field -> {
                     if (!properties.contains(field.getName())) {
                         initializeResultMapping(document, clazz, field, map.getNode()::appendChild);
                     }
@@ -600,7 +600,7 @@ public class TypeHandlerConfigurer extends MybatisConfigurer {
                 bound |= this.bindTypeHandler(table.getEntityType(), field);
             }
             if (bound && !table.isAutoInitResultMap()) {
-                ObjectUtils.setValue(table, "autoInitResultMap", true);
+                ObjectUtils.setObjectValue(table, "autoInitResultMap", true);
             }
         }
     }

+ 9 - 9
framework-database/src/main/java/com/chelvc/framework/database/support/Binlog.java

@@ -98,7 +98,7 @@ public class Binlog implements Serializable {
      * @return 转换后字段值
      */
     public static Object convert(@NonNull Class<?> model, @NonNull String property, Object object) {
-        return object == null ? null : convert(ObjectUtils.getField(model, property), object);
+        return object == null ? null : convert(ObjectUtils.getClassField(model, property), object);
     }
 
     /**
@@ -113,7 +113,7 @@ public class Binlog implements Serializable {
         }
 
         Class<?> model = entity.getClass();
-        Map<String, Field> fields = ObjectUtils.getAllFields(model);
+        Map<String, Field> fields = ObjectUtils.getClassFields(model);
         if (ObjectUtils.isEmpty(fields)) {
             return;
         }
@@ -121,7 +121,7 @@ public class Binlog implements Serializable {
             String column = StringUtils.hump2underscore(entry.getKey());
             Object value = mapping.get(column);
             value = convert(entry.getValue(), value);
-            ObjectUtils.setValue(entity, entry.getValue(), value);
+            ObjectUtils.setObjectValue(entity, entry.getValue(), value);
         }
     }
 
@@ -163,7 +163,7 @@ public class Binlog implements Serializable {
             return false;
         }
 
-        Map<String, Field> fields = ObjectUtils.getAllFields(model);
+        Map<String, Field> fields = ObjectUtils.getClassFields(model);
         if (ObjectUtils.isEmpty(fields)) {
             return false;
         }
@@ -263,12 +263,12 @@ public class Binlog implements Serializable {
             return null;
         }
 
-        Map<String, Field> fields = ObjectUtils.getAllFields(model);
+        Map<String, Field> fields = ObjectUtils.getClassFields(model);
         if (ObjectUtils.isEmpty(fields)) {
             return null;
         }
         T instance = null;
-        Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getAllFields);
+        Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
         for (Map.Entry<String, Field> entry : fields.entrySet()) {
             if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
                 continue;
@@ -280,7 +280,7 @@ public class Binlog implements Serializable {
                 if (instance == null) {
                     instance = ObjectUtils.instance(model);
                 }
-                ObjectUtils.setValue(instance, entry.getValue(), convert(entry.getValue(), a));
+                ObjectUtils.setObjectValue(instance, entry.getValue(), convert(entry.getValue(), a));
             }
         }
         return instance;
@@ -308,12 +308,12 @@ public class Binlog implements Serializable {
             return Collections.emptyMap();
         }
 
-        Map<String, Field> fields = ObjectUtils.getAllFields(model);
+        Map<String, Field> fields = ObjectUtils.getClassFields(model);
         if (ObjectUtils.isEmpty(fields)) {
             return Collections.emptyMap();
         }
         Map<String, Object> different = Maps.newHashMap();
-        Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getAllFields);
+        Map<String, Field> limits = ObjectUtils.ifNull(limit, ObjectUtils::getClassFields);
         for (Map.Entry<String, Field> entry : fields.entrySet()) {
             if (ObjectUtils.notEmpty(limits) && !limits.containsKey(entry.getKey())) {
                 continue;

+ 2 - 2
framework-feign/src/main/java/com/chelvc/framework/feign/encoder/CustomizeEncoder.java

@@ -76,13 +76,13 @@ public class CustomizeEncoder implements Encoder {
         if (object == null) {
             return Collections.emptyMap();
         }
-        Map<String, Field> fields = ObjectUtils.getAllFields(object.getClass());
+        Map<String, Field> fields = ObjectUtils.getClassFields(object.getClass());
         if (ObjectUtils.isEmpty(fields)) {
             return Collections.emptyMap();
         }
         Map<String, Object> values = Maps.newHashMapWithExpectedSize(fields.size());
         fields.forEach((name, field) -> {
-            Object value = ObjectUtils.getValue(object, field);
+            Object value = ObjectUtils.getObjectValue(object, field);
             FormProperty property = field.getAnnotation(FormProperty.class);
             if (property != null && StringUtils.notEmpty(property.value())) {
                 values.put(property.value(), value);

+ 2 - 2
framework-feign/src/main/java/com/chelvc/framework/feign/interceptor/FeignInvokeInterceptor.java

@@ -44,8 +44,8 @@ public class FeignInvokeInterceptor implements RequestInterceptor {
         RequestMappingHandlerMapping handlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
         Map<String, Predicate<Class<?>>> prefixes = handlerMapping.getPathPrefixes();
         this.servers = ObjectUtils.isEmpty(prefixes) ? Collections.emptySet() : prefixes.keySet();
-        Object registry = ObjectUtils.getValue(handlerMapping, "mappingRegistry");
-        Map<?, ?> mappings = (Map<?, ?>) ObjectUtils.getValue(registry, "urlLookup");
+        Object registry = ObjectUtils.getObjectValue(handlerMapping, "mappingRegistry");
+        Map<?, ?> mappings = (Map<?, ?>) ObjectUtils.getObjectValue(registry, "urlLookup");
         this.mappings = ObjectUtils.isEmpty(mappings) ? Collections.emptyMap() : (Map<String, ?>) mappings;
 
         // 初始化请求转发配置

+ 16 - 18
framework-jpush/src/main/java/com/chelvc/framework/jpush/config/JPushConfigurer.java

@@ -34,22 +34,21 @@ public class JPushConfigurer {
     @Bean
     @ConditionalOnMissingBean(JPushClient.class)
     public JPushClient jpushClient() {
-        return new JPushClient(this.properties.getSecret(), this.properties.getAppid()) {
+        String appid = this.properties.getAppid(), secret = this.properties.getSecret();
+        return new JPushClient(secret, appid) {
             {
-                ObjectUtils.setValue(this, "_pushClient",
-                        new PushClient(properties.getSecret(), properties.getAppid()) {
-                            @Override
-                            public CIDResult getCidList(int count, String type) throws APIConnectionException,
-                                    APIRequestException {
-                                // 对批量推送CID排序,确保推送结果顺序与发送数据顺序一致
-                                CIDResult result = super.getCidList(count, type);
-                                if (result != null && ObjectUtils.notEmpty(result.cidlist)) {
-                                    result.cidlist.sort(Comparator.naturalOrder());
-                                }
-                                return result;
-                            }
+                ObjectUtils.setObjectValue(this, "_pushClient", new PushClient(secret, appid) {
+                    @Override
+                    public CIDResult getCidList(int count, String type) throws APIConnectionException,
+                            APIRequestException {
+                        // 对批量推送CID排序,确保推送结果顺序与发送数据顺序一致
+                        CIDResult result = super.getCidList(count, type);
+                        if (result != null && ObjectUtils.notEmpty(result.cidlist)) {
+                            result.cidlist.sort(Comparator.naturalOrder());
                         }
-                );
+                        return result;
+                    }
+                });
             }
         };
     }
@@ -57,11 +56,10 @@ public class JPushConfigurer {
     @Bean
     @ConditionalOnMissingBean(JMessageClient.class)
     public JMessageClient jmessageClient() {
-        JMessageClient client = new JMessageClient(this.properties.getAppid(), this.properties.getSecret());
+        String appid = this.properties.getAppid(), secret = this.properties.getSecret();
+        JMessageClient client = new JMessageClient(appid, secret);
         client.setHttpClient(new ApacheHttpClient(
-                ServiceHelper.getBasicAuthorization(this.properties.getAppid(), this.properties.getSecret()),
-                null,
-                ClientConfig.getInstance()
+                ServiceHelper.getBasicAuthorization(appid, secret), null, ClientConfig.getInstance()
         ));
         return client;
     }

+ 1 - 4
framework-redis/src/main/java/com/chelvc/framework/redis/queue/TemporalUniqueRedisQueue.java

@@ -208,10 +208,7 @@ public class TemporalUniqueRedisQueue<E> extends AbstractQueue<E> {
         List<String> keys = Collections.singletonList(this.name);
         long min = 0, max = System.currentTimeMillis(), score = max + this.idle;
         List<E> values = this.template().execute(POLL_SCRIPT, keys, min, max, score);
-        if (ObjectUtils.isEmpty(values)) {
-            return null;
-        }
-        return values.get(0);
+        return ObjectUtils.isEmpty(values) ? null : values.get(0);
     }
 
     @Override

+ 1 - 1
framework-security/src/main/java/com/chelvc/framework/security/config/AuthorizeConfigurer.java

@@ -143,7 +143,7 @@ public class AuthorizeConfigurer extends WebSecurityConfigurerAdapter {
             Class<?> clazz =
                     Class.forName("org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties");
             ObjectProvider<?> actuator = this.applicationContext.getBeanProvider(clazz);
-            String basePath = (String) ObjectUtils.getValue(actuator.getIfAvailable(), "basePath");
+            String basePath = (String) ObjectUtils.getObjectValue(actuator.getIfAvailable(), "basePath");
             if (StringUtils.notEmpty(basePath)) {
                 ignores.add(HttpUtils.uri(basePath, "/**"));
             }