Package org.mybatis.spring

Examples of org.mybatis.spring.SqlSessionFactoryBean


      return new DataSourceTransactionManager(dataSource());
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
      SqlSessionFactoryBean ss = new SqlSessionFactoryBean();
      ss.setDataSource(dataSource());
      ss.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/sample/dao/UserDao.xml") });
      return (SqlSessionFactory) ss.getObject();
    }
View Full Code Here


  @Test
  public void testAddToConfigTrue() throws Exception {
    // the default SqlSessionFactory in AbstractMyBatisSpringTest is created with an explicitly set
    // MapperLocations list, so create a new factory here that tests auto-loading the config
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDatabaseIdProvider(null);
    // mapperLocations properties defaults to null
    factoryBean.setDataSource(dataSource);
    factoryBean.setPlugins(new Interceptor[] { executorInterceptor });

    SqlSessionFactory sqlSessionFactory = factoryBean.getObject();

    find(new SqlSessionTemplate(sqlSessionFactory), true);
    assertCommit(); // SqlSesssionTemplate autocommits
    assertSingleConnection();
    assertExecuteCount(1);
View Full Code Here

  public void testAddToConfigFalse() throws Throwable {
    try {
      // the default SqlSessionFactory in AbstractMyBatisSpringTest is created with an explicitly
      // set MapperLocations list, so create a new factory here that tests auto-loading the
      // config
      SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
      // mapperLocations properties defaults to null
      factoryBean.setDataSource(dataSource);

      SqlSessionFactory sqlSessionFactory = factoryBean.getObject();

      find(new SqlSessionTemplate(sqlSessionFactory), false);
      fail("TestDao's mapper xml should not be loaded");
    } catch (MyBatisSystemException mbse) {
      // unwrap exception so the exact MyBatis exception can be tested
View Full Code Here

    if(CollectionUtils.isEmpty(shardConfigurations)){
      for(Map.Entry<Integer, DataSource> entry : dataSources.entrySet()){
        int shardId = entry.getKey()//虚拟分区ID
        DataSource dataSource = entry.getValue()//虚拟分区所属数据源
       
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setConfigLocation(this.configLocation);
        factoryBean.setMapperLocations(this.mapperLocations);
        factoryBean.setDataSource(dataSource);
        factoryBean.setEnvironment(this.environment);
        factoryBean.setConfigurationProperties(this.configurationProperties);
        factoryBean.setPlugins(this.plugins);
        factoryBean.setTypeHandlers(this.typeHandlers);
        factoryBean.setTypeHandlersPackage(this.typeHandlersPackage);
        factoryBean.setTypeAliases(this.typeAliases);
        factoryBean.setTypeAliasesPackage(this.typeAliasesPackage);
       
        SqlSessionFactory sessionFacotry = factoryBean.getObject();
       
        shardConfigs.add(new ShardConfigurationImpl(shardId, dataSource, sessionFacotry));
      }
    }else {
      for(ShardConfigurationImpl shardConfiguration : shardConfigurations){
       
        Assert.notNull(shardConfiguration.getShardId(), "shard id can not be null.");
        Assert.notNull(shardConfiguration.getShardDataSource(), "data source can not be null.");
       
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setConfigLocation(shardConfiguration.getConfigLocation());
        factoryBean.setMapperLocations(shardConfiguration.getMapperLocations());
        factoryBean.setDataSource(shardConfiguration.getShardDataSource());
        factoryBean.setEnvironment(this.environment);
        factoryBean.setConfigurationProperties(this.configurationProperties);
        factoryBean.setPlugins(this.plugins);
        factoryBean.setTypeHandlers(this.typeHandlers);
        factoryBean.setTypeHandlersPackage(shardConfiguration.getTypeHandlersPackage());
        factoryBean.setTypeAliases(this.typeAliases);
        factoryBean.setTypeAliasesPackage(shardConfiguration.getTypeAliasesPackage());
       
        SqlSessionFactory sessionFacotry = factoryBean.getObject();
        shardConfiguration.setSqlSessionFactory(sessionFacotry);
       
        shardConfigs.add(shardConfiguration);
      }
     
View Full Code Here

        return ds;
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource());
        sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
        return sqlSessionFactoryBean.getObject();
    }
View Full Code Here

TOP

Related Classes of org.mybatis.spring.SqlSessionFactoryBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.