optimize: 格式优化。

This commit is contained in:
王帅 2024-10-17 20:40:21 +08:00
parent 462c8cea64
commit f19f7adaa2

View File

@ -15,11 +15,11 @@
*/
package com.mybatisflex.core.update;
import com.mybatisflex.core.exception.FlexExceptions;
import com.mybatisflex.core.util.ClassUtil;
import com.mybatisflex.core.util.MapUtil;
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
import org.apache.ibatis.logging.LogFactory;
import com.mybatisflex.core.util.MapUtil;
import java.util.Arrays;
import java.util.Map;
@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class ModifyAttrsRecordProxyFactory {
protected static final Map<Class<?>, Class<?>> CACHE = new ConcurrentHashMap<>();
private static final ModifyAttrsRecordProxyFactory INSTANCE = new ModifyAttrsRecordProxyFactory();
public static ModifyAttrsRecordProxyFactory getInstance() {
@ -41,30 +42,25 @@ public class ModifyAttrsRecordProxyFactory {
private ModifyAttrsRecordProxyFactory() {
}
@SuppressWarnings("unchecked")
public <T> T get(Class<T> target) {
Class<?> proxyClass = MapUtil.computeIfAbsent(CACHE, target, aClass -> {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(target);
Class<?>[] interfaces = Arrays.copyOf(target.getInterfaces(), target.getInterfaces().length + 1);
interfaces[interfaces.length - 1] = UpdateWrapper.class;
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(target);
factory.setInterfaces(interfaces);
return factory.createClass();
});
T proxyObject = null;
T proxyObject;
try {
// noinspection unchecked
proxyObject = (T) ClassUtil.newInstance(proxyClass);
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
} catch (Exception e) {
LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error("请为实体类添加公开的无参构造器!", e);
throw FlexExceptions.wrap(e, "请为实体类 %s 添加公开的无参构造器!", target.getCanonicalName());
}
return proxyObject;
}
}