// Path: src/main/java/com/github/mybatis/util/CloseableUtil.java
// public class CloseableUtil {
//   private CloseableUtil() {
//   }
// 
//   public static void closeQuietly(AutoCloseable c) {
//     if (c != null) {
//       try {
//         c.close();
//       } catch (Exception ignored) {
//       }
//     }
//   }
// }


import com.alibaba.druid.pool.DruidDataSource;
import com.github.autoconf.ConfigFactory;
import com.github.autoconf.api.IChangeListener;
import com.github.autoconf.api.IConfig;
import com.github.autoconf.api.IConfigFactory;
import com.github.mybatis.util.CloseableUtil;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.reflect.Reflection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.AbstractDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
      configFactory = ConfigFactory.getInstance();
    }
    configFactory.getConfig(configName, new IChangeListener() {
      @Override
      public void changed(IConfig conf) {
        String masterUrl = conf.get("masterUrl");
        if (Strings.isNullOrEmpty(masterUrl)) {
          LOG.error("cannot init {}", conf.getName());
          return;
        }
        String username = conf.get("username");
        String password = conf.get("password");
        // 分开读和写的接口，这样互不影响，必要时可以停止读或者写
        DruidDataSource writer = buildDruidDataSource("master", masterUrl, username, password);
        String slaveUrl = conf.get("slaveUrl");
        if (Strings.isNullOrEmpty(slaveUrl)) {
          slaveUrl = masterUrl;
        }
        DruidDataSource reader = buildDruidDataSource("slave", slaveUrl, username, password);

        List<DruidDataSource> ds = Lists.newArrayList();
        if (DynamicDataSource.this.writer != null) {
          ds.add(DynamicDataSource.this.writer);
        }
        if (DynamicDataSource.this.reader != null) {
          ds.add(DynamicDataSource.this.reader);
        }
        DynamicDataSource.this.writer = writer;
        DynamicDataSource.this.reader = reader;
        for (DruidDataSource i : ds) {
// Path: src/main/java/com/github/mybatis/util/CloseableUtil.java
// public class CloseableUtil {
//   private CloseableUtil() {
//   }
// 
//   public static void closeQuietly(AutoCloseable c) {
//     if (c != null) {
//       try {
//         c.close();
//       } catch (Exception ignored) {
//       }
//     }
//   }
// }


// Path: src/main/java/com/github/mybatis/spring/DynamicDataSource.java
import com.alibaba.druid.pool.DruidDataSource;
import com.github.autoconf.ConfigFactory;
import com.github.autoconf.api.IChangeListener;
import com.github.autoconf.api.IConfig;
import com.github.autoconf.api.IConfigFactory;
import com.github.mybatis.util.CloseableUtil;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.reflect.Reflection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.AbstractDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

      configFactory = ConfigFactory.getInstance();
    }
    configFactory.getConfig(configName, new IChangeListener() {
      @Override
      public void changed(IConfig conf) {
        String masterUrl = conf.get("masterUrl");
        if (Strings.isNullOrEmpty(masterUrl)) {
          LOG.error("cannot init {}", conf.getName());
          return;
        }
        String username = conf.get("username");
        String password = conf.get("password");
        // 分开读和写的接口，这样互不影响，必要时可以停止读或者写
        DruidDataSource writer = buildDruidDataSource("master", masterUrl, username, password);
        String slaveUrl = conf.get("slaveUrl");
        if (Strings.isNullOrEmpty(slaveUrl)) {
          slaveUrl = masterUrl;
        }
        DruidDataSource reader = buildDruidDataSource("slave", slaveUrl, username, password);

        List<DruidDataSource> ds = Lists.newArrayList();
        if (DynamicDataSource.this.writer != null) {
          ds.add(DynamicDataSource.this.writer);
        }
        if (DynamicDataSource.this.reader != null) {
          ds.add(DynamicDataSource.this.reader);
        }
        DynamicDataSource.this.writer = writer;
        DynamicDataSource.this.reader = reader;
        for (DruidDataSource i : ds) {
          CloseableUtil.closeQuietly(i);