use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project incubator-linkis by apache.
the class MybatisConfigurationFactory method sqlSessionFactory.
// Provide SqlSeesion(提供SqlSeesion)
@Bean(name = "sqlSessionFactory")
@Primary
public MybatisSqlSessionFactoryBean sqlSessionFactory() {
String typeAliasesPackage = MybatisConfiguration.BDP_SERVER_MYBATIS_TYPEALIASESPACKAGE.getValue();
// Configure the mapper scan to find all mapper.xml mapping
// files(配置mapper的扫描,找到所有的mapper.xml映射文件)
String mapperLocations = MybatisConfiguration.BDP_SERVER_MYBATIS_MAPPER_LOCATIONS.getValue();
// Load the global configuration file(加载全局的配置文件)
String configLocation = MybatisConfiguration.BDP_SERVER_MYBATIS_CONFIGLOCATION.getValue();
try {
MybatisSqlSessionFactoryBean sessionFactoryBean = new MybatisSqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
info("Mybatis typeAliasesPackage=" + typeAliasesPackage);
info("Mybatis mapperLocations=" + mapperLocations);
info("Mybatis configLocation=" + configLocation);
// Read configuration(读取配置)
sessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
// Set the location of the mapper.xml file(设置mapper.xml文件所在位置)
if (StringUtils.isNotBlank(mapperLocations)) {
String[] mapperArray = mapperLocations.split(",");
List<Resource> resources = new ArrayList<>();
for (String mapperLocation : mapperArray) {
CollectionUtils.addAll(resources, new PathMatchingResourcePatternResolver().getResources(mapperLocation));
}
sessionFactoryBean.setMapperLocations(resources.toArray(new Resource[0]));
}
/* Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperLocations);
sessionFactoryBean.setMapperLocations(resources);*/
// Set the location of the mybatis-config.xml configuration
// file(设置mybatis-config.xml配置文件位置)
sessionFactoryBean.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
// Add paging plugin, print sql plugin(添加分页插件、打印sql插件)
Interceptor[] plugins = new Interceptor[] { pageInterceptor() };
sessionFactoryBean.setPlugins(plugins);
return sessionFactoryBean;
} catch (IOException e) {
error("mybatis resolver mapper*xml is error", e);
return null;
} catch (Exception e) {
error("mybatis sqlSessionFactoryBean create error", e);
return null;
}
}
use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project FCLProject by FlowingCloudL.
the class DataSourceProxyConfig method sqlSessionFactoryBean.
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
// 订单服务中引入了mybatis-plus,所以要使用特殊的SqlSessionFactoryBean
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
// 代理数据源
sqlSessionFactoryBean.setDataSource(new DataSourceProxy(dataSource));
// 生成SqlSessionFactory
return sqlSessionFactoryBean.getObject();
}
use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project dolphinscheduler by apache.
the class SpringConnectionFactory method sqlSessionFactory.
/**
* * get sql session factory
* @return sqlSessionFactory
* @throws Exception sqlSessionFactory exception
*/
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setMapUnderscoreToCamelCase(true);
configuration.setCacheEnabled(false);
configuration.setCallSettersOnNulls(true);
configuration.setJdbcTypeForNull(JdbcType.NULL);
configuration.addInterceptor(paginationInterceptor());
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setConfiguration(configuration);
sqlSessionFactoryBean.setDataSource(dataSource());
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
dbConfig.setIdType(IdType.AUTO);
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setDbConfig(dbConfig);
sqlSessionFactoryBean.setGlobalConfig(globalConfig);
sqlSessionFactoryBean.setTypeAliasesPackage("org.apache.dolphinscheduler.dao.entity");
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("org/apache/dolphinscheduler/dao/mapper/*Mapper.xml"));
sqlSessionFactoryBean.setTypeEnumsPackage("org.apache.dolphinscheduler.*.enums");
return sqlSessionFactoryBean.getObject();
}
use of com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean in project dolphinscheduler by apache.
the class ConnectionFactory method getSqlSessionFactory.
/**
* * get sql session factory
*
* @return sqlSessionFactory
* @throws Exception sqlSessionFactory exception
*/
private SqlSessionFactory getSqlSessionFactory() throws Exception {
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("development", transactionFactory, getDataSource());
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setEnvironment(environment);
configuration.setLazyLoadingEnabled(true);
configuration.addMappers("org.apache.dolphinscheduler.dao.mapper");
configuration.addInterceptor(new PaginationInterceptor());
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setConfiguration(configuration);
sqlSessionFactoryBean.setDataSource(getDataSource());
sqlSessionFactoryBean.setTypeEnumsPackage("org.apache.dolphinscheduler.*.enums");
sqlSessionFactory = sqlSessionFactoryBean.getObject();
return sqlSessionFactory;
}
Aggregations