Skip to content

Commit

Permalink
For apache#647: refactor MasterSlaveDataSourceFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Mar 23, 2018
1 parent 4889d6a commit 1728946
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,38 @@ public static DataSource createDataSource(
*/
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());
}

/**
* Create master-slave data source.
*
* <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());
}

/**
* Create master-slave data source.
*
* <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());
}

/**
Expand All @@ -112,6 +112,6 @@ public static DataSource createDataSource(final byte[] yamlBytes) throws SQLExce
*/
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());
}
}

0 comments on commit 1728946

Please sign in to comment.