org.zodiac.datasource.jdbc.factory.SingleDataSourceFactory Maven / Gradle / Ivy
The newest version!
package org.zodiac.datasource.jdbc.factory;
import javax.sql.DataSource;
import org.zodiac.datasource.jdbc.config.DataSourceRuleInfo;
import java.sql.SQLException;
import java.util.Map;
import java.util.Objects;
public class SingleDataSourceFactory extends BaseDataSourceFactory {
private Map.Entry rule;
public SingleDataSourceFactory(Map.Entry rule) {
Objects.requireNonNull(rule.getValue().getMasterSlave(), () -> "'singleRule' should not be null");
this.rule = rule;
}
@Override
public DataSource getDataSource() throws SQLException {
DataSource dataSource = this.getDataSourceMap(rule).get(rule.getValue().getSingle().getDataSourceRef());
Objects.requireNonNull(dataSource, () -> String.format("'data-source-ref' %s for single-rule %s ",
rule.getValue().getSingle().getDataSourceRef(), rule.getKey()));
return dataSource;
}
}