当前位置: 首页>>代码示例>>Java>>正文


Java SqlSessionFactoryBean.afterPropertiesSet方法代码示例

本文整理汇总了Java中org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet方法的典型用法代码示例。如果您正苦于以下问题:Java SqlSessionFactoryBean.afterPropertiesSet方法的具体用法?Java SqlSessionFactoryBean.afterPropertiesSet怎么用?Java SqlSessionFactoryBean.afterPropertiesSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mybatis.spring.SqlSessionFactoryBean的用法示例。


在下文中一共展示了SqlSessionFactoryBean.afterPropertiesSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //导入方法依赖的package包/类
@Bean
public SqlSessionFactory sqlSessionFactory() {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());

    try {
        Properties properties = new Properties();
        properties.put("prefix", env.getProperty("datasource.prefix", ""));
        sqlSessionFactoryBean.setConfigurationProperties(properties);
        sqlSessionFactoryBean
                .setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/admin-mybatis-mappings/*.xml"));
        sqlSessionFactoryBean.afterPropertiesSet();
        return sqlSessionFactoryBean.getObject();
    } catch (Exception e) {
        throw new RuntimeException("Could not create sqlSessionFactory", e);
    }

}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:19,代码来源:DatabaseConfiguration.java

示例2: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //导入方法依赖的package包/类
@Bean
public SqlSessionFactory sqlSessionFactory() {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    DataSource dataSource = dataSource();
    sqlSessionFactoryBean.setDataSource(dataSource);
    String databaseType = initDatabaseType(dataSource);
    if (databaseType == null) {
        throw new FlowableException("couldn't deduct database type");
    }

    try {
        Properties properties = new Properties();
        properties.put("prefix", env.getProperty("datasource.prefix", ""));
        properties.put("blobType", "BLOB");
        properties.put("boolValue", "TRUE");

        properties.load(this.getClass().getClassLoader().getResourceAsStream("org/flowable/db/properties/" + databaseType + ".properties"));

        sqlSessionFactoryBean.setConfigurationProperties(properties);
        sqlSessionFactoryBean
                .setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml"));
        sqlSessionFactoryBean.afterPropertiesSet();
        return sqlSessionFactoryBean.getObject();
    } catch (Exception e) {
        throw new FlowableException("Could not create sqlSessionFactory", e);
    }

}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:29,代码来源:DatabaseConfiguration.java

示例3: initSqlSessionFactories

import org.mybatis.spring.SqlSessionFactoryBean; //导入方法依赖的package包/类
private void initSqlSessionFactories(ConfigurableListableBeanFactory beanFactory) throws Exception {
    Map<String, SqlSessionFactory> sqlSessionFactories = new HashMap<>(this.dataSourceLookup.getMapping().size());

    ReadWriteSplittingDataSource defaultDataSource = null;
    SqlSessionFactory defaultSqlSessionFactory = null;
    for (ReadWriteSplittingDataSource dataSource : this.dataSourceLookup.getMapping().values()) {

        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        sessionFactoryBean.setMapperLocations(mapperLocations);
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setTypeAliasesPackage(this.packageName + ".domain.entity");

        // init 初始化所有sql对应的元数据、资源(sqlNode, sqlSource, mappedStatement)等
        sessionFactoryBean.afterPropertiesSet();

        if (defaultDataSource == null) {
            //第一个
            defaultDataSource = dataSource;
            defaultSqlSessionFactory = sessionFactoryBean.getObject();
        } else {
            SqlSessionFactory newSqlSessionFactory = sessionFactoryBean.getObject();
            Field conf = newSqlSessionFactory.getClass().getDeclaredField("configuration");
            conf.setAccessible(true);
            Configuration newConfiguration = (Configuration) conf.get(newSqlSessionFactory);
            Field mappedStatementField = newConfiguration.getClass().getDeclaredField("mappedStatements");

            //去掉final修饰符
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt( mappedStatementField,  mappedStatementField.getModifiers() & ~Modifier.FINAL);
             mappedStatementField.setAccessible(true);

            //后续的元数据复用
            Configuration defaultConfiguration = defaultSqlSessionFactory.getConfiguration();
            Map<String, MappedStatement> reUsedMappedStatement = (Map)  mappedStatementField.get(defaultConfiguration);
            mappedStatementField.set(newConfiguration, reUsedMappedStatement);
        }
        beanFactory.registerSingleton(dataSource.getName() + "SqlSessionFactory", sessionFactoryBean);
        sqlSessionFactories.put(dataSource.getName(), sessionFactoryBean.getObject());
        defaultSqlSessionFactory = sessionFactoryBean.getObject();
    }

    this.sqlSessionFactoryLookup = new SqlSessionFactoryLookup(sqlSessionFactories);
}
 
开发者ID:baihui212,项目名称:tsharding,代码行数:45,代码来源:MapperScannerWithSharding.java


注:本文中的org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。