|
@@ -17,20 +17,17 @@ package com.baomidou.mybatisplus.core.toolkit;
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
import com.baomidou.mybatisplus.annotation.IdType;
|
|
|
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
|
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
|
|
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
|
|
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
-import org.apache.ibatis.logging.Log;
|
|
|
-import org.apache.ibatis.logging.LogFactory;
|
|
|
import org.apache.ibatis.session.Configuration;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* Mybatis全局缓存工具类
|
|
@@ -39,15 +36,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
* @since 2017-06-15
|
|
|
*/
|
|
|
public class GlobalConfigUtils {
|
|
|
- /**
|
|
|
- * 日志
|
|
|
- */
|
|
|
- private static final Log logger = LogFactory.getLog(GlobalConfigUtils.class);
|
|
|
-
|
|
|
- /**
|
|
|
- * 缓存全局信息
|
|
|
- */
|
|
|
- private static final Map<String, GlobalConfig> GLOBAL_CONFIG = new ConcurrentHashMap<>();
|
|
|
|
|
|
/**
|
|
|
* 获取当前的SqlSessionFactory
|
|
@@ -57,9 +45,7 @@ public class GlobalConfigUtils {
|
|
|
public static SqlSessionFactory currentSessionFactory(Class<?> clazz) {
|
|
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
|
|
Assert.notNull(tableInfo, ClassUtils.getUserClass(clazz).getName() + " Not Found TableInfoCache.");
|
|
|
- String configMark = tableInfo.getConfigMark();
|
|
|
- GlobalConfig mybatisGlobalConfig = getGlobalConfig(configMark);
|
|
|
- return mybatisGlobalConfig.getSqlSessionFactory();
|
|
|
+ return tableInfo.getConfiguration().getGlobalConfig().getSqlSessionFactory();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -70,19 +56,6 @@ public class GlobalConfigUtils {
|
|
|
return new GlobalConfig().setDbConfig(new GlobalConfig.DbConfig());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置全局设置(以configuration地址值作为Key)
|
|
|
- *
|
|
|
- * @param configuration Mybatis 容器配置对象
|
|
|
- * @param mybatisGlobalConfig 全局配置
|
|
|
- */
|
|
|
- public static void setGlobalConfig(Configuration configuration, GlobalConfig mybatisGlobalConfig) {
|
|
|
- Assert.isTrue(configuration != null && mybatisGlobalConfig != null,
|
|
|
- "Error: Could not setGlobalConfig !");
|
|
|
- // 设置全局设置
|
|
|
- GLOBAL_CONFIG.put(configuration.toString(), mybatisGlobalConfig);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取MybatisGlobalConfig (统一所有入口)
|
|
|
*
|
|
@@ -90,24 +63,7 @@ public class GlobalConfigUtils {
|
|
|
*/
|
|
|
public static GlobalConfig getGlobalConfig(Configuration configuration) {
|
|
|
Assert.notNull(configuration, "Error: You need Initialize MybatisConfiguration !");
|
|
|
- return getGlobalConfig(configuration.toString());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取MybatisGlobalConfig (统一所有入口)
|
|
|
- *
|
|
|
- * @param configMark 配置标记
|
|
|
- */
|
|
|
- public static GlobalConfig getGlobalConfig(String configMark) {
|
|
|
- GlobalConfig cache = GLOBAL_CONFIG.get(configMark);
|
|
|
- if (cache == null) {
|
|
|
- // 没有获取全局配置初始全局配置
|
|
|
- logger.debug("DeBug: MyBatis Plus Global configuration Initializing !");
|
|
|
- GlobalConfig globalConfig = defaults();
|
|
|
- GLOBAL_CONFIG.put(configMark, globalConfig);
|
|
|
- return globalConfig;
|
|
|
- }
|
|
|
- return cache;
|
|
|
+ return ((MybatisConfiguration) configuration).getGlobalConfig();
|
|
|
}
|
|
|
|
|
|
public static DbType getDbType(Configuration configuration) {
|