Пример #1
0
  @Override
  public String[] getFilterClasses() {
    List<Filter> filterConfigList = config.getFilters();

    List<String> classes = new ArrayList<String>();
    for (Filter filter : filterConfigList) {
      classes.add(filter.getClass().getName());
    }

    return classes.toArray(new String[classes.size()]);
  }
Пример #2
0
  /**
   * 参数定义: com.alibaba.druid.log.LogFilter=filter com.alibaba.druid.log.LogFilter.p1=prop-value
   * com.alibaba.druid.log.LogFilter.p2=prop-value
   *
   * @param url
   * @return
   * @throws SQLException
   */
  private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
    DataSourceProxyImpl dataSource = proxyDataSources.get(url);

    if (dataSource == null) {
      DataSourceProxyConfig config = parseConfig(url, info);

      Driver rawDriver = createDriver(config.getRawDriverClassName());

      DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);

      {
        String property = System.getProperty("druid.filters");
        if (property != null && property.length() > 0) {
          for (String filterItem : property.split(",")) {
            FilterManager.loadFilter(config.getFilters(), filterItem);
          }
        }
      }
      {
        int dataSourceId = createDataSourceId();
        newDataSource.setId(dataSourceId);

        for (Filter filter : config.getFilters()) {
          filter.init(newDataSource);
        }
      }

      DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
      if (oldDataSource == null) {
        if (config.isJmxOption()) {
          JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
        }
      }

      dataSource = proxyDataSources.get(url);
    }
    return dataSource;
  }