void buildQueryClientAndVerifyConnection()

in jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamConnection.java [612:652]


  void buildQueryClientAndVerifyConnection(
    final Properties info,
    final AWSCredentialsProvider credentialsProvider) throws SQLException {
    this.queryClientBuilder = AmazonTimestreamQueryClient
      .builder()
      .withClientConfiguration(this.clientConfiguration);

    final Object endpoint = info.get(TimestreamConnectionProperty.ENDPOINT.getConnectionProperty());

    Object region = info.get(TimestreamConnectionProperty.REGION.getConnectionProperty());

    if (endpoint != null) {
      if (region == null) {
        throw Error.createSQLException(LOGGER, Error.MISSING_SERVICE_REGION);
      }

      if (endpoint.toString().isEmpty()) {
        throw Error.createSQLException(LOGGER, Error.INVALID_ENDPOINT);
      }

      queryClientBuilder.withEndpointConfiguration(new EndpointConfiguration(endpoint.toString(), region.toString()));
    } else {
      if (region == null) {
        region = TimestreamConnectionProperty.REGION.getDefaultValue();
      }
      queryClientBuilder.withRegion(region.toString());
    }
    queryClientBuilder.withCredentials(credentialsProvider);

    // Build the client and issue a query to validate the actual connection.
    try {
      queryClient = this.queryClientBuilder.build();
      queryClient.query(new QueryRequest().withQueryString("SELECT 1"));
    } catch (final Exception sdkClientException) {
      throw Error.createSQLException(
        LOGGER,
        Constants.CONNECTION_FAILURE_SQL_STATE,
        sdkClientException,
        Error.CONN_FAILED);
    }
  }