class DynamicDataSource extends AbstractRoutingDataSource implements DataSource {
    public DynamicDataSource() {

    }

    public DynamicDataSource(Properties props) {
        if (props == null || props.size() == 0) {
            //缺少配置
            throw new IllegalStateException("Missing dynamic data source configuration");
        }

        String strictStr = props.getProperty("strict", "false");
        props.remove("strict");
        String defaultStr = props.getProperty("default", "default");
        props.remove("default");

        Map<String, DataSource> dataSourceMap = DsUtils.buildDsMap(props);

        //::获取默认数据源
        DataSource defSource = dataSourceMap.get(defaultStr);

        if (defSource == null) {
            defSource = dataSourceMap.get("master");
        }

        if (defSource == null) {
            throw new IllegalStateException("Missing default data source configuration");
        }

        //::初始化
        setStrict(Boolean.parseBoolean(strictStr));
        setTargetDataSources(dataSourceMap);
        setDefaultTargetDataSource(defSource);
    }

    /**
     * 添加目标数据源
     *
     * @since 2.4
     */
    public void addTargetDataSource(String name, DataSource dataSource) {<FILL_FUNCTION_BODY>}

    /**
     * 添加目标数据源集合
     *
     * @since 2.4
     */
    public void addTargetDataSourceAll(Map<String, DataSource> targetDataSources) {
        if (Utils.isEmpty(targetDataSources)) {
            throw new IllegalArgumentException("Property 'targetDataSources' is required");
        }

        targetDataSources.putAll(targetDataSources);
    }

    /**
     * 移除数据源
     */
    public void removeTargetDataSource(String name) throws IOException {
        if (targetDataSources == null) {
            return;
        }

        DataSource ds = targetDataSources.remove(name);
        if (ds != null) {
            closeDataSource(ds);
        }
    }

    /**
     * 获取数据源
     */
    public @Nullable DataSource getTargetDataSource(String name) {
        return targetDataSources.get(name);
    }

    /**
     * 获取数据源
     */
    public DataSource getDefaultTargetDataSource() {
        return defaultTargetDataSource;
    }

    /**
     * 设置当前数据源名
     * */
    public void setCurrentKey(String name){
        DynamicDsKey.setCurrent(name);
    }

    @Override
    protected String determineCurrentKey() {
        return DynamicDsKey.getCurrent();
    }
}

        if (targetDataSources == null) {
            targetDataSources = new LinkedHashMap<>();
        }

        targetDataSources.put(name, dataSource);
    
<methods>public non-sealed void <init>() ,public void close() throws java.io.IOException,public java.sql.Connection getConnection() throws java.sql.SQLException,public java.sql.Connection getConnection(java.lang.String, java.lang.String) throws java.sql.SQLException,public java.io.PrintWriter getLogWriter() throws java.sql.SQLException,public int getLoginTimeout() throws java.sql.SQLException,public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException,public boolean isWrapperFor(Class<?>) throws java.sql.SQLException,public void setDefaultTargetDataSource(javax.sql.DataSource) ,public void setLogWriter(java.io.PrintWriter) throws java.sql.SQLException,public void setLoginTimeout(int) throws java.sql.SQLException,public void setStrict(boolean) ,public void setTargetDataSources(Map<java.lang.String,javax.sql.DataSource>) ,public T unwrap(Class<T>) throws java.sql.SQLException<variables>protected javax.sql.DataSource defaultTargetDataSource,protected boolean strict,protected Map<java.lang.String,javax.sql.DataSource> targetDataSources