mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
optimize: 格式优化。
This commit is contained in:
parent
462c8cea64
commit
f19f7adaa2
@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.mybatisflex.core.update;
|
package com.mybatisflex.core.update;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
import com.mybatisflex.core.util.ClassUtil;
|
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.ProxyFactory;
|
||||||
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
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.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class ModifyAttrsRecordProxyFactory {
|
public class ModifyAttrsRecordProxyFactory {
|
||||||
|
|
||||||
protected static final Map<Class<?>, Class<?>> CACHE = new ConcurrentHashMap<>();
|
protected static final Map<Class<?>, Class<?>> CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static final ModifyAttrsRecordProxyFactory INSTANCE = new ModifyAttrsRecordProxyFactory();
|
private static final ModifyAttrsRecordProxyFactory INSTANCE = new ModifyAttrsRecordProxyFactory();
|
||||||
|
|
||||||
public static ModifyAttrsRecordProxyFactory getInstance() {
|
public static ModifyAttrsRecordProxyFactory getInstance() {
|
||||||
@ -41,30 +42,25 @@ public class ModifyAttrsRecordProxyFactory {
|
|||||||
private ModifyAttrsRecordProxyFactory() {
|
private ModifyAttrsRecordProxyFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T get(Class<T> target) {
|
public <T> T get(Class<T> target) {
|
||||||
Class<?> proxyClass = MapUtil.computeIfAbsent(CACHE, target, aClass -> {
|
Class<?> proxyClass = MapUtil.computeIfAbsent(CACHE, target, aClass -> {
|
||||||
ProxyFactory factory = new ProxyFactory();
|
|
||||||
factory.setSuperclass(target);
|
|
||||||
|
|
||||||
Class<?>[] interfaces = Arrays.copyOf(target.getInterfaces(), target.getInterfaces().length + 1);
|
Class<?>[] interfaces = Arrays.copyOf(target.getInterfaces(), target.getInterfaces().length + 1);
|
||||||
interfaces[interfaces.length - 1] = UpdateWrapper.class;
|
interfaces[interfaces.length - 1] = UpdateWrapper.class;
|
||||||
|
ProxyFactory factory = new ProxyFactory();
|
||||||
|
factory.setSuperclass(target);
|
||||||
factory.setInterfaces(interfaces);
|
factory.setInterfaces(interfaces);
|
||||||
|
|
||||||
return factory.createClass();
|
return factory.createClass();
|
||||||
});
|
});
|
||||||
|
|
||||||
T proxyObject = null;
|
T proxyObject;
|
||||||
try {
|
try {
|
||||||
// noinspection unchecked
|
|
||||||
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
||||||
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error("请为实体类添加公开的无参构造器!", e);
|
throw FlexExceptions.wrap(e, "请为实体类 %s 添加公开的无参构造器!", target.getCanonicalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return proxyObject;
|
return proxyObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user