Search in sources :

Example 16 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration 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();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration 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;
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)

Aggregations

MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)17 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)12 Bean (org.springframework.context.annotation.Bean)10 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)9 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)7 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)4 ConfigurationCustomizer (com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer)3 MybatisPlusProperties (com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties)2 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)2 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)2 Environment (org.apache.ibatis.mapping.Environment)2 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)2 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)2 MybatisSqlSessionFactoryBuilder (com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 PaginationInterceptor (com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1 DataSource (javax.sql.DataSource)1 Primary (org.springframework.context.annotation.Primary)1 Resource (org.springframework.core.io.Resource)1