DataSourceProxyImpl dataSource = proxyDataSources.get(url);
if (dataSource == null) {
String restUrl = url.substring(DEFAULT_PREFIX.length());
DataSourceProxyConfig config;
config = new DataSourceProxyConfig();
List<AbstractDruidFilterConfig> druidFilterConfigList = new ArrayList<AbstractDruidFilterConfig>();
String configFile = info.getProperty(CONFIG_PREFIX);
if (configFile != null) {
DruidFilterConfigLoader.loadConfig(configFile.trim(), druidFilterConfigList);
}
if (restUrl.startsWith(DRIVER_PREFIX)) {
int pos = restUrl.indexOf(':', DRIVER_PREFIX.length());
String driverText = restUrl.substring(DRIVER_PREFIX.length(), pos);
if (driverText.length() > 0) {
config.setRawDriverClassName(driverText.trim());
}
restUrl = restUrl.substring(pos + 1);
}
if (restUrl.startsWith(FILTERS_PREFIX)) {
int pos = restUrl.indexOf(':', FILTERS_PREFIX.length());
String filtersText = restUrl.substring(FILTERS_PREFIX.length(), pos);
for (String filterItem : filtersText.split(",")) {
DruidLoaderUtils.loadFilter(config.getFilters(), filterItem);
}
restUrl = restUrl.substring(pos + 1);
}
// 如果url中并无定义filter 采用配置
if (config.getFilters().size() <= 0) {
DruidLoaderUtils.loadFilter(config.getFilters(), druidFilterConfigList);
}
if (restUrl.startsWith(NAME_PREFIX)) {
int pos = restUrl.indexOf(':', NAME_PREFIX.length());
String name = restUrl.substring(NAME_PREFIX.length(), pos);
config.setName(name);
restUrl = restUrl.substring(pos + 1);
}
if (restUrl.startsWith(JMX_PREFIX)) {
int pos = restUrl.indexOf(':', JMX_PREFIX.length());
String jmxOption = restUrl.substring(JMX_PREFIX.length(), pos);
config.setJmxOption(jmxOption);
restUrl = restUrl.substring(pos + 1);
}
String rawUrl = restUrl;
config.setRawUrl(rawUrl);
if (config.getRawDriverClassName() == null) {
String rawDriverClassname = JdbcUtils.getDriverClassName(rawUrl);
config.setRawDriverClassName(rawDriverClassname);
}
config.setUrl(url);
Driver rawDriver = createDriver(config.getRawDriverClassName());
DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);
{
int dataSourceId = createDataSourceId();
newDataSource.setId(dataSourceId);
for (Filter filter : config.getFilters()) {
filter.init(newDataSource);
}
}
DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource); // 多线程处理需要
if (oldDataSource == null) {
// 放进去的线程负责注册MBean
if (config.isJmxOption()) {
JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
}
}
dataSource = proxyDataSources.get(url);