mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 08:38:26 +08:00
修复在使用 UpdateChain 更新实体类字段时偶发 ClassCastException 异常问题
This commit is contained in:
parent
0baa61fe03
commit
15e93168b6
@ -18,6 +18,7 @@ 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.Proxy;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
||||
|
||||
@ -56,10 +57,16 @@ public class ModifyAttrsRecordProxyFactory {
|
||||
T proxyObject;
|
||||
try {
|
||||
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
||||
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
||||
} catch (Exception e) {
|
||||
throw FlexExceptions.wrap(e, "请为实体类 %s 添加公开的无参构造器!", target.getCanonicalName());
|
||||
}
|
||||
if (proxyObject instanceof ProxyObject) {
|
||||
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
||||
} else if (proxyObject instanceof Proxy) {
|
||||
((Proxy) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
||||
} else {
|
||||
throw FlexExceptions.wrap("为实体类 %s 设置字段更新处理器时出错,获取的实体类代理对象既不是 ProxyObject 的实例,也不是 Proxy 的实例", target.getCanonicalName());
|
||||
}
|
||||
return proxyObject;
|
||||
}
|
||||
|
||||
|
||||
@ -15,12 +15,15 @@
|
||||
*/
|
||||
package com.mybatisflex.core.update;
|
||||
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
import com.mybatisflex.core.util.UpdateEntity;
|
||||
import org.apache.ibatis.javassist.util.proxy.Proxy;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
|
||||
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -32,7 +35,14 @@ import java.util.Map;
|
||||
public interface UpdateWrapper<T> extends PropertySetter<UpdateWrapper<T>>, Serializable {
|
||||
|
||||
default Map<String, Object> getUpdates() {
|
||||
ModifyAttrsRecordHandler handler = (ModifyAttrsRecordHandler) ((ProxyObject) this).getHandler();
|
||||
ModifyAttrsRecordHandler handler = null;
|
||||
if (this instanceof ProxyObject) {
|
||||
handler = (ModifyAttrsRecordHandler) ((ProxyObject) this).getHandler();
|
||||
} else if (this instanceof Proxy) {
|
||||
handler = (ModifyAttrsRecordHandler) ProxyFactory.getHandler((Proxy) this);
|
||||
} else {
|
||||
throw FlexExceptions.wrap("获取实体类代理对象 %s 的字段更新处理器时出错,该对象既不是 ProxyObject 的实例,也不是 Proxy 的实例", this.getClass().getName());
|
||||
}
|
||||
return handler.getUpdates();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user