mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
refactor: optimize ModifyAttrsRecordProxyFactory.java
This commit is contained in:
parent
6d50a6228b
commit
b76db561f1
@ -25,7 +25,9 @@ import java.util.Map;
|
||||
|
||||
class ModifyAttrsRecordHandler implements MethodHandler {
|
||||
|
||||
//更新内容
|
||||
/**
|
||||
* 更新的字段和内容
|
||||
*/
|
||||
private final Map<String, Object> updates = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, Object> getUpdates() {
|
||||
|
||||
@ -19,8 +19,11 @@ import com.mybatisflex.core.util.ClassUtil;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.apache.ibatis.util.MapUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
/**
|
||||
@ -28,16 +31,18 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class ModifyAttrsRecordProxyFactory {
|
||||
|
||||
private static final ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory();
|
||||
protected static final Map<Class<?>, Class<?>> CACHE = new ConcurrentHashMap<>();
|
||||
private static final ModifyAttrsRecordProxyFactory INSTANCE = new ModifyAttrsRecordProxyFactory();
|
||||
|
||||
public static ModifyAttrsRecordProxyFactory getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ModifyAttrsRecordProxyFactory() {
|
||||
}
|
||||
|
||||
public <T> T get(Class<T> target) {
|
||||
Class<?> proxyClass = MapUtil.computeIfAbsent(CACHE, target, aClass -> {
|
||||
ProxyFactory factory = new ProxyFactory();
|
||||
factory.setSuperclass(target);
|
||||
|
||||
@ -45,7 +50,8 @@ public class ModifyAttrsRecordProxyFactory {
|
||||
interfaces[interfaces.length - 1] = UpdateWrapper.class;
|
||||
factory.setInterfaces(interfaces);
|
||||
|
||||
final Class<?> proxyClass = factory.createClass();
|
||||
return factory.createClass();
|
||||
});
|
||||
|
||||
T proxyObject = null;
|
||||
try {
|
||||
@ -57,8 +63,6 @@ public class ModifyAttrsRecordProxyFactory {
|
||||
|
||||
return proxyObject;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -141,7 +141,7 @@ public class ClassUtil {
|
||||
// 没有任何构造函数的情况下,去查找 static 工厂方法,满足 lombok 注解的需求
|
||||
else {
|
||||
Method factoryMethod = ClassUtil.getFirstMethod(clazz, m -> m.getParameterCount() == 0
|
||||
&& clazz.isAssignableFrom(m.getReturnType())
|
||||
&& clazz == m.getReturnType()
|
||||
&& Modifier.isPublic(m.getModifiers())
|
||||
&& Modifier.isStatic(m.getModifiers()));
|
||||
if (factoryMethod != null) {
|
||||
|
||||
@ -53,7 +53,7 @@ public class MainSqlTest {
|
||||
|
||||
String sql2 = UpdateChain.of(Article.class)
|
||||
.set("xxxx", "xxxx")
|
||||
// .where(Article::getId).ge(100)
|
||||
.where(Article::getId).ge(100)
|
||||
.toSQL();
|
||||
|
||||
System.out.println(sql2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user