public Connection connect()

in wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java [829:879]


  public Connection connect(
      final String driverProtocol,
      final HostSpec hostSpec,
      final Properties props,
      final boolean isInitialConnection,
      final JdbcCallable<Connection, SQLException> connectFunc)
      throws SQLException {

    this.initFailoverMode();
    if (this.readerFailoverHandler == null) {
      if (this.readerFailoverHandlerSupplier == null) {
        throw new SQLException(Messages.get("Failover.nullReaderFailoverHandlerSupplier"));
      }
      this.readerFailoverHandler = this.readerFailoverHandlerSupplier.get();
    }

    if (this.writerFailoverHandler == null) {
      if (this.writerFailoverHandlerSupplier == null) {
        throw new SQLException(Messages.get("Failover.nullWriterFailoverHandlerSupplier"));
      }
      this.writerFailoverHandler = this.writerFailoverHandlerSupplier.get();
    }

    Connection conn = null;
    try {
      conn =
          this.staleDnsHelper.getVerifiedConnection(isInitialConnection, this.hostListProviderService,
              driverProtocol, hostSpec, props, connectFunc);
    } catch (final SQLException e) {
      if (!this.enableConnectFailover || !shouldExceptionTriggerConnectionSwitch(e)) {
        throw e;
      }

      try {
        failover(this.pluginService.getCurrentHostSpec());
      } catch (FailoverSuccessSQLException failoverSuccessException) {
        conn = this.pluginService.getCurrentConnection();
      }
    }

    if (conn == null) {
      // This should be unreachable, the above logic will either get a connection successfully or throw an exception.
      throw new SQLException(Messages.get("Failover.unableToConnect"));
    }

    if (isInitialConnection) {
      this.pluginService.refreshHostList(conn);
    }

    return conn;
  }