mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
refactor: optimize MapperHandler
This commit is contained in:
parent
a6b8eece5c
commit
ce4a935adb
@ -47,6 +47,7 @@ public class Mappers {
|
||||
|
||||
/**
|
||||
* 通过 entity Class 获取 Mapper 对象
|
||||
*
|
||||
* @param entityClass
|
||||
* @param <Entity>
|
||||
* @return mapper 对象
|
||||
@ -75,8 +76,8 @@ public class Mappers {
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class MapperHandler implements InvocationHandler {
|
||||
|
||||
private Class<?> mapperClass;
|
||||
private final SqlSessionFactory sqlSessionFactory = FlexGlobalConfig.getDefaultConfig().getSqlSessionFactory();
|
||||
private final ExecutorType executorType = FlexGlobalConfig.getDefaultConfig().getConfiguration().getDefaultExecutorType();
|
||||
@ -91,9 +92,15 @@ public class Mappers {
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
try (SqlSession sqlSession = openSession()) {
|
||||
Object mapper = sqlSession.getMapper(mapperClass);
|
||||
return method.invoke(mapper, args);
|
||||
if ("getClass".equals(method.getName())) {
|
||||
return mapperClass;
|
||||
} else if ("toString".equals(method.getName())) {
|
||||
return mapperClass.getName();
|
||||
} else {
|
||||
try (SqlSession sqlSession = openSession()) {
|
||||
Object mapper = sqlSession.getMapper(mapperClass);
|
||||
return method.invoke(mapper, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,13 +24,27 @@ import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 类实例创建者创建者
|
||||
* Created by michael on 17/3/21.
|
||||
*
|
||||
* @author michael
|
||||
* @date 17/3/21
|
||||
*/
|
||||
public class ClassUtil {
|
||||
|
||||
private ClassUtil() {
|
||||
}
|
||||
|
||||
private static final String[] OBJECT_METHODS = new String[]{
|
||||
"toString",
|
||||
"getClass",
|
||||
"equals",
|
||||
"hashCode",
|
||||
"wait",
|
||||
"notify",
|
||||
"notifyAll",
|
||||
"clone",
|
||||
"finalize"
|
||||
};
|
||||
|
||||
//proxy frameworks
|
||||
private static final List<String> PROXY_CLASS_NAMES = Arrays.asList("net.sf.cglib.proxy.Factory"
|
||||
// cglib
|
||||
@ -299,4 +313,8 @@ public class ClassUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isObjectMethod(String methodName) {
|
||||
return ArrayUtil.contains(OBJECT_METHODS, methodName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user