|
@@ -1,140 +1,306 @@
|
|
-//package com.citupro.flames.config;
|
|
|
|
-//
|
|
|
|
-//import com.alibaba.druid.pool.DruidDataSource;
|
|
|
|
-//import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
|
|
|
-//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
-//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
-//import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
|
|
|
-//import com.bing.digitalparadigm.component.MySqlInjector;
|
|
|
|
-//import com.bing.digitalparadigm.component.TenantMybaitsInnerInterceptor;
|
|
|
|
-//import com.citupro.common.mybatis.plugin.SqlInterceptor;
|
|
|
|
-//import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
-//import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
-//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
-//import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
-//import org.springframework.context.ApplicationContext;
|
|
|
|
-//import org.springframework.context.annotation.Bean;
|
|
|
|
-//import org.springframework.context.annotation.Conditional;
|
|
|
|
-//import org.springframework.context.annotation.Configuration;
|
|
|
|
-//import org.springframework.context.annotation.Primary;
|
|
|
|
-//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
|
-//import javax.annotation.PostConstruct;
|
|
|
|
-//import javax.sql.DataSource;
|
|
|
|
-//import java.util.ArrayList;
|
|
|
|
-//import java.util.HashMap;
|
|
|
|
-//import java.util.List;
|
|
|
|
-//import java.util.Map;
|
|
|
|
-////@ConfigurationProperties(prefix="employeewhitelist")
|
|
|
|
-//@Configuration
|
|
|
|
-//@MapperScan("com.citupro.flames.mapper")
|
|
|
|
-//public class MyBatiesPlusConfiguration {
|
|
|
|
-// @SuppressWarnings("all")
|
|
|
|
-// private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MyBatiesPlusConfiguration.class);
|
|
|
|
-// // 精确到 master 目录,以便跟其他数据源隔离
|
|
|
|
-// static final String MAPPER_LOCATION = "classpath:mybatis/mapper/**/*.xml";
|
|
|
|
-// private volatile List<String> tableName = new ArrayList<>();
|
|
|
|
-// private volatile List<String> nointerceptionTableNames = new ArrayList<>();
|
|
|
|
-// private volatile Map<String, String> tablenameandcolumn = new HashMap<>();
|
|
|
|
|
|
+package com.citupro.module.menduner.flames.config;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
|
|
|
+import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
|
|
|
+import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS;
|
|
|
|
+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.IdentifierGenerator;
|
|
|
|
+import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
|
|
|
+import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
|
|
|
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
|
|
|
+import com.citupro.module.menduner.flames.plugin.SqlInterceptor;
|
|
|
|
+import org.apache.ibatis.mapping.DatabaseIdProvider;
|
|
|
|
+import org.apache.ibatis.plugin.Interceptor;
|
|
|
|
+import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
+import org.mybatis.spring.SqlSessionTemplate;
|
|
|
|
+import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
|
+import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
|
+import org.springframework.core.io.ResourceLoader;
|
|
|
|
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
+
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
|
+import javax.sql.DataSource;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.function.Consumer;
|
|
|
|
+
|
|
|
|
+//@ConfigurationProperties(prefix="employeewhitelist")
|
|
|
|
+@Configuration
|
|
|
|
+@MapperScan(basePackages="com.citupro.module.menduner.flames.mapper",sqlSessionFactoryRef = "primarySqlSessionFactory",sqlSessionTemplateRef ="primarySqlSessionTemplateFactory" )
|
|
|
|
+@MapperScan(basePackages = "com.citupro.module.menduner.flames.menduner.mapper", sqlSessionFactoryRef = "mendunerSqlSessionFactory",sqlSessionTemplateRef ="mendunerSqlSessionTemplateFactory")
|
|
|
|
+@EnableConfigurationProperties({MybatisPlusProperties.class})
|
|
|
|
+public class MyBatiesPlusConfiguration implements InitializingBean {
|
|
|
|
+ @SuppressWarnings("all")
|
|
|
|
+ private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MyBatiesPlusConfiguration.class);
|
|
|
|
+ private volatile List<String> tableName = new ArrayList<>();
|
|
|
|
+ private volatile List<String> nointerceptionTableNames = new ArrayList<>();
|
|
|
|
+ private volatile Map<String, String> tablenameandcolumn = new HashMap<>();
|
|
// private volatile TenantMybaitsInnerInterceptor tenantMybaitsInnerInterceptor = new TenantMybaitsInnerInterceptor(tableName, nointerceptionTableNames);
|
|
// private volatile TenantMybaitsInnerInterceptor tenantMybaitsInnerInterceptor = new TenantMybaitsInnerInterceptor(tableName, nointerceptionTableNames);
|
|
-//
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private final MybatisPlusProperties properties;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ObjectProvider<Interceptor[]> interceptorsProvider;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ObjectProvider<DatabaseIdProvider> databaseIdProvider;
|
|
|
|
+
|
|
|
|
+ private Interceptor[] interceptors;
|
|
|
|
+ private final ResourceLoader resourceLoader;
|
|
|
|
+ private DatabaseIdProvider finalDatabaseIdProvider;
|
|
|
|
+ private final List<ConfigurationCustomizer> configurationCustomizers;
|
|
|
|
+ private final ApplicationContext applicationContext;
|
|
|
|
+
|
|
|
|
+ public MyBatiesPlusConfiguration(MybatisPlusProperties properties,
|
|
|
|
+ ResourceLoader resourceLoader,
|
|
|
|
+ ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider,
|
|
|
|
+ ApplicationContext applicationContext) {
|
|
|
|
+ this.properties = properties;
|
|
|
|
+
|
|
|
|
+ this.resourceLoader = resourceLoader;
|
|
|
|
+ this.configurationCustomizers = (List)configurationCustomizersProvider.getIfAvailable();
|
|
|
|
+ this.applicationContext = applicationContext;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
|
+ this.interceptors = (Interceptor[])this.interceptorsProvider.getIfAvailable();
|
|
|
|
+ this.finalDatabaseIdProvider = (DatabaseIdProvider)this.databaseIdProvider.getIfAvailable();
|
|
|
|
+
|
|
|
|
+ }
|
|
// @Bean
|
|
// @Bean
|
|
// public TenantLineInnerInterceptor intTenantLineInnerInterceptor2() {
|
|
// public TenantLineInnerInterceptor intTenantLineInnerInterceptor2() {
|
|
// return new TenantLineInnerInterceptor(this.tenantMybaitsInnerInterceptor);
|
|
// return new TenantLineInnerInterceptor(this.tenantMybaitsInnerInterceptor);
|
|
// }
|
|
// }
|
|
-//
|
|
|
|
-////<editor-fold defaultstate="collapsed" desc="delombok">
|
|
|
|
-////</editor-fold>
|
|
|
|
-// @Bean
|
|
|
|
-// public MybatisPlusInterceptor mybatisPlusInterceptor(TenantLineInnerInterceptor tenantLineInnerInterceptor) {
|
|
|
|
-// log.info("TenantConfig init ========================= MybatisPlusInterceptor");
|
|
|
|
-// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
|
-// interceptor.addInnerInterceptor(tenantLineInnerInterceptor);
|
|
|
|
-//// interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
|
|
|
-// interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
|
|
|
-//// interceptor.addInnerInterceptor(new RelationInterceptor());
|
|
|
|
-// return interceptor;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-////<editor-fold defaultstate="collapsed" desc="delombok">
|
|
|
|
-////</editor-fold>
|
|
|
|
-// @Bean
|
|
|
|
-// public SqlInterceptor intSqlInterceptor() {
|
|
|
|
-// SqlInterceptor sqlInterceptor = new SqlInterceptor();
|
|
|
|
-// return sqlInterceptor;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//// private EmployeeWhiteListInterceptor employeeWhiteListInterceptor;
|
|
|
|
-////
|
|
|
|
-//// @Autowired
|
|
|
|
-//// private StatisticsWhiteEmployeeService statisticsWhiteEmployeeService;
|
|
|
|
-//// @Bean(name = "masterTransactionManager")
|
|
|
|
-//// @Primary
|
|
|
|
-//// public DataSourceTransactionManager masterTransactionManager(@Qualifier("dynamicRoutingDataSource") DynamicRoutingDataSource dataSource) {
|
|
|
|
-//// return new DataSourceTransactionManager(dataSource);
|
|
|
|
-//// }
|
|
|
|
-////
|
|
|
|
-//// @Bean
|
|
|
|
-////// @ConditionalOnBean(MybatisPlusInterceptor.class)
|
|
|
|
-//// public EmployeeWhiteListInterceptor intTenantLineInnerInterceptor(MybatisPlusInterceptor mybatisPlusInterceptor){
|
|
|
|
-//// EmployeeWhiteListInterceptor employeeWhiteListInterceptor =new EmployeeWhiteListInterceptor();
|
|
|
|
-////// employeeWhiteListInterceptor.addWhiteTableName("");
|
|
|
|
-//// employeeWhiteListInterceptor.addWhiteTableNameAll(tablenameandcolumn);
|
|
|
|
-//// mybatisPlusInterceptor.addInnerInterceptor(employeeWhiteListInterceptor);
|
|
|
|
-////
|
|
|
|
-////
|
|
|
|
-//// this.employeeWhiteListInterceptor = employeeWhiteListInterceptor;
|
|
|
|
-//// return employeeWhiteListInterceptor;
|
|
|
|
-//// }
|
|
|
|
-// @Bean
|
|
|
|
-// public DefaultSqlInjector sqlInjector() {
|
|
|
|
-// return new MySqlInjector();
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-////// @DS()
|
|
|
|
-//// @Bean(name = "business",initMethod="init")
|
|
|
|
-//// @ConfigurationProperties(prefix = "spring.datasource.druid" )
|
|
|
|
-//// public DruidDataSource masterDataSource() {
|
|
|
|
-//// return new DruidDataSource();
|
|
|
|
-//// }
|
|
|
|
-////
|
|
|
|
-////
|
|
|
|
-//// @Bean(name = "dataFactory",initMethod="init")
|
|
|
|
-//// @ConfigurationProperties(prefix = "spring.data.factory.datasource.druid" )
|
|
|
|
-//// @Conditional(value = DataFatroryCondition.class)
|
|
|
|
-//// public DruidDataSource dataFactoryDataSource() {
|
|
|
|
-//// return new DruidDataSource();
|
|
|
|
-//// }
|
|
|
|
-////
|
|
|
|
-//// /**
|
|
|
|
-//// * 多数据源
|
|
|
|
-//// * DynamicDataSourceContextHolder 可以手动选择数据源
|
|
|
|
-//// * @param dataSource
|
|
|
|
-//// * @return
|
|
|
|
-//// */
|
|
|
|
-//// @Bean(name = "dynamicRoutingDataSource")
|
|
|
|
-//// @Primary
|
|
|
|
-//// public DynamicRoutingDataSource dynamicRoutingDataSource(@Qualifier("business") DruidDataSource dataSource, ApplicationContext applicationContext){
|
|
|
|
-//// DynamicRoutingDataSource dynamicRoutingDataSource =new DynamicRoutingDataSource();
|
|
|
|
-//// dynamicRoutingDataSource.addDataSource("business",dataSource);
|
|
|
|
-//// String[] beanNamesForType = applicationContext.getBeanNamesForType(DataSource.class);
|
|
|
|
-//// for (String beanName : beanNamesForType) {
|
|
|
|
-//// if(!"business".equals(beanName) && !"dynamicRoutingDataSource".equals(beanName)){
|
|
|
|
-//// DataSource dynamicDataSource = applicationContext.getBean(beanName, DataSource.class);
|
|
|
|
-//// dynamicRoutingDataSource.addDataSource(beanName,dynamicDataSource);
|
|
|
|
-//// }
|
|
|
|
-//// }
|
|
|
|
-////
|
|
|
|
-//// dynamicRoutingDataSource.setPrimary("business");
|
|
|
|
-//// return dynamicRoutingDataSource;
|
|
|
|
-//// }
|
|
|
|
-// public Map<String, String> getTablenameandcolumn() {
|
|
|
|
-// return tablenameandcolumn;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public void setTablenameandcolumn(Map<String, String> tablenameandcolumn) {
|
|
|
|
-// this.tablenameandcolumn = tablenameandcolumn;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public MybatisPlusInterceptor mybatisPlusInterceptor(TenantLineInnerInterceptor tenantLineInnerInterceptor) {
|
|
|
|
+ log.info("TenantConfig init ========================= MybatisPlusInterceptor");
|
|
|
|
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
|
+ interceptor.addInnerInterceptor(tenantLineInnerInterceptor);
|
|
|
|
+// interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
|
|
|
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
|
|
|
+// interceptor.addInnerInterceptor(new RelationInterceptor());
|
|
|
|
+ return interceptor;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public SqlInterceptor intSqlInterceptor() {
|
|
|
|
+ SqlInterceptor sqlInterceptor = new SqlInterceptor();
|
|
|
|
+ return sqlInterceptor;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean(name = "primarySqlSessionFactory")
|
|
|
|
+ @Primary
|
|
|
|
+ public SqlSessionFactory primarySqlSessionFactory(@Qualifier("primaryDataSource") DataSource dataSource
|
|
|
|
+ ,MybatisPlusInterceptor mybatisPlusInterceptor,SqlInterceptor sqlInterceptor) throws Exception {
|
|
|
|
+ Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/primary/*.xml");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
|
|
|
|
+ factory.setVfs(SpringBootVFS.class);
|
|
|
|
+ factory.setPlugins(mybatisPlusInterceptor,sqlInterceptor);
|
|
|
|
+ if (StringUtils.hasText(this.properties.getConfigLocation())) {
|
|
|
|
+ factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.applyConfiguration(factory);
|
|
|
|
+ if (this.properties.getConfigurationProperties() != null) {
|
|
|
|
+ factory.setConfigurationProperties(this.properties.getConfigurationProperties());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ObjectUtils.isEmpty(this.interceptors)) {
|
|
|
|
+ factory.setPlugins(this.interceptors);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.finalDatabaseIdProvider != null) {
|
|
|
|
+ factory.setDatabaseIdProvider(this.finalDatabaseIdProvider);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
|
|
|
|
+ factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (this.properties.getTypeAliasesSuperType() != null) {
|
|
|
|
+ factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
|
|
|
|
+ factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
|
|
|
|
+ factory.setMapperLocations(this.properties.resolveMapperLocations());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GlobalConfig globalConfig = this.properties.getGlobalConfig();
|
|
|
|
+ if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, false, false).length > 0) {
|
|
|
|
+ MetaObjectHandler metaObjectHandler = (MetaObjectHandler)this.applicationContext.getBean(MetaObjectHandler.class);
|
|
|
|
+ globalConfig.setMetaObjectHandler(metaObjectHandler);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false, false).length > 0) {
|
|
|
|
+ ISqlInjector iSqlInjector = (ISqlInjector)this.applicationContext.getBean(ISqlInjector.class);
|
|
|
|
+ globalConfig.setSqlInjector(iSqlInjector);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Objects.requireNonNull(globalConfig);
|
|
|
|
+ this.getBeanThen(IdentifierGenerator.class, globalConfig::setIdentifierGenerator);
|
|
|
|
+ factory.setGlobalConfig(globalConfig);
|
|
|
|
+ factory.setMapperLocations(resources);
|
|
|
|
+ factory.setDataSource(dataSource);
|
|
|
|
+
|
|
|
|
+ return factory.getObject();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void applyConfiguration(MybatisSqlSessionFactoryBean factory) {
|
|
|
|
+ MybatisPlusProperties.CoreConfiguration coreConfiguration = this.properties.getConfiguration();
|
|
|
|
+ MybatisConfiguration configuration = null;
|
|
|
|
+ if (coreConfiguration != null || !StringUtils.hasText(this.properties.getConfigLocation())) {
|
|
|
|
+ configuration = new MybatisConfiguration();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (configuration != null && coreConfiguration != null) {
|
|
|
|
+ coreConfiguration.applyTo(configuration);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
|
|
|
|
+ Iterator var4 = this.configurationCustomizers.iterator();
|
|
|
|
+
|
|
|
|
+ while(var4.hasNext()) {
|
|
|
|
+ ConfigurationCustomizer customizer = (ConfigurationCustomizer)var4.next();
|
|
|
|
+ customizer.customize(configuration);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ factory.setConfiguration(configuration);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean(name = "mendunerSqlSessionFactory")
|
|
|
|
+ public SqlSessionFactory mendunerSqlSessionFactory(@Qualifier("mendunerDataSource") DataSource dataSource
|
|
|
|
+ ,MybatisPlusInterceptor mybatisPlusInterceptor,SqlInterceptor sqlInterceptor) throws Exception {
|
|
|
|
+
|
|
|
|
+ MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
|
|
|
|
+
|
|
|
|
+// factory.setma
|
|
|
|
+ factory.setPlugins(mybatisPlusInterceptor,sqlInterceptor);
|
|
|
|
+// factory.setTypeAliasesPackage("com.citupro.flames.pojo");
|
|
|
|
+ if (StringUtils.hasText(this.properties.getConfigLocation())) {
|
|
|
|
+ factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.applyConfiguration(factory);
|
|
|
|
+ if (this.properties.getConfigurationProperties() != null) {
|
|
|
|
+ factory.setConfigurationProperties(this.properties.getConfigurationProperties());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ObjectUtils.isEmpty(this.interceptors)) {
|
|
|
|
+ factory.setPlugins(this.interceptors);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.finalDatabaseIdProvider != null) {
|
|
|
|
+ factory.setDatabaseIdProvider(this.finalDatabaseIdProvider);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
|
|
|
|
+ factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.properties.getTypeAliasesSuperType() != null) {
|
|
|
|
+ factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
|
|
|
|
+ factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
|
|
|
|
+ factory.setMapperLocations(this.properties.resolveMapperLocations());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GlobalConfig globalConfig = this.properties.getGlobalConfig();
|
|
|
|
+ if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, false, false).length > 0) {
|
|
|
|
+ MetaObjectHandler metaObjectHandler = (MetaObjectHandler)this.applicationContext.getBean(MetaObjectHandler.class);
|
|
|
|
+ globalConfig.setMetaObjectHandler(metaObjectHandler);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false, false).length > 0) {
|
|
|
|
+ ISqlInjector iSqlInjector = (ISqlInjector)this.applicationContext.getBean(ISqlInjector.class);
|
|
|
|
+ globalConfig.setSqlInjector(iSqlInjector);
|
|
|
|
+ }
|
|
|
|
+ Objects.requireNonNull(globalConfig);
|
|
|
|
+ this.getBeanThen(IdentifierGenerator.class, globalConfig::setIdentifierGenerator);
|
|
|
|
+
|
|
|
|
+ factory.setGlobalConfig(globalConfig);
|
|
|
|
+ factory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/menduner/*.xml"));
|
|
|
|
+ factory.setDataSource(dataSource);
|
|
|
|
+ factory.setVfs(SpringBootVFS.class);
|
|
|
|
+
|
|
|
|
+ return factory.getObject();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean(name = "primarySqlSessionTemplateFactory")
|
|
|
|
+ @Primary
|
|
|
|
+ public SqlSessionTemplate primarySqlSessionTemplateFactory(@Qualifier("primarySqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
|
|
|
|
+ return new SqlSessionTemplate(sqlSessionFactory);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean(name = "mendunerSqlSessionTemplateFactory")
|
|
|
|
+ public SqlSessionTemplate mendunerSqlSessionTemplateFactory(@Qualifier("mendunerSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
|
|
|
|
+ return new SqlSessionTemplate(sqlSessionFactory);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private <T> void getBeanThen(Class<T> clazz, Consumer<T> consumer) {
|
|
|
|
+ if (this.applicationContext.getBeanNamesForType(clazz, false, false).length > 0) {
|
|
|
|
+ consumer.accept(this.applicationContext.getBean(clazz));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, String> getTablenameandcolumn() {
|
|
|
|
+ return tablenameandcolumn;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setTablenameandcolumn(Map<String, String> tablenameandcolumn) {
|
|
|
|
+ this.tablenameandcolumn = tablenameandcolumn;
|
|
|
|
+ }
|
|
|
|
+
|
|
// @PostConstruct
|
|
// @PostConstruct
|
|
// public void printNacosConfig() {
|
|
// public void printNacosConfig() {
|
|
// if (null != tenantMybaitsInnerInterceptor) {
|
|
// if (null != tenantMybaitsInnerInterceptor) {
|
|
@@ -143,20 +309,22 @@
|
|
// }
|
|
// }
|
|
// log.info("从配置中心获取到过滤表的的配置为:{},不需要过滤的表配置为:{}", tableName, this.nointerceptionTableNames);
|
|
// log.info("从配置中心获取到过滤表的的配置为:{},不需要过滤的表配置为:{}", tableName, this.nointerceptionTableNames);
|
|
// }
|
|
// }
|
|
-//
|
|
|
|
-// public List<String> getTableName() {
|
|
|
|
-// return tableName;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public void setTableName(List<String> tableName) {
|
|
|
|
-// this.tableName = tableName;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public List<String> getNointerceptionTableNames() {
|
|
|
|
-// return nointerceptionTableNames;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// public void setNointerceptionTableNames(List<String> nointerceptionTableNames) {
|
|
|
|
-// this.nointerceptionTableNames = nointerceptionTableNames;
|
|
|
|
-// }
|
|
|
|
-//}
|
|
|
|
|
|
+
|
|
|
|
+ public List<String> getTableName() {
|
|
|
|
+ return tableName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setTableName(List<String> tableName) {
|
|
|
|
+ this.tableName = tableName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<String> getNointerceptionTableNames() {
|
|
|
|
+ return nointerceptionTableNames;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setNointerceptionTableNames(List<String> nointerceptionTableNames) {
|
|
|
|
+ this.nointerceptionTableNames = nointerceptionTableNames;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|