mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Merge branch 'main' of https://github.com/mybatis-flex/mybatis-flex
This commit is contained in:
commit
7ce553cc39
@ -133,7 +133,7 @@ public class MybatisFlexBootstrap {
|
|||||||
* @return mapperObject
|
* @return mapperObject
|
||||||
*/
|
*/
|
||||||
public <T> T getMapper(Class<T> mapperClass) {
|
public <T> T getMapper(Class<T> mapperClass) {
|
||||||
return Mappers.ofMapperClass(mapperClass);
|
return Mappers.ofMapperClass(getEnvironmentId(), mapperClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ package com.mybatisflex.core.mybatis;
|
|||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
import com.mybatisflex.core.FlexGlobalConfig;
|
import com.mybatisflex.core.FlexGlobalConfig;
|
||||||
import com.mybatisflex.core.exception.FlexExceptions;
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import org.apache.ibatis.reflection.ExceptionUtil;
|
import org.apache.ibatis.reflection.ExceptionUtil;
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
@ -84,6 +85,13 @@ public class Mappers {
|
|||||||
, new MapperHandler(mapperClass)));
|
, new MapperHandler(mapperClass)));
|
||||||
return (M) mapperObject;
|
return (M) mapperObject;
|
||||||
}
|
}
|
||||||
|
public static <M> M ofMapperClass(String environmentId, Class<M> mapperClass) {
|
||||||
|
Object mapperObject = MapUtil.computeIfAbsent(MAPPER_OBJECTS, mapperClass, clazz ->
|
||||||
|
Proxy.newProxyInstance(mapperClass.getClassLoader()
|
||||||
|
, new Class[]{mapperClass}
|
||||||
|
, new MapperHandler(environmentId, mapperClass)));
|
||||||
|
return (M) mapperObject;
|
||||||
|
}
|
||||||
|
|
||||||
private static class MapperHandler implements InvocationHandler {
|
private static class MapperHandler implements InvocationHandler {
|
||||||
|
|
||||||
@ -92,12 +100,24 @@ public class Mappers {
|
|||||||
private final SqlSessionFactory sqlSessionFactory;
|
private final SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
public MapperHandler(Class<?> mapperClass) {
|
public MapperHandler(Class<?> mapperClass) {
|
||||||
|
this(null, mapperClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapperHandler(String environmentId, Class<?> mapperClass) {
|
||||||
this.mapperClass = mapperClass;
|
this.mapperClass = mapperClass;
|
||||||
this.executorType = FlexGlobalConfig.getDefaultConfig()
|
if(StringUtil.noText(environmentId)) {
|
||||||
.getConfiguration()
|
this.executorType = FlexGlobalConfig.getDefaultConfig()
|
||||||
.getDefaultExecutorType();
|
.getConfiguration()
|
||||||
this.sqlSessionFactory = FlexGlobalConfig.getDefaultConfig()
|
.getDefaultExecutorType();
|
||||||
.getSqlSessionFactory();
|
this.sqlSessionFactory = FlexGlobalConfig.getDefaultConfig()
|
||||||
|
.getSqlSessionFactory();
|
||||||
|
} else {
|
||||||
|
this.executorType = FlexGlobalConfig.getConfig(environmentId)
|
||||||
|
.getConfiguration()
|
||||||
|
.getDefaultExecutorType();
|
||||||
|
this.sqlSessionFactory = FlexGlobalConfig.getConfig(environmentId)
|
||||||
|
.getSqlSessionFactory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlSession openSession() {
|
private SqlSession openSession() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user