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

The following examples show how to use org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory. 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: DataSourceBuilder.java    From jboot with 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
Source File: YamlConfigurationTransactionExample.java    From opensharding-spi-impl-example with Apache License 2.0 5 votes vote down vote up
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
Source File: YamlConfigurationTransactionExample.java    From opensharding-spi-impl-example with Apache License 2.0 5 votes vote down vote up
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
Source File: YamlConfigurationTransactionExample.java    From opensharding-spi-impl-example with Apache License 2.0 5 votes vote down vote up
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 File: DataSourceConfig.java    From MicroCommunity with 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());
    }