Search in sources :

Example 1 with ConfigurationService

use of io.shardingjdbc.orchestration.internal.config.ConfigurationService 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 2 with ConfigurationService

use of io.shardingjdbc.orchestration.internal.config.ConfigurationService in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceFactory method createDataSource.

/**
 * Create sharding data source.
 *
 * @param dataSourceMap data source map
 * @param shardingRuleConfig sharding rule configuration
 * @param orchestrationConfig orchestration configuration
 * @param configMap config map
 * @param props properties for data source
 * @return sharding data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final ShardingRuleConfiguration shardingRuleConfig, final Map<String, Object> configMap, final Properties props, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
    OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
    if (null == shardingRuleConfig || shardingRuleConfig.getTableRuleConfigs().isEmpty()) {
        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, shardingRuleConfig, configMap, props, 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 3 with ConfigurationService

use of io.shardingjdbc.orchestration.internal.config.ConfigurationService in project sharding-jdbc by shardingjdbc.

the class OrchestrationMasterSlaveDataSourceFactory method createDataSource.

/**
 * Create master-slave data source.
 *
 * @param dataSourceMap data source map
 * @param yamlMasterSlaveRuleConfig yaml master-slave rule configuration
 * @param orchestrationConfig orchestration configuration
 * @return master-slave data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlMasterSlaveRuleConfiguration yamlMasterSlaveRuleConfig, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
    OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
    if (null == yamlMasterSlaveRuleConfig) {
        ConfigurationService configService = orchestrationFacade.getConfigService();
        final MasterSlaveRuleConfiguration cloudMasterSlaveRuleConfig = configService.loadMasterSlaveRuleConfiguration();
        Preconditions.checkState(null != cloudMasterSlaveRuleConfig, "Missing the master-slave rule configuration on register center");
        return createDataSource(configService.loadDataSourceMap(), cloudMasterSlaveRuleConfig, configService.loadMasterSlaveConfigMap(), orchestrationFacade);
    } else {
        return createDataSource(dataSourceMap, yamlMasterSlaveRuleConfig.getMasterSlaveRuleConfiguration(), yamlMasterSlaveRuleConfig.getConfigMap(), orchestrationFacade);
    }
}
Also used : YamlOrchestrationMasterSlaveRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationMasterSlaveRuleConfiguration) MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) YamlMasterSlaveRuleConfiguration(io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration) OrchestrationFacade(io.shardingjdbc.orchestration.internal.OrchestrationFacade) ConfigurationService(io.shardingjdbc.orchestration.internal.config.ConfigurationService)

Example 4 with ConfigurationService

use of io.shardingjdbc.orchestration.internal.config.ConfigurationService in project sharding-jdbc by shardingjdbc.

the class OrchestrationMasterSlaveDataSourceFactory method createDataSource.

/**
 * Create master-slave data source.
 *
 * @param dataSourceMap data source map
 * @param masterSlaveRuleConfig master-slave rule configuration
 * @param orchestrationConfig orchestration configuration
 * @param configMap config map
 * @return master-slave data source
 * @throws SQLException SQL exception
 */
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final MasterSlaveRuleConfiguration masterSlaveRuleConfig, final Map<String, Object> configMap, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
    OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
    if (null == masterSlaveRuleConfig || null == masterSlaveRuleConfig.getMasterDataSourceName()) {
        ConfigurationService configService = orchestrationFacade.getConfigService();
        final MasterSlaveRuleConfiguration cloudMasterSlaveRuleConfig = configService.loadMasterSlaveRuleConfiguration();
        Preconditions.checkState(null != cloudMasterSlaveRuleConfig, "Missing the master-slave rule configuration on register center");
        return createDataSource(configService.loadDataSourceMap(), cloudMasterSlaveRuleConfig, configService.loadMasterSlaveConfigMap(), orchestrationFacade);
    } else {
        return createDataSource(dataSourceMap, masterSlaveRuleConfig, configMap, orchestrationFacade);
    }
}
Also used : YamlOrchestrationMasterSlaveRuleConfiguration(io.shardingjdbc.orchestration.yaml.YamlOrchestrationMasterSlaveRuleConfiguration) MasterSlaveRuleConfiguration(io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration) YamlMasterSlaveRuleConfiguration(io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration) OrchestrationFacade(io.shardingjdbc.orchestration.internal.OrchestrationFacade) ConfigurationService(io.shardingjdbc.orchestration.internal.config.ConfigurationService)

Aggregations

OrchestrationFacade (io.shardingjdbc.orchestration.internal.OrchestrationFacade)4 ConfigurationService (io.shardingjdbc.orchestration.internal.config.ConfigurationService)4 MasterSlaveRuleConfiguration (io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration)2 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)2 YamlMasterSlaveRuleConfiguration (io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration)2 YamlShardingRuleConfiguration (io.shardingjdbc.core.yaml.sharding.YamlShardingRuleConfiguration)2 YamlOrchestrationMasterSlaveRuleConfiguration (io.shardingjdbc.orchestration.yaml.YamlOrchestrationMasterSlaveRuleConfiguration)2 YamlOrchestrationShardingRuleConfiguration (io.shardingjdbc.orchestration.yaml.YamlOrchestrationShardingRuleConfiguration)2