Package com.alibaba.druid.pool.ha

Examples of com.alibaba.druid.pool.ha.DataSourceHolder


            throw new SQLException("can not get connection, no availabe datasources");
        }

        int index = (int) (connectionId % size);

        DataSourceHolder first = null;
        DataSourceHolder dataSource = null;

        try {
            int itemIndex = 0;
            for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
                if (!item.isEnable()) {
View Full Code Here


                        return;
                    }
                }
            }
        } else {
            DataSourceHolder holder = createDataSourceHolder(this.url, 1);
            this.addDataSource("master", holder);
        }
    }
View Full Code Here

        if (filters != null && !filters.isEmpty()) {
            dataSource.setFilters(filters);
        }
        dataSource.setProxyFilters(proxyFilters);

        DataSourceHolder holder = new DataSourceHolder(this, dataSource);
        holder.setWeight(weight);
        return holder;
    }
View Full Code Here

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;

        int randomNumber = produceRandomNumber();
        DataSourceHolder first = null;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }
View Full Code Here

    @Override
    public MultiConnectionHolder getConnection(MultiDataSourceConnection conn, String sql) throws SQLException {
        MultiDataSource multiDataSource = conn.getMultiDataSource();

        DataSourceHolder dataSource = null;
        int leastCount = -1;

        for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
            if (!item.isEnable()) {
                continue;
            }

            int activeCount = item.getDataSource().getActiveCount();
            if (dataSource == null) {
                leastCount = activeCount;
                dataSource = item;
            } else {
                if (leastCount > item.getDataSource().getActiveCount()) {
                    dataSource = item;
                    leastCount = activeCount;
                }
            }
        }

        if (dataSource == null) {
            throw new SQLException("can not get real connection, enableDataSourceCount "
                                   + multiDataSource.getEnabledDataSourceCount());
        }

        return dataSource.getConnection();
    }
View Full Code Here

            throw new SQLException("can not get connection, no availabe datasources");
        }

        int index = (int) (connectionId % size);

        DataSourceHolder first = null;
        DataSourceHolder dataSource = null;

        try {
            int itemIndex = 0;
            for (DataSourceHolder item : multiDataSource.getDataSources().values()) {
                if (!item.isEnable()) {
View Full Code Here

                        return;
                    }
                }
            }
        } else {
            DataSourceHolder holder = createDataSourceHolder(this.url, 1);
            this.addDataSource("master", holder);
        }
    }
View Full Code Here

        if (filters != null && !filters.isEmpty()) {
            dataSource.setFilters(filters);
        }
        dataSource.setProxyFilters(proxyFilters);

        DataSourceHolder holder = new DataSourceHolder(this, dataSource);
        holder.setWeight(weight);
        return holder;
    }
View Full Code Here

            int weight = (Integer) item.get("weight");

            String key = ip + ":" + port + "/" + schema;
            keys.add(key);

            DataSourceHolder holder = dataSource.getDataSourceHolder(key);

            if (holder == null) {
                String jdbcUrl = createJdbcUrl(ip, port, schema);
                holder = dataSource.createDataSourceHolder(jdbcUrl, weight);
                dataSource.addDataSource(key, holder);
            } else {
                if (holder.getWeight() != weight) {
                    holder.setWeight(weight);
                    dataSource.afterDataSourceChanged(null);
                }
            }
        }
View Full Code Here

            int weight = item.getIntValue("weight");

            String key = ip + ":" + port + "/" + schema;
            keys.add(key);

            DataSourceHolder holder = dataSource.getDataSourceHolder(key);

            if (holder == null) {
                String jdbcUrl = createJdbcUrl(ip, port, schema);
                holder = dataSource.createDataSourceHolder(jdbcUrl, weight);
                dataSource.addDataSource(key, holder);
            } else {
                if (holder.getWeight() != weight) {
                    holder.setWeight(weight);
                    dataSource.afterDataSourceChanged(null);
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.pool.ha.DataSourceHolder

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.