use of com.baomidou.mybatisplus.core.MybatisConfiguration in project mybaits-plus-join by Createsequence.
the class DefaultMybatisPlusExtendConfig method sqlSessionFactory.
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource);
// 插件
sqlSessionFactory.setPlugins(new DynamicResultInterceptor());
MybatisConfiguration configuration = new MybatisConfiguration();
GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
// 自定义sql注入
globalConfig.setSqlInjector(new JoinMethodInjector());
sqlSessionFactory.setConfiguration(configuration);
// 插件
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
configuration.addInterceptor(interceptor);
return sqlSessionFactory.getObject();
}
use of com.baomidou.mybatisplus.core.MybatisConfiguration in project project by Ahaochan.
the class MultiMyBatisConfig method getFactory.
public MybatisSqlSessionFactoryBean getFactory(DataSource dataSource) {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
factory.setDataSource(dataSource);
factory.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
MybatisConfiguration configuration = this.properties.getConfiguration();
if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
configuration = new MybatisConfiguration();
}
if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
customizer.customize(configuration);
}
}
factory.setConfiguration(configuration);
if (this.properties.getConfigurationProperties() != null) {
factory.setConfigurationProperties(this.properties.getConfigurationProperties());
}
if (!ObjectUtils.isEmpty(this.interceptors)) {
factory.setPlugins(this.interceptors);
}
if (this.databaseIdProvider != null) {
factory.setDatabaseIdProvider(this.databaseIdProvider);
}
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.typeHandlers)) {
factory.setTypeHandlers(this.typeHandlers);
}
Resource[] mapperLocations = this.properties.resolveMapperLocations();
if (!ObjectUtils.isEmpty(mapperLocations)) {
factory.setMapperLocations(mapperLocations);
}
// TODO 修改源码支持定义 TransactionFactory
this.getBeanThen(TransactionFactory.class, factory::setTransactionFactory);
// TODO 对源码做了一定的修改(因为源码适配了老旧的mybatis版本,但我们不需要适配)
Class<? extends LanguageDriver> defaultLanguageDriver = this.properties.getDefaultScriptingLanguageDriver();
if (!ObjectUtils.isEmpty(this.languageDrivers)) {
factory.setScriptingLanguageDrivers(this.languageDrivers);
}
Optional.ofNullable(defaultLanguageDriver).ifPresent(factory::setDefaultScriptingLanguageDriver);
// TODO 自定义枚举包
if (StringUtils.hasLength(this.properties.getTypeEnumsPackage())) {
factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
}
// TODO 此处必为非 NULL
GlobalConfig globalConfig = this.properties.getGlobalConfig();
// TODO 注入填充器
this.getBeanThen(MetaObjectHandler.class, globalConfig::setMetaObjectHandler);
// TODO 注入主键生成器
this.getBeanThen(IKeyGenerator.class, i -> globalConfig.getDbConfig().setKeyGenerator(i));
// TODO 注入sql注入器
this.getBeanThen(ISqlInjector.class, globalConfig::setSqlInjector);
// TODO 注入ID生成器
this.getBeanThen(IdentifierGenerator.class, globalConfig::setIdentifierGenerator);
// TODO 设置 GlobalConfig 到 MybatisSqlSessionFactoryBean
factory.setGlobalConfig(globalConfig);
return factory;
}
use of com.baomidou.mybatisplus.core.MybatisConfiguration in project springboot-templet-start by thedestiny.
the class MybatisPlusConfigPrimaryDatasource method priSqlSessionFactory.
// pre
@Bean("priSqlSessionFactory")
public SqlSessionFactory priSqlSessionFactory(@Qualifier("priDatasource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource);
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
configuration.setJdbcTypeForNull(JdbcType.NULL);
configuration.setMapUnderscoreToCamelCase(true);
configuration.setCacheEnabled(false);
configuration.setDefaultExecutorType(ExecutorType.BATCH);
sqlSessionFactory.setConfiguration(configuration);
sqlSessionFactory.setTypeAliasesPackage("com.destiny.hiootamus.entity.primary");
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/primary/*.xml"));
sqlSessionFactory.setPlugins(plusInterceptor);
sqlSessionFactory.setGlobalConfig(new GlobalConfig().setBanner(true));
return sqlSessionFactory.getObject();
}
use of com.baomidou.mybatisplus.core.MybatisConfiguration in project scaleph by flowerfine.
the class MasterDataSourceConfig method masterSqlSessionFactory.
@Primary
@Bean(MASTER_SQL_SESSION_FACTORY)
public SqlSessionFactory masterSqlSessionFactory() throws Exception {
MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
MybatisPlusProperties props = new MybatisPlusProperties();
props.setMapperLocations(new String[] { MASTER_MAPPER_XML_PATH });
factoryBean.setMapperLocations(props.resolveMapperLocations());
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setMapUnderscoreToCamelCase(true);
configuration.setLogImpl(Slf4jImpl.class);
factoryBean.setConfiguration(configuration);
factoryBean.setDataSource(masterDataSource());
factoryBean.setTypeAliasesPackage(MASTER_ENTITY_PACKAGE);
factoryBean.setPlugins(mybatisPlusInterceptor);
return factoryBean.getObject();
}
use of com.baomidou.mybatisplus.core.MybatisConfiguration in project lamp-util by zuihou.
the class BaseDatabaseConfiguration method applyConfiguration.
protected void applyConfiguration(MybatisSqlSessionFactoryBean factory) {
MybatisConfiguration configuration = this.properties.getConfiguration();
if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
configuration = new MybatisConfiguration();
}
if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
customizer.customize(configuration);
}
}
factory.setConfiguration(configuration);
// BeanUtil.copyProperties 无法复制生成对象
/*
MybatisConfiguration newConfiguration = this.properties.getConfiguration();
if (newConfiguration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
newConfiguration = new MybatisConfiguration();
}
// zuihou 改过这里: 这里一定要复制一次, 否则多数据源时,会导致拦截器等执行多次
MybatisConfiguration configuration = new MybatisConfiguration();
// BeanUtil.copyProperties(newConfiguration, configuration);
BeanUtils.copyProperties(newConfiguration, configuration);
if (!CollectionUtils.isEmpty(this.configurationCustomizers)) {
for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
customizer.customize(configuration);
}
}
factory.setConfiguration(configuration);
*/
}
Aggregations