提交 17289461 编写于 作者: T terrymanu

For #647: refactor MasterSlaveDataSourceFactory

上级 4889d6a3
......@@ -65,7 +65,7 @@ public final class MasterSlaveDataSourceFactory {
*/
public static DataSource createDataSource(final File yamlFile) throws SQLException, IOException {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlFile);
return new MasterSlaveDataSource(config.getDataSources(), config.getMasterSlaveRule().getMasterSlaveRuleConfiguration().build(), config.getMasterSlaveRule().getConfigMap());
return createDataSource(config.getDataSources(), config.getMasterSlaveRule().getMasterSlaveRuleConfiguration(), config.getMasterSlaveRule().getConfigMap());
}
/**
......@@ -73,15 +73,14 @@ public final class MasterSlaveDataSourceFactory {
*
* <p>One master data source can configure multiple slave data source.</p>
*
* @param dataSourceMap data source map
* @param yamlFile yaml file for master-slave rule configuration without data sources
* @param yamlBytes yaml bytes for master-slave rule configuration with data sources
* @return master-slave 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 {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlFile);
return new MasterSlaveDataSource(dataSourceMap, config.getMasterSlaveRule().getMasterSlaveRuleConfiguration().build(), config.getMasterSlaveRule().getConfigMap());
public static DataSource createDataSource(final byte[] yamlBytes) throws SQLException, IOException {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlBytes);
return createDataSource(config.getDataSources(), config.getMasterSlaveRule().getMasterSlaveRuleConfiguration(), config.getMasterSlaveRule().getConfigMap());
}
/**
......@@ -89,14 +88,15 @@ public final class MasterSlaveDataSourceFactory {
*
* <p>One master data source can configure multiple slave data source.</p>
*
* @param yamlBytes yaml bytes for master-slave rule configuration with data sources
* @param dataSourceMap data source map
* @param yamlFile yaml file for master-slave rule configuration without data sources
* @return master-slave data source
* @throws SQLException SQL exception
* @throws IOException IO exception
*/
public static DataSource createDataSource(final byte[] yamlBytes) throws SQLException, IOException {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlBytes);
return new MasterSlaveDataSource(config.getDataSources(), config.getMasterSlaveRule().getMasterSlaveRuleConfiguration().build(), config.getMasterSlaveRule().getConfigMap());
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final File yamlFile) throws SQLException, IOException {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlFile);
return createDataSource(dataSourceMap, config.getMasterSlaveRule().getMasterSlaveRuleConfiguration(), config.getMasterSlaveRule().getConfigMap());
}
/**
......@@ -112,6 +112,6 @@ public final class MasterSlaveDataSourceFactory {
*/
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final byte[] yamlBytes) throws SQLException, IOException {
YamlMasterSlaveConfiguration config = YamlMasterSlaveConfiguration.unmarshal(yamlBytes);
return new MasterSlaveDataSource(dataSourceMap, config.getMasterSlaveRule().getMasterSlaveRuleConfiguration().build(), config.getMasterSlaveRule().getConfigMap());
return createDataSource(dataSourceMap, config.getMasterSlaveRule().getMasterSlaveRuleConfiguration(), config.getMasterSlaveRule().getConfigMap());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册