mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
!547 修复在使用 UpdateChain 更新实体类字段时偶发 ClassCastException 异常问题
Merge pull request !547 from iminifly/main
This commit is contained in:
commit
6f0444a139
@ -18,6 +18,7 @@ package com.mybatisflex.core.update;
|
|||||||
import com.mybatisflex.core.exception.FlexExceptions;
|
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 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.ProxyFactory;
|
||||||
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
import org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
||||||
|
|
||||||
@ -56,10 +57,16 @@ public class ModifyAttrsRecordProxyFactory {
|
|||||||
T proxyObject;
|
T proxyObject;
|
||||||
try {
|
try {
|
||||||
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
||||||
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw FlexExceptions.wrap(e, "请为实体类 %s 添加公开的无参构造器!", target.getCanonicalName());
|
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;
|
return proxyObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,12 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.mybatisflex.core.update;
|
package com.mybatisflex.core.update;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
import com.mybatisflex.core.query.QueryColumn;
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
import com.mybatisflex.core.query.QueryCondition;
|
import com.mybatisflex.core.query.QueryCondition;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
import com.mybatisflex.core.util.LambdaUtil;
|
import com.mybatisflex.core.util.LambdaUtil;
|
||||||
import com.mybatisflex.core.util.UpdateEntity;
|
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 org.apache.ibatis.javassist.util.proxy.ProxyObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -32,7 +35,14 @@ import java.util.Map;
|
|||||||
public interface UpdateWrapper<T> extends PropertySetter<UpdateWrapper<T>>, Serializable {
|
public interface UpdateWrapper<T> extends PropertySetter<UpdateWrapper<T>>, Serializable {
|
||||||
|
|
||||||
default Map<String, Object> getUpdates() {
|
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();
|
return handler.getUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user