/**
   * Gets available open connections.
   *
   * @return array of open connections with parameters
   */
  public ConnectionWithParams[] getConnectedConnections() {
    Iterator iter = connections.keySet().iterator();
    if (!iter.hasNext()) return null;

    ArrayList aux = new ArrayList();

    while (iter.hasNext()) {
      ConnectionWithParams _cwp = (ConnectionWithParams) connections.get(iter.next());
      if (_cwp.isConnected()) {
        aux.add(_cwp);
      }
    }

    ConnectionWithParams[] resp = new ConnectionWithParams[aux.size()];
    for (int i = 0; i < aux.size(); i++) {
      resp[i] = (ConnectionWithParams) aux.get(i);
    }
    return resp;
  }
  /**
   * Creates a new connection with its parameters if not created yet.
   *
   * @param _drvName driver name
   * @param _user user name
   * @param _pw password
   * @param _name connection name
   * @param _host host url
   * @param _port port number as string
   * @param _db database name
   * @param _schema schema name
   * @param _connected whether or not to connect the connection
   * @return the connection with parameters object
   * @throws SQLException
   */
  public ConnectionWithParams getConnection(
      String _drvName,
      String _user,
      String _pw,
      String _name,
      String _host,
      String _port,
      String _db,
      String _schema,
      boolean _connected)
      throws DBException {

    // IVectorialDatabaseDriver drv =
    Driver _drv = getInstanceFromName(_drvName);

    if (_drv == null) return null;

    String conn_str = getConnStringForDriver(_drv, _host, _port, _db, _user, _pw);
    String key = getConnectionKey(_drvName, _host, _db, _port, _user);

    if (!connections.containsKey(key)) {

      ConnectionWithParams cwp = null;

      if (_connected) {
        IConnection new_connection;

        try {
          new_connection = getConnectionForDriver(_drv, conn_str, _host, _port, _db, _user, _pw);
        } catch (Exception e) {
          throw new DBException(e);
        }

        cwp =
            new ConnectionWithParams(
                conn_str,
                new_connection,
                _drvName,
                _user,
                _pw,
                _name,
                _host,
                _port,
                _db,
                _schema,
                true);
      } else {

        cwp =
            new ConnectionWithParams(
                conn_str, null, _drvName, _user, null, _name, _host, _port, _db, _schema, false);
      }
      connections.put(key, cwp);
    }

    ConnectionWithParams _cwp = (ConnectionWithParams) connections.get(key);

    if (_cwp.getName().compareTo(_name) != 0) {
      // connections.remove(key);
      _cwp.setName(_name);
      connections.put(key, _cwp);
    }

    if ((!_cwp.isConnected()) && (_connected)) {
      _cwp.connect(_pw);
    }

    return _cwp;
  }