Java Code Examples for org.mybatis.spring.SqlSessionFactoryBean#setTypeHandlersPackage()

The following examples show how to use org.mybatis.spring.SqlSessionFactoryBean#setTypeHandlersPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MybatisAutoConfiguration.java    From FS-Blog with Apache License 2.0 6 votes vote down vote up
@Bean(name = "sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(HikariDataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    if (StringUtils.hasText(this.properties.getConfig())) {
        factory.setConfigLocation(
                this.resourceLoader.getResource(this.properties.getConfig()));
    } else {
        if (this.interceptors != null && this.interceptors.length > 0) {
            factory.setPlugins(this.interceptors);
        }
        factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
        factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
        factory.setMapperLocations(this.properties.getMapperLocations());
    }
    return factory.getObject();
}
 
Example 2
Source File: HistoryDataSourceConfig.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public static SqlSessionFactoryBean historySqlSessionFactory(DataSource historyDataSource) throws Exception {
  SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
  sessionFactory.setDataSource(historyDataSource);
  sessionFactory.setTypeHandlersPackage("cern.c2mon.server.history.mapper");

  VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
  Properties properties = new Properties();
  properties.putAll(ImmutableMap.of(
      "HSQL", "oracle",
      "Oracle", "oracle",
      "MySQL", "mysql"
  ));
  databaseIdProvider.setProperties(properties);

  sessionFactory.setDatabaseIdProvider(databaseIdProvider);
  return sessionFactory;
}
 
Example 3
Source File: TestApplication.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Bean
public SqlSessionFactory sqlSessionFactory2(@Qualifier("dataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setVfs(SpringBootVFS.class);
    factory.setDataSource(dataSource);
    String typeHandlers = "org.hswebframework.web.dao.mybatis.handler";
    factory.setTypeHandlersPackage(typeHandlers);
    factory.setMapperLocations(new Resource[]{new ClassPathResource("org/hswebframework/web/dao/test/TestDao.xml")});

    SqlSessionFactory sqlSessionFactory = factory.getObject();
    return sqlSessionFactory;
}
 
Example 4
Source File: ConfigDataSourceConfig.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public static SqlSessionFactoryBean configSqlSessionFactory(DataSource configurationDataSource,
                                                            VendorDatabaseIdProvider databaseIdProvider) throws Exception {
  SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
  sessionFactory.setDataSource(configurationDataSource);
  sessionFactory.setTypeHandlersPackage("cern.c2mon.server.configuration.mybatis");
  sessionFactory.setDatabaseIdProvider(databaseIdProvider);
  return sessionFactory;
}
 
Example 5
Source File: CacheDataSourceConfig.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public static SqlSessionFactoryBean cacheSqlSessionFactory(DataSource cacheDataSource) {
  SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
  sessionFactory.setDataSource(cacheDataSource);
  sessionFactory.setDatabaseIdProvider(databaseIdProvider());
  sessionFactory.setTypeHandlersPackage("cern.c2mon.server.cache.dbaccess.type");
  return sessionFactory;
}
 
Example 6
Source File: MybatisAutoConfiguration.java    From spring-boot-mybatis-rw with Apache License 2.0 5 votes vote down vote up
@Bean
public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSource)
		throws Exception {

	SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
	Interceptor rwplugin = new RWPlugin();
	if (StringUtils.hasText(this.properties.getConfigLocation())) {
		factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
	}
	factory.setConfiguration(properties.getConfiguration());

	if (ObjectUtils.isEmpty(this.interceptors)) {
		Interceptor[] plugins = { rwplugin };
		factory.setPlugins(plugins);
	} else {
		List<Interceptor> interceptorList = new ArrayList<Interceptor>(Arrays.asList(interceptors));
		interceptorList.add(rwplugin);
		factory.setPlugins(interceptorList.toArray(new Interceptor[interceptorList.size()]));
	}
	if (this.databaseIdProvider != null) {
		factory.setDatabaseIdProvider(this.databaseIdProvider);
	}
	if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
		factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
	}
	if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
		factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
	}
	if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
		factory.setMapperLocations(this.properties.resolveMapperLocations());
	}
	factory.setDataSource(dataSource);
	return factory.getObject();
}
 
Example 7
Source File: MapperAutoConfiguration.java    From Mapper with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    applyConfiguration(factory);
    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.properties.resolveMapperLocations())) {
        factory.setMapperLocations(this.properties.resolveMapperLocations());
    }

    return factory.getObject();
}