Search in sources :

Example 1 with YamlShardingRuleConfiguration

use of io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param dataSourceMap data source map
 * @param yamlFile yaml file for rule configuration of databases and tables sharding without data sources
 * @return sharding data source
 * @throws SQLException SQL exception
 * @throws IOException IO exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final File yamlFile) throws SQLException, IOException {
    YamlOrchestrationShardingRuleConfiguration config = unmarshal(yamlFile);
    YamlShardingRuleConfiguration shardingRuleConfig = config.getShardingRule();
    return createDataSource(dataSourceMap, shardingRuleConfig, config.getOrchestration().getOrchestrationConfiguration());
}
Also used : YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)

Example 2 with YamlShardingRuleConfiguration

use of io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param yamlByteArray yaml byte array for rule configuration of databases and tables sharding with data sources
 * @return sharding data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final byte[] yamlByteArray) throws SQLException {
    YamlOrchestrationShardingRuleConfiguration config = unmarshal(yamlByteArray);
    YamlShardingRuleConfiguration shardingRuleConfig = config.getShardingRule();
    return createDataSource(config.getDataSources(), shardingRuleConfig, config.getOrchestration().getOrchestrationConfiguration());
}
Also used : YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)

Example 3 with YamlShardingRuleConfiguration

use of io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param dataSourceMap data source map
 * @param yamlShardingRuleConfig yaml sharding rule configuration
 * @param orchestrationConfig orchestration configuration
 * @return sharding data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlShardingRuleConfiguration yamlShardingRuleConfig, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
    OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
    if (null == yamlShardingRuleConfig) {
        ConfigurationService configService = orchestrationFacade.getConfigService();
        final ShardingRuleConfiguration cloudShardingRuleConfig = configService.loadShardingRuleConfiguration();
        Preconditions.checkState(null != cloudShardingRuleConfig, "Missing the sharding rule configuration on register center");
        return createDataSource(configService.loadDataSourceMap(), cloudShardingRuleConfig, configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
    } else {
        return createDataSource(dataSourceMap, yamlShardingRuleConfig.getShardingRuleConfiguration(), yamlShardingRuleConfig.getConfigMap(), yamlShardingRuleConfig.getProps(), orchestrationFacade);
    }
}
Also used : YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration) YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) OrchestrationFacade(io.shardingjdbc.orchestration.internal.OrchestrationFacade) ConfigurationService(io.shardingjdbc.orchestration.internal.config.ConfigurationService)

Example 4 with YamlShardingRuleConfiguration

use of io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param dataSourceMap data source map
 * @param yamlByteArray yaml byte array for rule configuration of databases and tables sharding without data sources
 * @return sharding data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final byte[] yamlByteArray) throws SQLException {
    YamlOrchestrationShardingRuleConfiguration config = unmarshal(yamlByteArray);
    YamlShardingRuleConfiguration shardingRuleConfig = config.getShardingRule();
    return createDataSource(dataSourceMap, shardingRuleConfig, config.getOrchestration().getOrchestrationConfiguration());
}
Also used : YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)

Example 5 with YamlShardingRuleConfiguration

use of io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param yamlFile yaml file for rule configuration of databases and tables sharding with data sources
 * @return sharding data source
 * @throws SQLException SQL exception
 * @throws IOException IO exception
 */
public static DataSource createDataSource(final File yamlFile) throws SQLException, IOException {
    YamlOrchestrationShardingRuleConfiguration config = unmarshal(yamlFile);
    YamlShardingRuleConfiguration shardingRuleConfig = config.getShardingRule();
    return createDataSource(config.getDataSources(), shardingRuleConfig, config.getOrchestration().getOrchestrationConfiguration());
}
Also used : YamlOrchestrationShardingRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration) YamlShardingRuleConfiguration(io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)

Aggregations

YamlShardingRuleConfiguration (io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)5 YamlOrchestrationShardingRuleConfiguration (io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration)5 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)1 OrchestrationFacade (io.shardingjdbc.orchestration.internal.OrchestrationFacade)1 ConfigurationService (io.shardingjdbc.orchestration.internal.config.ConfigurationService)1