public Connection getConnection(MultiDataSourceConnection connectionProxy, String sql) throws SQLException {
MultiDataSource multiDataSource = connectionProxy.getHaDataSource();
Object[] array = multiDataSource.getDataSources().toArray();
DruidDataSource minDataSource = null;
int min = 0;
for (Object item : array) {
DruidDataSource dataSource = (DruidDataSource) item;
if (!dataSource.isEnable()) {
continue;
}
int activeCount = dataSource.getActiveCount();
if (minDataSource == null || activeCount < min) {
minDataSource = dataSource;
min = activeCount;
}
if (activeCount >= maxActive) {
continue;
}
return dataSource.getConnection();
}
if (minDataSource != null) {
return minDataSource.getConnection();
}