mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
commit
426d2352e9
@ -173,7 +173,7 @@ public class FlexGlobalConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNormalValueOfLogicDelete(Object normalValueOfLogicDelete) {
|
public void setNormalValueOfLogicDelete(Object normalValueOfLogicDelete) {
|
||||||
if (normalValueOfLogicDelete == null){
|
if (normalValueOfLogicDelete == null) {
|
||||||
throw new NullPointerException("normalValueOfLogicDelete can not be null.");
|
throw new NullPointerException("normalValueOfLogicDelete can not be null.");
|
||||||
}
|
}
|
||||||
this.normalValueOfLogicDelete = normalValueOfLogicDelete;
|
this.normalValueOfLogicDelete = normalValueOfLogicDelete;
|
||||||
@ -184,7 +184,7 @@ public class FlexGlobalConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDeletedValueOfLogicDelete(Object deletedValueOfLogicDelete) {
|
public void setDeletedValueOfLogicDelete(Object deletedValueOfLogicDelete) {
|
||||||
if (deletedValueOfLogicDelete == null){
|
if (deletedValueOfLogicDelete == null) {
|
||||||
throw new NullPointerException("deletedValueOfLogicDelete can not be null.");
|
throw new NullPointerException("deletedValueOfLogicDelete can not be null.");
|
||||||
}
|
}
|
||||||
this.deletedValueOfLogicDelete = deletedValueOfLogicDelete;
|
this.deletedValueOfLogicDelete = deletedValueOfLogicDelete;
|
||||||
@ -241,6 +241,30 @@ public class FlexGlobalConfig {
|
|||||||
return defaultConfig;
|
return defaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定默认全局配置(允许手动。在多源时,方便由注解指定默认源)
|
||||||
|
*
|
||||||
|
* <code><pre>
|
||||||
|
* @Configuration
|
||||||
|
* public class Config{
|
||||||
|
* @Bean(value = "db1", typed = true) //默认
|
||||||
|
* public DataSource db1(@Inject("${demo.db1}") HikariDataSource ds) {
|
||||||
|
* return ds;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Bean("db2")
|
||||||
|
* public DataSource db1(@Inject("${demo.db2}") HikariDataSource ds) {
|
||||||
|
* return ds;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre></code>
|
||||||
|
*
|
||||||
|
* @param config 全局配置
|
||||||
|
*/
|
||||||
|
public static void setDefaultConfig(FlexGlobalConfig config) {
|
||||||
|
defaultConfig = config;
|
||||||
|
}
|
||||||
|
|
||||||
public static FlexGlobalConfig getConfig(Configuration configuration) {
|
public static FlexGlobalConfig getConfig(Configuration configuration) {
|
||||||
return getConfig(configuration.getEnvironment().getId());
|
return getConfig(configuration.getEnvironment().getId());
|
||||||
}
|
}
|
||||||
@ -249,9 +273,21 @@ public class FlexGlobalConfig {
|
|||||||
return globalConfigs.get(environmentId);
|
return globalConfigs.get(environmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void setConfig(String id, FlexGlobalConfig config) {
|
public static synchronized void setConfig(String id, FlexGlobalConfig config) {
|
||||||
|
setConfig(id, config, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置全局配置
|
||||||
|
*
|
||||||
|
* @param id 环境id
|
||||||
|
* @param config 全局配置
|
||||||
|
* @param autoDefault 自动指定默认全局配置(在多源时,方便由注解指定默认源)
|
||||||
|
*/
|
||||||
|
public static synchronized void setConfig(String id, FlexGlobalConfig config, boolean autoDefault) {
|
||||||
//first setConfig,copy the config to default
|
//first setConfig,copy the config to default
|
||||||
if (globalConfigs.isEmpty()) {
|
if (autoDefault && globalConfigs.isEmpty()) {
|
||||||
|
|
||||||
defaultConfig.setSqlSessionFactory(config.sqlSessionFactory);
|
defaultConfig.setSqlSessionFactory(config.sqlSessionFactory);
|
||||||
defaultConfig.setDbType(config.dbType);
|
defaultConfig.setDbType(config.dbType);
|
||||||
@ -267,6 +303,4 @@ public class FlexGlobalConfig {
|
|||||||
|
|
||||||
globalConfigs.put(id, config);
|
globalConfigs.put(id, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -32,6 +32,8 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
|||||||
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
||||||
factoryBuilderPlus = bean;
|
factoryBuilderPlus = bean;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initAfter(dsWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MybatisAdapterFlex(BeanWrap dsWrap, Props dsProps) {
|
protected MybatisAdapterFlex(BeanWrap dsWrap, Props dsProps) {
|
||||||
@ -42,6 +44,16 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
|||||||
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
||||||
factoryBuilderPlus = bean;
|
factoryBuilderPlus = bean;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initAfter(dsWrap);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initAfter(BeanWrap dsWrap) {
|
||||||
|
globalConfig.setSqlSessionFactory(getFactory());
|
||||||
|
|
||||||
|
if (dsWrap.typed()) {
|
||||||
|
FlexGlobalConfig.setDefaultConfig(globalConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,8 +63,6 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initConfiguration(Environment environment) {
|
protected void initConfiguration(Environment environment) {
|
||||||
|
|
||||||
|
|
||||||
//for configuration section
|
//for configuration section
|
||||||
config = new FlexConfiguration(environment);
|
config = new FlexConfiguration(environment);
|
||||||
|
|
||||||
@ -72,7 +82,8 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
|||||||
Utils.injectProperties(globalConfig, globalProps);
|
Utils.injectProperties(globalConfig, globalProps);
|
||||||
}
|
}
|
||||||
globalConfig.setConfiguration(config);
|
globalConfig.setConfiguration(config);
|
||||||
FlexGlobalConfig.setConfig(environment.getId(), globalConfig);
|
|
||||||
|
FlexGlobalConfig.setConfig(environment.getId(), globalConfig, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user