public PooledDataSource(
     ClassLoader driverClassLoader, String driver, String url, Properties driverProperties) {
   dataSource = new UnpooledDataSource(driverClassLoader, driver, url, driverProperties);
   expectedConnectionTypeCode =
       assembleConnectionTypeCode(
           dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
 }
  /*
   * Closes all active and idle connections in the pool
   */
  public void forceCloseAll() { // 关闭pool里的所有连接,两个list中的连接都移除且关闭
    synchronized (state) {
      expectedConnectionTypeCode =
          assembleConnectionTypeCode(
              dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
      for (int i = state.activeConnections.size(); i > 0; i--) { // 遍历活动连接list
        try {
          PooledConnection conn = state.activeConnections.remove(i - 1); // 从活动连接list移出
          conn.invalidate(); // PooledConnection的valid设为false

          Connection realConn = conn.getRealConnection(); // 获取真conn (java.sql.Connection)
          if (!realConn.getAutoCommit()) { // 不是自动提交的话
            realConn.rollback(); // 回滚
          }
          realConn.close();
        } catch (Exception e) {
          // ignore
        }
      }
      for (int i = state.idleConnections.size(); i > 0; i--) { // 简历空闲连接list
        try {
          PooledConnection conn = state.idleConnections.remove(i - 1);
          conn.invalidate();

          Connection realConn = conn.getRealConnection();
          if (!realConn.getAutoCommit()) {
            realConn.rollback();
          }
          realConn.close();
        } catch (Exception e) {
          // ignore
        }
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("PooledDataSource forcefully closed/removed all connections.");
    }
  }
  /*
   * Closes all active and idle connections in the pool
   */
  public void forceCloseAll() {
    synchronized (state) {
      expectedConnectionTypeCode =
          assembleConnectionTypeCode(
              dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
      for (int i = state.activeConnections.size(); i > 0; i--) {
        try {
          PooledConnection conn = (PooledConnection) state.activeConnections.remove(i - 1);
          conn.invalidate();

          Connection realConn = conn.getRealConnection();
          if (!realConn.getAutoCommit()) {
            realConn.rollback();
          }
          realConn.close();
        } catch (Exception e) {
          // ignore
        }
      }
      for (int i = state.idleConnections.size(); i > 0; i--) {
        try {
          PooledConnection conn = (PooledConnection) state.idleConnections.remove(i - 1);
          conn.invalidate();

          Connection realConn = conn.getRealConnection();
          if (!realConn.getAutoCommit()) {
            realConn.rollback();
          }
          realConn.close();
        } catch (Exception e) {
          // ignore
        }
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("PooledDataSource forcefully closed/removed all connections.");
    }
  }
 @Override
 public Connection getConnection()
     throws SQLException { // 获得连接,即popConnection(...).getProxyConnection()获得代理连接
   return popConnection(dataSource.getUsername(), dataSource.getPassword()).getProxyConnection();
 }
 public PooledDataSource(String driver, String url, String username, String password) {
   dataSource = new UnpooledDataSource(driver, url, username, password);
   expectedConnectionTypeCode =
       assembleConnectionTypeCode(
           dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
 }
 public String getUsername() {
   return dataSource.getUsername();
 }
 public Connection getConnection() throws SQLException {
   return popConnection(dataSource.getUsername(), dataSource.getPassword()).getProxyConnection();
 }