Package com.alibaba.druid.proxy.jdbc

Examples of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig


            if (this.jdbcUrl != null) {
                this.jdbcUrl = this.jdbcUrl.trim();

                if (jdbcUrl.startsWith(DruidDriver.DEFAULT_PREFIX)) {
                    DataSourceProxyConfig config = DruidDriver.parseConfig(jdbcUrl, null);
                    this.driverClass = config.getRawDriverClassName();
                    this.jdbcUrl = config.getRawUrl();
                    if (this.name == null) {
                        this.name = config.getName();
                    }
                    this.filters.addAll(config.getFilters());
                }
            }

            if (this.driver == null) {
                if (this.driverClass == null || this.driverClass.isEmpty()) {
View Full Code Here


     */
    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(",")) {
                        DruidLoaderUtils.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);
View Full Code Here

    }

    public static DataSourceProxyConfig parseConfig(String url, Properties info) throws SQLException {
        String restUrl = url.substring(DEFAULT_PREFIX.length());

        DataSourceProxyConfig config = new DataSourceProxyConfig();

        List<AbstractDruidFilterConfig> druidFilterConfigList = new ArrayList<AbstractDruidFilterConfig>();

        if (info != null) {
            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);
        return config;
    }
View Full Code Here

        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);
View Full Code Here

    private void initFromWrapDriverUrl() throws SQLException {
        if (!jdbcUrl.startsWith(DruidDriver.DEFAULT_PREFIX)) {
            return;
        }

        DataSourceProxyConfig config = DruidDriver.parseConfig(jdbcUrl, null);
        this.driverClass = config.getRawDriverClassName();

        LOG.error("error url : '" + jdbcUrl + "', it should be : '" + config.getRawUrl() + "'");

        this.jdbcUrl = config.getRawUrl();
        if (this.name == null) {
            this.name = config.getName();
        }

        for (Filter filter : config.getFilters()) {
            addFilter(filter);
        }
    }
View Full Code Here

     */
    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);
View Full Code Here

    }

    public static DataSourceProxyConfig parseConfig(String url, Properties info) throws SQLException {
        String restUrl = url.substring(DEFAULT_PREFIX.length());

        DataSourceProxyConfig config = new DataSourceProxyConfig();

        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(",")) {
                FilterManager.loadFilter(config.getFilters(), filterItem);
            }
            restUrl = restUrl.substring(pos + 1);
        }

        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);
        return config;
    }
View Full Code Here

    private void initFromWrapDriverUrl() throws SQLException {
        if (!jdbcUrl.startsWith(DruidDriver.DEFAULT_PREFIX)) {
            return;
        }

        DataSourceProxyConfig config = DruidDriver.parseConfig(jdbcUrl, null);
        this.driverClass = config.getRawDriverClassName();

        LOG.error("error url : '" + jdbcUrl + "', it should be : '" + config.getRawUrl() + "'");

        this.jdbcUrl = config.getRawUrl();
        if (this.name == null) {
            this.name = config.getName();
        }

        for (Filter filter : config.getFilters()) {
            addFilter(filter);
        }
    }
View Full Code Here

    private void initFromWrapDriverUrl() throws SQLException {
        if (!jdbcUrl.startsWith(DruidDriver.DEFAULT_PREFIX)) {
            return;
        }

        DataSourceProxyConfig config = DruidDriver.parseConfig(jdbcUrl, null);
        this.driverClass = config.getRawDriverClassName();

        LOG.error("error url : '" + jdbcUrl + "', it should be : '" + config.getRawUrl() + "'");

        this.jdbcUrl = config.getRawUrl();
        if (this.name == null) {
            this.name = config.getName();
        }

        for (Filter filter : config.getFilters()) {
            addFilter(filter);
        }
    }
View Full Code Here

    private void initFromWrapDriverUrl() throws SQLException {
        if (!jdbcUrl.startsWith(DruidDriver.DEFAULT_PREFIX)) {
            return;
        }

        DataSourceProxyConfig config = DruidDriver.parseConfig(jdbcUrl, null);
        this.driverClass = config.getRawDriverClassName();

        LOG.error("error url : '" + jdbcUrl + "', it should be : '" + config.getRawUrl() + "'");

        this.jdbcUrl = config.getRawUrl();
        if (this.name == null) {
            this.name = config.getName();
        }

        for (Filter filter : config.getFilters()) {
            addFilter(filter);
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.