Răsfoiți Sursa

代码优化

woody 9 luni în urmă
părinte
comite
4082f43a7f

+ 0 - 42
framework-common/src/main/java/com/chelvc/framework/common/model/Copier.java

@@ -1,42 +0,0 @@
-package com.chelvc.framework.common.model;
-
-import com.chelvc.framework.common.util.ObjectUtils;
-
-/**
- * 属性复制接口
- *
- * @author Woody
- * @date 2024/1/30
- */
-public interface Copier {
-    /**
-     * 将当前对象属性值复制到目标对象实例
-     *
-     * @param target 目标对象实例
-     * @param <T>    目标对象类型
-     */
-    default <T> void to(T target) {
-        ObjectUtils.copying(this, target);
-    }
-
-    /**
-     * 将当前对象属性值复制到目标对象
-     *
-     * @param target 目标对象
-     * @param <T>    目标对象类型
-     * @return 目标对象实例
-     */
-    default <T> T to(Class<T> target) {
-        return ObjectUtils.copying(this, target);
-    }
-
-    /**
-     * 将对象属性值复制到当前对象
-     *
-     * @param object 被复制对象实例
-     * @param <T>    被复制对象类型
-     */
-    default <T> void of(T object) {
-        ObjectUtils.copying(object, this);
-    }
-}

+ 19 - 3
framework-common/src/main/java/com/chelvc/framework/common/util/ObjectUtils.java

@@ -619,6 +619,18 @@ public final class ObjectUtils {
         return MAPPER_FACTORY;
     }
 
+    /**
+     * 对象属性复制
+     *
+     * @param source 源对象实例
+     * @param <T>    源对象类型
+     * @return 目标对象实例
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T copying(T source) {
+        return source == null ? null : (T) copying(source, source.getClass());
+    }
+
     /**
      * 对象属性复制
      *
@@ -626,9 +638,13 @@ public final class ObjectUtils {
      * @param target 目标对象实例
      * @param <T>    源对象类型
      * @param <R>    目标对象类型
+     * @return 目标对象实例
      */
-    public static <T, R> void copying(T source, R target) {
-        getCopierBuilder().getMapperFacade().map(source, target);
+    public static <T, R> R copying(T source, R target) {
+        if (source != null && target != null) {
+            getCopierBuilder().getMapperFacade().map(source, target);
+        }
+        return target;
     }
 
     /**
@@ -640,7 +656,7 @@ public final class ObjectUtils {
      * @param <R>    目标对象类型
      * @return 目标对象实例
      */
-    public static <T, R> R copying(T source, Class<R> target) {
+    public static <T, R> R copying(T source, @NonNull Class<R> target) {
         return getCopierBuilder().getMapperFacade().map(source, target);
     }
 

+ 19 - 1
framework-database/src/main/java/com/chelvc/framework/database/interceptor/DynamicInvokeInterceptor.java

@@ -1,6 +1,8 @@
 package com.chelvc.framework.database.interceptor;
 
 import java.sql.Connection;
+import java.time.temporal.Temporal;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -340,6 +342,18 @@ public class DynamicInvokeInterceptor implements Interceptor {
                         Consumer<Expression> changing);
     }
 
+    /**
+     * 判断是否是元类型参数
+     *
+     * @param parameter 参数
+     * @return true/false
+     */
+    private boolean isMetaParameter(Object parameter) {
+        return parameter == null || parameter instanceof Enum || parameter instanceof Number
+                || parameter instanceof String || parameter instanceof Boolean || parameter instanceof Character
+                || parameter instanceof Date || parameter instanceof Temporal;
+    }
+
     /**
      * 获取参数值
      *
@@ -348,6 +362,10 @@ public class DynamicInvokeInterceptor implements Interceptor {
      * @return 参数值
      */
     private Object getParameterValue(BoundSql bound, JdbcParameter parameter) {
+        Object object = bound.getParameterObject();
+        if (this.isMetaParameter(object)) {
+            return object;
+        }
         List<ParameterMapping> mappings = bound.getParameterMappings();
         if (ObjectUtils.isEmpty(mappings)) {
             return null;
@@ -356,7 +374,7 @@ public class DynamicInvokeInterceptor implements Interceptor {
         if (bound.hasAdditionalParameter(property)) {
             return bound.getAdditionalParameter(property);
         }
-        return SystemMetaObject.forObject(bound.getParameterObject()).getValue(property);
+        return SystemMetaObject.forObject(object).getValue(property);
     }
 
     /**

+ 0 - 312
framework-database/src/main/java/com/chelvc/framework/database/support/Updates.java

@@ -244,156 +244,6 @@ public final class Updates {
         return update.divide(getters);
     }
 
-    /**
-     * 是否相同
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> eq(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.eq(columns);
-    }
-
-    /**
-     * 是否相同
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> eq(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.eq(getters);
-    }
-
-    /**
-     * 是否不同
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> ne(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.ne(columns);
-    }
-
-    /**
-     * 是否不同
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> ne(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.ne(getters);
-    }
-
-    /**
-     * 是否小于
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> lt(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.lt(columns);
-    }
-
-    /**
-     * 是否小于
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> lt(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.lt(getters);
-    }
-
-    /**
-     * 是否大于或等于
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> le(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.le(columns);
-    }
-
-    /**
-     * 是否大于或等于
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> le(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.le(getters);
-    }
-
-    /**
-     * 是否大于
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> gt(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.gt(columns);
-    }
-
-    /**
-     * 是否大于
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> gt(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.gt(getters);
-    }
-
-    /**
-     * 是否大于或等于
-     *
-     * @param columns 列名数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    public static <T> Update<T> ge(@NonNull String... columns) {
-        Update<T> update = update();
-        return update.ge(columns);
-    }
-
-    /**
-     * 是否大于或等于
-     *
-     * @param getters Getter方法数组
-     * @param <T>     数据类型
-     * @return 字段更新对象实例
-     */
-    @SafeVarargs
-    public static <T> Update<T> ge(@NonNull SFunction<T, ?>... getters) {
-        Update<T> update = update();
-        return update.ge(getters);
-    }
-
     /**
      * 设置更新表达式
      *
@@ -577,168 +427,6 @@ public final class Updates {
             return this;
         }
 
-        /**
-         * 是否相同
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> eq(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " = VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否相同
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> eq(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.eq(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
-        /**
-         * 是否不同
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> ne(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " != VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否不同
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> ne(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.ne(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
-        /**
-         * 是否小于
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> lt(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " < VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否小于
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> lt(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.lt(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于或等于
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> le(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " <= VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于或等于
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> le(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.le(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> gt(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " > VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> gt(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.gt(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于或等于
-         *
-         * @param columns 列名数组
-         * @return 字段更新对象实例
-         */
-        public final Update<T> ge(@NonNull String... columns) {
-            for (String column : columns) {
-                this.set(column, column + " >= VALUES(" + column + ")");
-            }
-            return this;
-        }
-
-        /**
-         * 是否大于或等于
-         *
-         * @param getters Getter方法数组
-         * @return 字段更新对象实例
-         */
-        @SafeVarargs
-        public final Update<T> ge(@NonNull SFunction<T, ?>... getters) {
-            for (SFunction<T, ?> getter : getters) {
-                this.ge(DatabaseContextHolder.getter2column(getter));
-            }
-            return this;
-        }
-
         /**
          * 设置更新表达式
          *