<NME> DataSourceBuilder.java
<BEF> /**
 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 *  http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jboot.db.datasource;

import com.dangdang.ddframe.rdb.sharding.api.ShardingDataSourceFactory;
import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule;
import com.jfinal.log.Log;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.jboot.db.sharding.IShardingRuleFactory;
import io.jboot.db.sharding.ShardingRuleFactoryBuilder;
import io.jboot.utils.StringUtils;

import javax.sql.DataSource;
import java.sql.SQLException;
public class DataSourceBuilder {

    private DataSourceConfig config;

    public DataSourceBuilder(DataSourceConfig datasourceConfig) {
        this.config = datasourceConfig;
    }

    public DataSource build() {

        String shardingConfigYaml = config.getShardingConfigYaml();

        // 不启用分库分表的配置
        if (StrUtil.isBlank(shardingConfigYaml)) {
            DataSource ds = createDataSource(config);
            return JbootSeataManager.me().wrapDataSource(ds);
        }


        File yamlFile = shardingConfigYaml.startsWith(File.separator)
                ? new File(shardingConfigYaml)
                : new File(PathKit.getRootClassPath(), shardingConfigYaml);

        try {
            return YamlShardingDataSourceFactory.createDataSource(yamlFile);
        } catch (Exception e) {
            throw new JbootException(e);
        }
    }


    private DataSource createDataSource(DataSourceConfig dsc) {

        String factory = dsc.getFactory();
        if (StrUtil.isBlank(factory)) {
            return new HikariDataSourceFactory().createDataSource(dsc);
        }

        switch (factory) {
            case "hikari":
            case "hikariCP":
            case "hikaricp":
                return new HikariDataSourceFactory().createDataSource(dsc);
            case "druid":
                return new DruidDataSourceFactory().createDataSource(dsc);
            default:

        ShardingRule shardingRule = factory.createShardingRule(dataSource);
        try {
            return ShardingDataSourceFactory.createDataSource(shardingRule);
        } catch (SQLException e) {
            log.error("create sharding datasource error." + e.toString(), e);
        }

<MSG> update sharding-jdbc version to 2.0.0

<DFF> @@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * <p>
- *  http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  * <p>
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,14 +15,14 @@
  */
 package io.jboot.db.datasource;
 
-import com.dangdang.ddframe.rdb.sharding.api.ShardingDataSourceFactory;
-import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule;
 import com.jfinal.log.Log;
 import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
 import io.jboot.db.sharding.IShardingRuleFactory;
 import io.jboot.db.sharding.ShardingRuleFactoryBuilder;
 import io.jboot.utils.StringUtils;
+import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource;
+import io.shardingjdbc.core.rule.ShardingRule;
 
 import javax.sql.DataSource;
 import java.sql.SQLException;
@@ -75,7 +75,8 @@ public class DataSourceBuilder {
 
         ShardingRule shardingRule = factory.createShardingRule(dataSource);
         try {
-            return ShardingDataSourceFactory.createDataSource(shardingRule);
+//            return ShardingDataSourceFactory.createDataSource(shardingRule);
+            return new ShardingDataSource(shardingRule);
         } catch (SQLException e) {
             log.error("create sharding datasource error." + e.toString(), e);
         }

{'addition_count': 5, 'commit_subject': 'update sharding-jdbc version to 2.0.0', 'deletion_count': 4, 'file_extension': '.java', 'lang': 'java', 'license': 'apache-2.0', 'repo_name': 'yangfuhai/jboot'}