mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed: UpdateChain.toSQL() error if entity has no default constructor.
This commit is contained in:
parent
e2b347a28c
commit
90a38bff7b
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.mybatisflex.core.update;
|
||||
|
||||
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;
|
||||
@ -22,6 +23,9 @@ import org.apache.ibatis.logging.LogFactory;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* @author michael
|
||||
*/
|
||||
public class ModifyAttrsRecordProxyFactory {
|
||||
|
||||
private static final ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory();
|
||||
@ -41,14 +45,13 @@ public class ModifyAttrsRecordProxyFactory {
|
||||
interfaces[interfaces.length - 1] = UpdateWrapper.class;
|
||||
factory.setInterfaces(interfaces);
|
||||
|
||||
|
||||
final Class<?> proxyClass = factory.createClass();
|
||||
|
||||
T proxyObject = null;
|
||||
try {
|
||||
proxyObject = (T) proxyClass.newInstance();
|
||||
proxyObject = (T) ClassUtil.newInstance(proxyClass);
|
||||
((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e){
|
||||
LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error(e.toString(), e);
|
||||
}
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ public class ClassUtil {
|
||||
|
||||
Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
|
||||
for (Constructor<?> constructor : declaredConstructors) {
|
||||
if (constructor.getParameterCount() == 0) {
|
||||
if (constructor.getParameterCount() == 0 && Modifier.isPublic(constructor.getModifiers())) {
|
||||
defaultConstructor = constructor;
|
||||
} else if (Modifier.isPublic(constructor.getModifiers())) {
|
||||
otherConstructor = constructor;
|
||||
|
||||
@ -2,6 +2,7 @@ package com.mybatisflex.test;
|
||||
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.mybatis.FlexConfiguration;
|
||||
import com.mybatisflex.core.table.TableManager;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.mapper.ArticleMapper;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@ -12,16 +13,25 @@ public class MainSqlTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Environment environment = new Environment("test", new JdbcTransactionFactory(), new HikariDataSource());
|
||||
|
||||
FlexConfiguration configuration = new FlexConfiguration(environment);
|
||||
|
||||
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
|
||||
|
||||
Environment environment = new Environment("test", new JdbcTransactionFactory(), new HikariDataSource());
|
||||
FlexConfiguration configuration = new FlexConfiguration(environment);
|
||||
globalConfig.setConfiguration(configuration);
|
||||
FlexGlobalConfig.setConfig("test", globalConfig, true);
|
||||
|
||||
|
||||
configuration.addMapper(ArticleMapper.class);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ArticleMapper mapper = (ArticleMapper) Proxy.newProxyInstance(MainSqlTest.class.getClassLoader(),
|
||||
// new Class[]{ArticleMapper.class}, new InvocationHandler() {
|
||||
// @Override
|
||||
@ -38,6 +48,9 @@ public class MainSqlTest {
|
||||
// System.out.println(sql1);
|
||||
|
||||
|
||||
TableManager.setHintTableMapping("tb_article","tb_article1");
|
||||
|
||||
|
||||
String sql2 = UpdateChain.of(Article.class)
|
||||
.set("xxxx", "xxxx")
|
||||
.where(Article::getId).ge(100)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user