Java Code Examples for org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory

The following examples show how to use org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory. These examples are extracted from open source projects. 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 Project: jboot   Source File: DataSourceBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public DataSource build() {

        String shardingConfigYaml = config.getShardingConfigYaml();

        // 不启用分库分表的配置
        if (StrUtil.isBlank(shardingConfigYaml)) {
            DataSource ds = createDataSource(config);
            return JbootSeataManager.me().wrapDataSource(ds);
        }


        File yamlFile = shardingConfigYaml.startsWith(File.separator)
                ? new File(shardingConfigYaml)
                : new File(PathKit.getRootClassPath(), shardingConfigYaml);

        try {
            return YamlShardingDataSourceFactory.createDataSource(yamlFile);
        } catch (Exception e) {
            throw new JbootException(e);
        }
    }
 
Example 2
public static void main(final String[] args) throws SQLException, IOException {
    DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getFile(configFile));
    CommonService commonService = getCommonService(dataSource);
    commonService.initEnvironment();
    processSagaTransaction(dataSource, commonService);
    commonService.cleanEnvironment();
}
 
Example 3
public static void main(final String[] args) throws SQLException, IOException {
    DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getFile(configFile));
    CommonService commonService = getCommonService(dataSource);
    commonService.initEnvironment();
    processSeataTransaction(dataSource, commonService);
    commonService.cleanEnvironment();
}
 
Example 4
public static void main(final String[] args) throws SQLException, IOException {
    DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getFile(configFile));
    CommonService commonService = getCommonService(dataSource);
    commonService.initEnvironment();
    processXATransaction(dataSource, commonService);
    commonService.cleanEnvironment();
}
 
Example 5
Source Project: MicroCommunity   Source File: DataSourceConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 构建dataSource
     * 这里没有使用ShardingDataSourceFactory
     * 因为要为durid数据源配置监听Filter
     *
     * @return 数据源对象
     * @throws SQLException sql异常
     * @throws IOException  IO 异常
     * @since 1.8
     */
    @Bean
    public DataSource dataSource() throws SQLException, IOException {
//        YamlShardingConfiguration config = parse();
//        YamlShardingRuleConfiguration rule = config.getShardingRule();
//        for (String key : config.getDataSources().keySet()) {
//            DruidDataSource d = (DruidDataSource) config.getDataSources().get(key);
//            d.setProxyFilters(Lists.newArrayList(statFilter));
//        }
//        return ShardingDataSourceFactory.createDataSource(config.getDataSources(),
//                rule.getShardingRuleConfiguration(), config.getConfigMap(), config.getProps());

        return YamlShardingDataSourceFactory.createDataSource(getYmlFile());
    }